[FIX] website_forum: post edition working again
[odoo/odoo.git] / addons / hr_timesheet_invoice / test / test_hr_timesheet_invoice.yml
1 -
2   In order to test hr_timesheet_invoice in OpenERP, I create account line to manage invoice based on costs.
3 -
4   I create an account analytic line.
5 -
6   !record {model: account.analytic.line, id: account_analytic_line_developyamlforhrmodule0 }:
7     account_id: account.analytic_agrolait
8     amount: -1.0
9     general_account_id: account.a_expense
10     journal_id: hr_timesheet.analytic_journal
11     name: develop yaml for hr module
12     product_id: product.product_product_consultant
13     product_uom_id: product.product_uom_hour
14     to_invoice: hr_timesheet_invoice.timesheet_invoice_factor2
15     unit_amount: 5.00
16 -
17   Assign partner name and price list in analytic account.
18 -
19   !record {model: account.analytic.account, id: account.analytic_agrolait}:
20     partner_id: base.res_partner_2
21     pricelist_id: product.list0
22 -
23   I open this account and make the state as pending.
24 -
25   !python {model: account.analytic.account}: |
26     self.set_open(cr, uid, [ref('account.analytic_agrolait')], None)
27     self.set_pending(cr, uid, [ref('account.analytic_agrolait')], None)
28 -
29   I assign account on analytic account line.
30 -
31   !python {model: hr.analytic.timesheet}: |
32     self.on_change_account_id(cr, uid, [ref('account_analytic_line_developyamlforhrmodule0')], ref('account.analytic_agrolait'))
33
34 -
35   I create a Tax Codes
36 -
37   !record {model: account.tax.code, id: tax_case}:
38     name: Tax_case
39     company_id: base.main_company
40     sign: 1
41 -
42   I create a Tax
43 -
44   !record {model: account.tax, id: tax10}:
45     name: Tax 10.0
46     amount: 10.0
47     type: fixed
48     sequence: 1
49     company_id: base.main_company
50     type_tax_use: all
51     tax_code_id: tax_case
52 -
53   I create an Account with the tax
54 -
55   !record {model: account.account, id: account_income_i000}:
56     name: "income account"
57     code: "I000"
58     type: 'other'
59     user_type: "account.data_account_type_income"
60     tax_ids: [tax10]
61
62   I set the account as property_account_income on the product and I set the tax on the product 
63 -  
64   !record {model: product.product, id: product.product_product_consultant}:
65     property_account_income: account_income_i000
66     uom_id: product.product_uom_hour
67     taxes_id: [tax10] 
68     list_price: 75
69 -
70   I create invoice on analytic Line using "Invoice analytic Line" wizard.
71 -
72   !record {model: hr.timesheet.invoice.create, id: hr_timesheet_invoice_create_0}:
73     date: 1
74     name: 1
75     price: 1
76     product: product.product_product_consultant
77     time: 1
78 -
79   I click on "Create Invoice" button of "Invoice analytic Line" wizard to create invoice.
80 -
81   !python {model: hr.timesheet.invoice.create}: |
82     action_result = self.do_create(cr, uid, [ref("hr_timesheet_invoice_create_0")], {
83         "active_ids": [ref("hr_timesheet_invoice.account_analytic_line_developyamlforhrmodule0")]
84     })
85     invoice_pool = self.pool.get('account.invoice')
86     invoice_domain = action_result['domain']
87     invoice_ids = invoice_pool.search(cr, uid, invoice_domain)
88     invoice_pool.write(cr, uid, invoice_ids, {'origin': 'test-hrtsic0_id_'+str( ref("hr_timesheet_invoice_create_0")) \
89         + '_aaldyfhrm0_id_'+str( ref("hr_timesheet_invoice.account_analytic_line_developyamlforhrmodule0") ) })
90
91 -
92   I check that Invoice is created for this timesheet.
93 -
94   !python {model: account.analytic.line}: |
95     aline = self.browse(cr, uid, ref('account_analytic_line_developyamlforhrmodule0'))
96     analytic_account_obj = self.pool.get('account.analytic.account')
97     data = self.pool.get('hr.timesheet.invoice.create').read(cr, uid, [ref("hr_timesheet_invoice_create_0")], [], context)[0]
98     partner = aline.account_id.partner_id.id
99
100     invoice_obj = self.pool.get('account.invoice')
101     invoice_ids = invoice_obj.search(cr, uid, [('partner_id', '=', partner),
102        ('origin', '=', 'test-hrtsic0_id_'+str( ref("hr_timesheet_invoice_create_0")) + '_aaldyfhrm0_id_'+str( ref("hr_timesheet_invoice.account_analytic_line_developyamlforhrmodule0") ))
103     ])
104     invoice_id = invoice_obj.browse(cr, uid, invoice_ids)[0]
105
106     for invoice in invoice_id.invoice_line:
107       product = invoice.product_id.id
108
109     product_exp = data['product'][0]
110
111     assert product == product_exp
112     assert aline.invoice_id, "Invoice created, but analytic line wasn't updated."
113     assert aline.invoice_id == invoice_id, "Invoice doesn't match the one at analytic line"
114     assert invoice_id.amount_untaxed == 187.5, "Invoice amount mismatch: %s" % invoice_id.amount_untaxed
115     assert invoice_id.amount_tax == 50, "Invoice tax mismatch: %s" %  invoice_id.amount_tax