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