[IMP] hr: onboarding
[odoo/odoo.git] / addons / account_voucher / test / case5_suppl_usd_usd.yml
1 -
2   In order to check the Account_voucher module with multi-currency in OpenERP, 
3   I create a supplier invoices in USD and make the payment in USD but with another exchange rate and with a write-off
4 -
5   I create a cash account with currency USD
6 -
7   !record {model: account.account, id: account_cash_usd_id2}:
8     currency_id: base.USD
9     name: "cash account in usd"
10     code: "Xcash usd2"
11     type: 'liquidity'
12     user_type: "account.data_account_type_cash"
13
14 -
15   I create currency USD in OpenERP for November of 1.8 Rate
16 -
17   !record {model: res.currency.rate, id: nov_usd}:
18     currency_id: base.USD
19     name: !eval "'%s-11-01' %(datetime.now().year)"
20     rate: 1.8
21 -
22   I create currency USD in OpenERP for December of 1.5 Rate
23 -
24   !record {model: res.currency.rate, id: dec_usd}:
25     currency_id: base.USD
26     name: !eval "'%s-12-01' %(datetime.now().year)"
27     rate: 1.5
28 -
29   I set the income and expense currency accounts on the main company
30 -
31   !python {model: res.company}: |
32     from datetime import datetime
33     vals = {
34       'income_currency_exchange_account_id': ref('account.o_expense'),
35       'expense_currency_exchange_account_id': ref('account.o_expense')}
36     self.write(cr, uid, ref('base.main_company'), vals)
37 -
38   I create a bank journal with EUR as currency
39 -
40   !record {model: account.journal, id: bank_journal_EUR}:
41     name: Bank Journal(EUR)
42     code: BEUR
43     type: bank
44     analytic_journal_id: analytic.sit
45     sequence_id: account.sequence_bank_journal
46     default_debit_account_id: account.cash
47     default_credit_account_id: account.cash
48     company_id: base.main_company
49 -
50   I create a bank journal with USD as currency
51 -
52   !record {model: account.journal, id: bank_journal_USD}:
53     name: Bank Journal(USD)
54     code: BUSD
55     type: bank
56     analytic_journal_id: analytic.sit
57     sequence_id: account.sequence_bank_journal
58     default_debit_account_id: account_cash_usd_id2
59     default_credit_account_id: account_cash_usd_id2
60     currency: base.USD
61     company_id: base.main_company
62 -
63   I set the context as would do the action in supplier invoice menuitem
64 -
65   !context
66     'default_type': 'in_invoice'
67 -
68   I create the invoice on 1st november for 1000 USD
69 -
70   !record {model: account.invoice, id: account_supplier_invoice_november, view: account.invoice_supplier_form}:
71     account_id: account.a_pay
72     company_id: base.main_company
73     currency_id: base.USD
74     date_invoice: !eval "'%s-11-01' %(datetime.now().year)"
75     period_id: account.period_1
76     invoice_line:
77       - account_id: account.a_expense
78         name: '[PCSC234] PC Assemble SC234'
79         price_unit: 1000.0
80         quantity: 1.0
81         product_id: product.product_product_3
82         uos_id: product.product_uom_unit
83     journal_id: account.sales_journal
84     partner_id: base.res_partner_19
85     reference_type: none
86     check_total : 1000
87 -
88   I Validate invoice by clicking on Validate button
89 -
90   !workflow {model: account.invoice, action: invoice_open, ref: account_supplier_invoice_november}
91 -
92   I check that first invoice move is correct for creditor account(debit - credit == -555.56)
93 -
94   !python {model: account.invoice}: |
95     from openerp.tools import float_compare
96     invoice_id = self.browse(cr, uid, ref("account_supplier_invoice_november"))
97     assert invoice_id.move_id, "Move not created for open invoice"
98     move_line_obj = self.pool.get('account.move.line')
99     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
100     move_line = move_line_obj.browse(cr, uid, move_lines[0])
101     assert (float_compare(move_line.debit - move_line.credit, -555.56, precision_digits=2) == 0), "Invoice move is incorrect for creditor account"
102     assert (float_compare(move_line.amount_currency, -1000, precision_digits=2) == 0), "Amount currency is incorrect for creditor account"
103 -
104   I set the context that will be used for the encoding of all the vouchers of this file
105 -
106   !context
107     'type': 'payment'
108 -
109   I create the voucher of payment with values $950, journal USD
110 -
111   !record {model: account.voucher, id: account_voucher_case_5_supplier_flow, view: view_vendor_payment_form}:
112     account_id: account.cash
113     amount: 950.0
114     company_id: base.main_company
115     journal_id: bank_journal_USD
116     name: 'Payment: Case Basic SUPPLIER USD/USD'
117     partner_id: base.res_partner_19
118     period_id: account.period_12
119     date: !eval time.strftime("%Y-12-01")
120     payment_option: 'with_writeoff'
121     writeoff_acc_id: account.a_expense
122     comment: 'Write Off'
123     type: 'payment'
124 -
125   I fill $1000 for the previously encoded invoice
126 -
127   !python {model: account.voucher}: |
128     import time
129     from openerp.tools import float_compare
130     vals = {}
131     voucher_id = self.browse(cr, uid, ref('account_voucher_case_5_supplier_flow'))
132     for item in voucher_id.line_dr_ids:
133         if float_compare(item.amount_unreconciled, 1000.00, precision_digits=2) == 0:
134             self.pool.get('account.voucher.line').write(cr, uid, [item.id], {'amount': 1000})
135     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
136 -
137   I check that writeoff amount computed is -50.0
138 -
139   !python {model: account.voucher}: |
140     from openerp.tools import float_compare
141     writeoff_amount = self.browse(cr, uid, ref('account_voucher_case_5_supplier_flow')).writeoff_amount
142     assert float_compare(writeoff_amount, -50.0, precision_digits=2) == 0
143 -
144   I confirm the voucher
145 -
146   !workflow {model: account.voucher, action: proforma_voucher, ref: account_voucher_case_5_supplier_flow}
147 -
148   I check that the move of my voucher is valid and that it is posted
149 -
150   !python {model: account.voucher}: |
151     voucher_id = self.browse(cr, uid, ref('account_voucher_case_5_supplier_flow'))
152     assert voucher_id.state == 'posted', "Voucher state is not posted"
153     for move_line in voucher_id.move_id.line_id:
154         assert move_line.state == 'valid', "Voucher move is not valid"
155 -
156   I check that my creditor account is correct
157 -
158   I check that the bank entry is -$950 and 633.33€ as amount_currency and credit, respectively.
159 -
160   I check that the creditor account has 1 new line with $1000 and 666.67€ as amount_currency and debit, respectively.
161 -
162   I check that my currency rate difference is correct (111.11€ in debit/credit with no amount_currency)
163 -
164   I check that my writeoff is correct. 33.34€ in credit with -$50 as amount currency
165 -
166   !python {model: account.voucher}: |
167     from openerp.tools import float_compare
168     voucher_id = self.browse(cr, uid, ref('account_voucher_case_5_supplier_flow'))
169     for move_line in voucher_id.move_id.line_id:
170         if float_compare(move_line.amount_currency, -950.00, precision_digits=2) == 0:
171             assert float_compare(move_line.credit, 633.33, precision_digits=2) == 0, "Wrong bank entry."
172         elif float_compare(move_line.credit, 111.11, precision_digits=2) == 0 or float_compare(move_line.debit, 111.11, precision_digits=2) == 0:
173             assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0, "Incorrect Currency Difference."
174         elif float_compare(move_line.credit, 33.34, precision_digits=2) == 0:
175             assert float_compare(move_line.amount_currency, -50.0, precision_digits=2) == 0, "Writeoff amount is wrong."
176         elif float_compare(move_line.debit, 666.67, precision_digits=2) == 0:
177             assert float_compare(move_line.amount_currency, 1000.0, precision_digits=2) == 0, "Wrong supplier entry."
178         else:
179             assert False, "Wrong entry. Unrecognized account move line"
180 -
181   I check the residual amount of invoice, it should be 0 in residual currency and 0 in amount_residual and paid
182 -
183    !python {model: account.invoice}: |
184     from openerp.tools import float_compare
185     invoice_id = self.browse(cr, uid, ref("account_supplier_invoice_november"))
186     move_line_obj = self.pool.get('account.move.line')
187     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)])
188     move_line = move_line_obj.browse(cr, uid, move_lines[0])
189     assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for supplier invoice"