[IMP] hr: onboarding
[odoo/odoo.git] / addons / account_voucher / test / case1_usd_usd_payment_rate.yml
1 -
2   In order to check the Account_voucher module with multi-currency in OpenERP, 
3   I create 2 Invoices in USD and make 1 Payment in USD based on the currency rating given by the bank which is slightly different that the one encoded in OpenERP
4 -
5   I set the income and expense currency accounts on the main company
6 -
7   !python {model: res.company}: |
8     from datetime import datetime
9     vals = {
10       'income_currency_exchange_account_id': ref('account.o_expense'),
11       'expense_currency_exchange_account_id': ref('account.o_expense')}
12     self.write(cr, uid, ref('base.main_company'), vals)
13 -
14   I create currency USD in OpenERP for January of 1.333333 Rate
15 -
16   !python {model: res.currency.rate}: |
17     from datetime import datetime
18     curr_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'USD')])[0]
19     date = '%s-01-01' %(datetime.now().year)
20     ids = self.search(cr, uid, [('currency_id','=',curr_id), ('name', '=', date)])
21     self.write(cr, uid, ids, {'rate': 1.333333})
22 -
23   I create currency USD in OpenERP for February of 1.250000 Rate
24 -
25   !record {model: res.currency.rate, id: feb_usd}:
26     currency_id: base.USD
27     name: !eval "'%s-02-01' %(datetime.now().year)"
28     rate: 1.250000
29
30 -
31   I create currency USD in OpenERP for March of 1.111111 Rate
32 -
33   !record {model: res.currency.rate, id: mar_usd}:
34     currency_id: base.USD
35     name: !eval "'%s-03-01' %(datetime.now().year)"
36     rate: 1.111111
37
38 -
39   I create currency USD in OpenERP for April of 1.052632 Rate
40 -
41   !record {model: res.currency.rate, id: apr_usd}:
42     currency_id: base.USD
43     name: !eval "'%s-04-01' %(datetime.now().year)"
44     rate: 1.052632
45
46 -
47   I create a cash account with currency USD
48 -
49   !record {model: account.account, id: account_cash_usd_id}:
50     currency_id: base.USD
51     name: "cash account in usd"
52     code: "Xcash usd"
53     type: 'liquidity'
54     user_type: "account.data_account_type_cash"
55
56 -
57   I create a bank journal with USD as currency
58 -
59   !record {model: account.journal, id: bank_journal_USD}:
60     name: Bank Journal(USD)
61     code: BUSD
62     type: bank
63     analytic_journal_id: analytic.sit
64     sequence_id: account.sequence_bank_journal
65     default_debit_account_id: account_cash_usd_id
66     default_credit_account_id: account_cash_usd_id
67     currency: base.USD
68     company_id: base.main_company
69
70 -
71   I create a new partner Kate Mc Kay
72 -
73   !record {model: res.partner, id: res_partner_mc_kay}:
74     name: "Mc Kay Kate"
75     property_account_receivable: account.a_recv
76     property_account_payable: account.a_pay
77 -
78   I create the first invoice on 1st January  for 200 USD
79 -
80   !record {model: account.invoice, id: account_invoice_jan_payment_rate}:
81     account_id: account.a_recv
82     company_id: base.main_company
83     currency_id: base.USD
84     date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
85     period_id: account.period_1
86     invoice_line:
87       - account_id: account.a_sale
88         name: '[PCSC234] PC Assemble SC234'
89         price_unit: 200.0
90         quantity: 1.0
91         product_id: product.product_product_3
92         uos_id: product.product_uom_unit
93     journal_id: account.sales_journal
94     partner_id: res_partner_mc_kay
95     reference_type: none
96 -
97   I Validate invoice by clicking on Validate button
98 -
99   !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_jan_payment_rate}
100 -
101   I check that first invoice move is correct for debtor account (debit - credit == 150.0)
102 -
103   !python {model: account.invoice}: |
104     from openerp.tools import float_compare
105     invoice_id = self.browse(cr, uid, ref("account_invoice_jan_payment_rate"))
106     assert invoice_id.move_id, "Move not created for open invoice"
107     move_line_obj = self.pool.get('account.move.line')
108     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
109     move_line = move_line_obj.browse(cr, uid, move_lines[0])
110     assert (float_compare(move_line.debit - move_line.credit, 150.0, precision_digits=2) == 0), "Invoice move is not correct for debtors account"
111 -
112   I create the second invoice on 1st February for 100 USD
113 -
114   !record {model: account.invoice, id: account_invoice_feb_payment_rate}:
115     account_id: account.a_recv
116     company_id: base.main_company
117     currency_id: base.USD
118     date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
119     period_id: account.period_2
120     invoice_line:
121       - account_id: account.a_sale
122         name: '[PCSC234] PC Assemble SC234'
123         price_unit: 100.0
124         quantity: 1.0
125         product_id: product.product_product_3
126         uos_id: product.product_uom_unit
127     journal_id: account.sales_journal
128     partner_id: res_partner_mc_kay
129     reference_type: none
130 -
131   I Validate invoice by clicking on Validate button
132 -
133   !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_feb_payment_rate}
134 -
135   I check that second invoice move is correct for debtor account (debit - credit == 80)
136 -
137   !python {model: account.invoice}: |
138     from openerp.tools import float_compare
139     invoice_id = self.browse(cr, uid, ref("account_invoice_feb_payment_rate"))
140     assert invoice_id.move_id, "Move not created for open invoice"
141     move_line_obj = self.pool.get('account.move.line')
142     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
143     move_line = move_line_obj.browse(cr, uid, move_lines[0])
144     assert (float_compare(move_line.debit - move_line.credit, 80, precision_digits=2) == 0), "Invoice move is not correct for debtors account"
145
146 -
147   I set the context that will be used for the encoding of all the vouchers of this file
148 -
149   !context
150     'type': 'receipt'
151 -
152   On the first March, I create the first voucher of payment with values 240 USD, journal USD, and specifying that $1 = 0.8€
153 -
154   !record {model: account.voucher, id: account_voucher_1_case1_payment_rate, view: view_vendor_receipt_form}:
155     account_id: account.cash
156     amount: 240.0
157     company_id: base.main_company
158     journal_id: bank_journal_USD
159     name: 'Payment: Case 1 USD/USD payment rate'
160     partner_id: res_partner_mc_kay
161     period_id: account.period_3
162     date: !eval time.strftime("%Y-03-01")
163     payment_option: 'with_writeoff'
164     writeoff_acc_id: account.a_expense
165     comment: 'Write Off'
166     payment_rate: 0.8
167     payment_rate_currency_id: base.EUR
168
169 -
170   I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$>
171 -
172   !python {model: account.voucher}: |
173     from openerp.tools import float_compare
174     vals = {}
175     voucher_id = self.browse(cr, uid, ref('account_voucher_1_case1_payment_rate'))
176     data = []
177     for item in voucher_id.line_cr_ids:
178         if float_compare(item.amount_unreconciled, 200.00, precision_digits=2) == 0:
179             data += [(item.id, 180.0)]
180         else:
181             data += [(item.id, 70.0)]
182     for line_id, amount in data:
183         self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
184     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
185 -
186   I check that writeoff amount computed is -10.0
187 -
188   !python {model: account.voucher}: |
189     from openerp.tools import float_compare
190     voucher = ref('account_voucher_1_case1_payment_rate') 
191     voucher_id = self.browse(cr, uid, voucher)
192     assert (float_compare(voucher_id.writeoff_amount, -10.0, precision_digits=2) == 0), "Writeoff amount is not -10.0"
193 -
194   I confirm the voucher
195 -
196   !python {model: account.voucher}: |
197     voucher = ref('account_voucher_1_case1_payment_rate') 
198     self.signal_workflow(cr, uid, [voucher], 'proforma_voucher')
199 -
200   I check that the move of my first voucher is valid
201 -
202   !python {model: account.voucher}: |
203     voucher = ref('account_voucher_1_case1_payment_rate') 
204     voucher_id = self.browse(cr, uid, voucher)
205     move_line_obj = self.pool.get('account.move.line')
206     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
207     for move_line in move_line_obj.browse(cr, uid, move_lines):
208         assert move_line.state == 'valid', "Voucher move is not valid"
209 -
210   I check that my debtor account is correct
211 -
212   I check that the debtor account has 2 new lines with -180 and -70 as amount_currency columns and that their credit columns are respectively 144 and 56
213 -
214   I check that my write-off is correct. 8 debit and 10 amount_currency
215 -
216   !python {model: account.voucher}: |
217     from openerp.tools import float_compare
218     voucher = ref('account_voucher_1_case1_payment_rate') 
219     voucher_id = self.browse(cr, uid, voucher)
220     move_line_obj = self.pool.get('account.move.line')
221     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
222     for move_line in move_line_obj.browse(cr, uid, move_lines):
223         if float_compare(move_line.amount_currency, -180.00, precision_digits=2) == 0:
224             assert float_compare(move_line.credit, 144.00, precision_digits=2) == 0, "Debtor account has wrong entry."
225         elif float_compare(move_line.amount_currency, -70.00, precision_digits=2) == 0:
226             assert float_compare(move_line.credit, 56.00, precision_digits=2) == 0, "Debtor account has wrong entry."
227         elif float_compare(move_line.amount_currency, 10.00, precision_digits=2) == 0:
228             assert float_compare(move_line.debit, 8.00, precision_digits=2) == 0, "Writeoff amount is wrong: Got a debit of %s (expected 8,00€)" % (move_line.debit)
229         elif float_compare(move_line.amount_currency, 240.00, precision_digits=2) == 0:
230             assert float_compare(move_line.debit, 192.00, precision_digits=2) == 0, "Bank entry is wrong."
231         else:
232             assert False, "Unrecognized journal entry"
233 -
234   I check the residual amount of Invoice1, should be 20 in amount_currency and 6 in amount_residual
235 -
236   !python {model: account.invoice}: |
237     from openerp.tools import float_compare
238     invoice_id = self.browse(cr, uid, ref("account_invoice_jan_payment_rate"))
239     move_line_obj = self.pool.get('account.move.line')
240     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)])
241     move_line = move_line_obj.browse(cr, uid, move_lines[0])
242     assert (float_compare(move_line.amount_residual, 6.0, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice"
243     assert (float_compare(move_line.amount_residual_currency, 20.0, precision_digits=2) == 0) , "Residual amount in currency is not correct for first Invoice"
244 -
245   I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
246 -
247   !python {model: account.invoice}: |
248     from openerp.tools import float_compare
249     invoice_id = self.browse(cr, uid, ref("account_invoice_feb_payment_rate"))
250     move_line_obj = self.pool.get('account.move.line')
251     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)])
252     move_line = move_line_obj.browse(cr, uid, move_lines[0])
253     assert (float_compare(move_line.amount_residual, 24.0, precision_digits=2) == 0) , "Residual amount is not correct for second Invoice"
254     assert (float_compare(move_line.amount_residual_currency, 30.0, precision_digits=2) == 0) , "Residual amount in currency is not correct for second Invoice"