123a446317200b836ba0e512b55c023c11338cf4
[odoo/odoo.git] / addons / account_voucher / test / case1_usd_usd.yml
1 -
2   I create a currency rate for USD for january of 1.333333
3 -
4   !python {model: res.currency.rate}: |
5     from datetime import datetime
6     curr_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'USD')])
7     date = '%s-01-01' %(datetime.now().year)
8     ids = self.search(cr, uid, [('currency_id','=',curr_id), ('name', '=', date)])
9     self.write(cr, uid, ids, {'rate': 1.333333})
10 -
11   I create a currency rate for USD for february of 1.250000
12 -
13   !record {model: res.currency.rate, id: feb_usd}:
14     currency_id: base.USD
15     name: !eval "'%s-02-01' %(datetime.now().year)"
16     rate: 1.250000
17
18 -
19   I create a currency rate for USD for march of 1.111111
20 -
21   !record {model: res.currency.rate, id: mar_usd}:
22     currency_id: base.USD
23     name: !eval "'%s-03-01' %(datetime.now().year)"
24     rate: 1.111111
25
26 -
27   I create a currency rate for USD for april of 1.052632
28 -
29   !record {model: res.currency.rate, id: apr_usd}:
30     currency_id: base.USD
31     name: !eval "'%s-04-01' %(datetime.now().year)"
32     rate: 1.052632
33
34 -
35   I create a bank journal with USD as currency
36 -
37   !record {model: account.journal, id: bank_journal_USD}:
38     name: Bank Journal(USD)
39     code: BUSD
40     type: bank
41     analytic_journal_id: account.sit
42     sequence_id: account.sequence_bank_journal
43     default_debit_account_id: account.cash
44     default_credit_account_id: account.cash
45     currency: base.USD
46     company_id: base.main_company
47     view_id: account.account_journal_bank_view
48
49 -
50   I set up some accounts for currency rate expense/income in my company
51 -
52   !record {model: res.company, id: base.main_company}:
53     property_expense_currency_exchange: account.o_expense
54     property_income_currency_exchange: account.o_income
55 -
56   I create new partner Mark Strauss.
57 -
58   !record {model: res.partner, id: res_partner_strauss0}:
59     address:
60       - city: paris
61         country_id: base.fr
62         name: Mark Strauss
63         street: 1 rue Rockfeller
64         type: invoice
65         zip: '75016'
66     name: Mr. Mark Strauss
67 -
68   I create the first invoice on 1st January  for 200 USD
69 -
70   !record {model: account.invoice, id: account_invoice_jan}:
71     account_id: account.a_recv
72     address_contact_id: base.res_partner_address_3000
73     address_invoice_id: base.res_partner_address_3000
74     company_id: base.main_company
75     currency_id: base.USD
76     date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
77     period_id: account.period_1
78     invoice_line:
79       - account_id: account.a_sale
80         name: '[PC1] Basic PC'
81         price_unit: 200.0
82         quantity: 1.0
83         product_id: product.product_product_pc1
84         uos_id: product.product_uom_unit
85     journal_id: account.sales_journal
86     partner_id: res_partner_strauss0
87     reference_type: none
88 -
89   I Validate invoice by clicking on Validate button
90 -
91   !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_jan}
92 -
93   I check that first invoice move is correct for debtor account (debit - credit == 150.0)
94 -
95   !python {model: account.invoice}: |
96     invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
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 (move_line.debit - move_line.credit == 150.0), "Invoice move is not correct for debtors account"
102 -
103   I create the second invoice on 1st February for 100 USD
104 -
105   !record {model: account.invoice, id: account_invoice_feb}:
106     account_id: account.a_recv
107     address_contact_id: base.res_partner_address_3000
108     address_invoice_id: base.res_partner_address_3000
109     company_id: base.main_company
110     currency_id: base.USD
111     date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
112     period_id: account.period_2
113     invoice_line:
114       - account_id: account.a_sale
115         name: '[PC1] Basic PC'
116         price_unit: 100.0
117         quantity: 1.0
118         product_id: product.product_product_pc1
119         uos_id: product.product_uom_unit
120     journal_id: account.sales_journal
121     partner_id: res_partner_strauss0
122     reference_type: none
123 -
124   I Validate invoice by clicking on Validate button
125 -
126   !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_feb}
127 -
128   I check that second invoice move is correct for debtor account (debit - credit == 80)
129 -
130   !python {model: account.invoice}: |
131     invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
132     assert invoice_id.move_id, "Move not created for open invoice"
133     move_line_obj = self.pool.get('account.move.line')
134     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
135     move_line = move_line_obj.browse(cr, uid, move_lines[0])
136     assert (move_line.debit - move_line.credit == 80), "Invoice move is not correct for debtors account"
137
138 -
139   I create the first voucher of payment
140   <create with values 240 USD, journal USD, and fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$>
141 -
142   !python {model: account.voucher}: |
143     import netsvc, time
144     vals = {}
145     res = self.onchange_partner_id(cr, uid, [], ref("res_partner_strauss0"), ref('bank_journal_USD'), 240.00, 2, ttype='receipt', date=False)
146     vals = {
147         'account_id': ref('account.cash'),
148         'amount': 240.00,
149         'company_id': ref('base.main_company'),
150         'currency_id': ref('base.USD'),
151         'journal_id': ref('bank_journal_USD'),
152         'partner_id': ref('res_partner_strauss0'),
153         'period_id': ref('account.period_3'),
154         'type': 'receipt',
155         'date': time.strftime("%Y-03-01"),
156         'payment_option': 'with_writeoff',
157         'writeoff_acc_id': ref('account.a_expense'),
158         'comment': 'Write Off',
159         'name': 'First payment',
160     }
161     if not res['value']['line_cr_ids']:
162       res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
163     for item in res['value']['line_cr_ids']:
164         if item['amount_unreconciled'] == 200.00:
165             item['amount'] = 180.00
166         else:
167             item['amount'] = 70.00
168     vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
169     id = self.create(cr, uid, vals)
170     voucher_id = self.browse(cr, uid, id)
171     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
172 -
173   I check that writeoff amount computed is -10.0
174 -
175   !python {model: account.voucher}: |
176     voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
177     voucher_id = self.browse(cr, uid, voucher[0])
178     assert (voucher_id.writeoff_amount == -10.0), "Writeoff amount is not -10.0"
179 -
180   I check that currency rate difference is -34.0
181 -
182   !python {model: account.voucher}: |
183     voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
184     voucher_id = self.browse(cr, uid, voucher[0])
185     assert (voucher_id.currency_rate_difference == -34.0), "Currency rate difference is not -34.0"
186 -
187   I confirm the voucher
188 -
189   !python {model: account.voucher}: |
190     import netsvc
191     voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
192     wf_service = netsvc.LocalService("workflow")
193     wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
194 -
195   I check that the move of my first voucher is valid
196 -
197   !python {model: account.voucher}: |
198     voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
199     voucher_id = self.browse(cr, uid, voucher[0])
200     move_line_obj = self.pool.get('account.move.line')
201     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
202     for move_line in move_line_obj.browse(cr, uid, move_lines):
203         assert move_line.state == 'valid', "Voucher move is not valid"
204 -
205   I check that my debtor account is correct
206 -
207   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 135 and 56
208 -
209   I check that my currency rate difference is correct. 34 in credit with no amount_currency
210 -
211   I check that my write-off is correct. 9 debit and 10 amount_currency
212 -
213   !python {model: account.voucher}: |
214     voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
215     voucher_id = self.browse(cr, uid, voucher[0])
216     move_line_obj = self.pool.get('account.move.line')
217     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
218     for move_line in move_line_obj.browse(cr, uid, move_lines):
219         if move_line.amount_currency == -180.00:
220             assert move_line.credit == 135.00, "Debtor account has wrong entry."
221         elif move_line.amount_currency == -70.00:
222             assert move_line.credit == 56.00, "Debtor account has wrong entry."
223         elif move_line.credit == 34.00:
224             assert move_line.amount_currency == 0.00, "Incorrect currency rate difference."
225         elif move_line.amount_currency == 10.00:
226             assert move_line.debit == 9.00, "Writeoff amount is wrong."
227 -
228   I check the residual amount of Invoice1, should be 20 in amount_currency and 15 in company currency
229 -
230   !python {model: account.invoice}: |
231     invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
232     move_line_obj = self.pool.get('account.move.line')
233     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)])
234     move_line = move_line_obj.browse(cr, uid, move_lines[0])
235     assert (move_line.amount_residual_currency == 20.0 and move_line.amount_residual == 15.0) , "Residual amount is not correct for first Invoice"
236 -
237   I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
238 -
239   !python {model: account.invoice}: |
240     invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
241     move_line_obj = self.pool.get('account.move.line')
242     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)])
243     move_line = move_line_obj.browse(cr, uid, move_lines[0])
244     assert (move_line.amount_residual_currency == 30.0 and move_line.amount_residual == 24.0) , "Residual amount is not correct for first Invoice"
245 -
246   I create the second voucher of payment
247   <create with values 45 USD, journal USD, and fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$>
248   
249 -
250   !python {model: account.voucher}: |
251     import netsvc, time
252     vals = {}
253     res = self.onchange_partner_id(cr, uid, [], ref("res_partner_strauss0"), ref('bank_journal_USD'), 45.00, 2, ttype='receipt', date=False)
254     vals = {
255         'account_id': ref('account.cash'),
256         'amount': 45.00,
257         'company_id': ref('base.main_company'),
258         'currency_id': ref('base.USD'),
259         'journal_id': ref('bank_journal_USD'),
260         'partner_id': ref('res_partner_strauss0'),
261         'period_id': ref('account.period_3'),
262         'type': 'receipt',
263         'date': time.strftime("%Y-04-01"),
264         'payment_option': 'with_writeoff',
265         'writeoff_acc_id': ref('account.a_expense'),
266         'comment': 'Write Off',
267         'name': 'Second payment',
268     }
269     if not res['value']['line_cr_ids']:
270       res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
271     for item in res['value']['line_cr_ids']:
272         if item['amount_unreconciled'] == 20.00:
273             item['amount'] = 20.00
274         else:
275             item['amount'] = 30.00
276     vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
277     id = self.create(cr, uid, vals)
278     voucher_id = self.browse(cr, uid, id)
279     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
280 -
281   I check that writeoff amount computed is -5.0
282 -
283   !python {model: account.voucher}: |
284     voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
285     voucher_id = self.browse(cr, uid, voucher[0])
286     assert (voucher_id.writeoff_amount == -5.0), "Writeoff amount is not -5.0"
287 -
288   I check that currency rate difference is -8.50
289 -
290   !python {model: account.voucher}: |
291     voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
292     voucher_id = self.browse(cr, uid, voucher[0])
293     assert (voucher_id.currency_rate_difference == -8.50), "Currency rate difference is not -8.50"
294 -
295   I confirm the voucher
296 -
297   !python {model: account.voucher}: |
298     import netsvc
299     voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
300     wf_service = netsvc.LocalService("workflow")
301     wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
302 -
303   I check that the move of my second voucher is valid
304 -
305   !python {model: account.voucher}: |
306     voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
307     voucher_id = self.browse(cr, uid, voucher[0])
308     move_line_obj = self.pool.get('account.move.line')
309     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
310     for move_line in move_line_obj.browse(cr, uid, move_lines):
311         assert move_line.state == 'valid', "Voucher move is not valid"
312 -
313   I check that my debtor account is correct
314 -
315   I check that the debtor account has 2 new lines with -20 and -30 as amount_currency columns and their credit columns are respectively 15 and 24.
316 -
317   I check that my currency rate difference is correct. 8.5 in credit with no amount_currency
318 -
319   I check that my writeoff is correct. 4.75 debit and 5 amount_currency
320 -
321   !python {model: account.voucher}: |
322     voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
323     voucher_id = self.browse(cr, uid, voucher[0])
324     move_line_obj = self.pool.get('account.move.line')
325     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
326     for move_line in move_line_obj.browse(cr, uid, move_lines):
327         if move_line.amount_currency == -20.00:
328             assert move_line.credit == 15.00, "Debtor account has wrong entry."
329         elif move_line.amount_currency == -30.00:
330             assert move_line.credit == 24.00, "Debtor account has wrong entry."
331         elif move_line.credit == 8.50:
332             assert move_line.amount_currency == 0.00, "Incorrect Currency Difference."
333         elif move_line.amount_currency == 5.00:
334             assert move_line.debit == 4.75, "Writeoff amount is wrong."
335 -
336   I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
337 -
338   !python {model: account.invoice}: |
339     invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
340     move_line_obj = self.pool.get('account.move.line')
341     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)])
342     move_line = move_line_obj.browse(cr, uid, move_lines[0])
343     assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice"
344 -    
345   I check the residual amuont of Invoice2, should be 0 in residual currency and 0 in amount_residual and paid
346 -
347   !python {model: account.invoice}: |
348     invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
349     move_line_obj = self.pool.get('account.move.line')
350     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)])
351     move_line = move_line_obj.browse(cr, uid, move_lines[0])
352     assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for second Invoice"