2 In order to test hr_timesheet_invoice in OpenERP, I create account line to manage invoice based on costs.
4 I create an account analytic line.
6 !record {model: account.analytic.line, id: account_analytic_line_developyamlforhrmodule0 }:
7 account_id: account.analytic_agrolait
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
17 Assign partner name and price list in analytic account.
19 !record {model: account.analytic.account, id: account.analytic_agrolait}:
20 partner_id: base.res_partner_2
21 pricelist_id: product.list0
23 I open this account and make the state as pending.
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)
29 I assign account on analytic account line.
31 !python {model: hr.analytic.timesheet}: |
32 self.on_change_account_id(cr, uid, [ref('account_analytic_line_developyamlforhrmodule0')], ref('account.analytic_agrolait'))
37 !record {model: account.tax.code, id: tax_case}:
39 company_id: base.main_company
44 !record {model: account.tax, id: tax10}:
49 company_id: base.main_company
53 I create an Account with the tax
55 !record {model: account.account, id: account_income_i000}:
56 name: "income account"
59 user_type: "account.data_account_type_income"
62 I set the account as property_account_income on the product and I set the tax on the product
64 !record {model: product.product, id: product.product_product_consultant}:
65 property_account_income: account_income_i000
66 uom_id: product.product_uom_hour
70 I create invoice on analytic Line using "Invoice analytic Line" wizard.
72 !record {model: hr.timesheet.invoice.create, id: hr_timesheet_invoice_create_0}:
76 product: product.product_product_consultant
79 I click on "Create Invoice" button of "Invoice analytic Line" wizard to create invoice.
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")]
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") ) })
92 I check that Invoice is created for this timesheet.
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
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") ))
104 invoice_id = invoice_obj.browse(cr, uid, invoice_ids)[0]
106 for invoice in invoice_id.invoice_line:
107 product = invoice.product_id.id
109 product_exp = data['product'][0]
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