5649bf0d4bba922b335e4e513ce1a11d8686eb34
[odoo/odoo.git] / addons / account_voucher / test / case3_eur_eur.yml
1 -
2   In order to check the Account_voucher module with multi-currency in OpenERP, 
3   I create 2 Invoices in EUR and make 2 Payments in EUR based on the currency rating on that particular date.
4 -
5   I create currency EUR in OpenERP for January of 1.000000 Rate
6 -
7   !record {model: res.currency.rate, id: jan_eur}:
8     currency_id: base.EUR
9     name: !eval "'%s-01-01' %(datetime.now().year)"
10     rate: 1.000000
11 -
12   I modify the debtor account in order to make sure there is no currency_id linked
13 -
14   !python {model: account.account}: |
15     from datetime import datetime
16     ids = self.search(cr, uid, [('name', 'ilike', 'debtor')])
17     self.write(cr, uid, ids, {'currency_id': False})
18 -
19   I create a bank journal with EUR as currency
20 -
21   !record {model: account.journal, id: bank_journal_EUR}:
22     name: Bank Journal(EUR)
23     code: BEUR
24     type: bank
25     analytic_journal_id: account.sit
26     sequence_id: account.sequence_bank_journal
27     default_debit_account_id: account.cash
28     default_credit_account_id: account.cash
29     currency: base.EUR
30     company_id: base.main_company
31     view_id: account.account_journal_bank_view
32 -
33   I create the first invoice on 1st January for 150 EUR
34 -
35   !record {model: account.invoice, id: account_first_invoice_jan_eur}:
36     account_id: account.a_recv
37     address_contact_id: base.res_partner_address_3000
38     address_invoice_id: base.res_partner_address_3000
39     company_id: base.main_company
40     currency_id: base.EUR
41     date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
42     period_id: account.period_1
43     invoice_line:
44       - account_id: account.a_sale
45         name: '[PC1] Basic PC'
46         price_unit: 150.0
47         quantity: 1.0
48         product_id: product.product_product_pc1
49         uos_id: product.product_uom_unit
50     journal_id: account.sales_journal
51     partner_id: base.res_partner_seagate
52     reference_type: none
53 -
54   I Validate invoice by clicking on Validate button
55 -
56   !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_eur}
57 -
58   I check that first invoice move is correct for debtor account(debit - credit == 150)
59 -
60   !python {model: account.invoice}: |
61     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_eur"))
62     assert invoice_id.move_id, "Move not created for open invoice"
63     move_line_obj = self.pool.get('account.move.line')
64     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
65     move_line = move_line_obj.browse(cr, uid, move_lines[0])
66     assert (move_line.debit - move_line.credit == 150.00), "Invoice move is incorrect for debtors account"
67 -
68   I create the second invoice on 1st February for 80 EUR
69 -
70   !record {model: account.invoice, id: account_second_invoice_feb_eur}:
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.EUR
76     date_invoice: !eval "'%s-02-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: 80.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: base.res_partner_seagate
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_second_invoice_feb_eur}
92 -
93   I check that second invoice move is correct for debtor account (debit - credit == 80)
94 -
95   !python {model: account.invoice}: |
96     invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_eur"))
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 == 80.00), "Invoice move is incorrect for debtors account"
102 -
103   I create the first voucher of payment
104   <create with values 120 EUR, journal EUR, and fill amounts 100 for the invoice of 150 EUR and 20 for the invoice of 80 EUR>
105 -
106   !python {model: account.voucher}: |
107     import netsvc, time
108     vals = {}
109     res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_EUR'), 120.00, False, ttype='receipt', date=False)
110     vals = {
111         'account_id': ref('account.cash'),
112         'amount': 120.00,
113         'company_id': ref('base.main_company'),
114         'currency_id': ref('base.EUR'),
115         'journal_id': ref('bank_journal_EUR'),
116         'partner_id': ref('base.res_partner_seagate'),
117         'period_id': ref('account.period_3'),
118         'type': 'receipt',
119         'date': time.strftime("%Y-03-01"),
120         'payment_option': 'with_writeoff',
121         'writeoff_acc_id': ref('account.a_expense'),
122         'comment': 'Write Off',
123         'name': 'First payment: Case 3',
124     }
125     if not res['value']['line_cr_ids']:
126       res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
127     for item in res['value']['line_cr_ids']:
128         if item['amount_unreconciled'] == 150.00:
129             item['amount'] = 100.00
130         else:
131             item['amount'] = 20.00
132     vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
133     id = self.create(cr, uid, vals)
134     voucher_id = self.browse(cr, uid, id)
135     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
136 -
137   I check that writeoff amount computed is 0.00
138 -
139   !python {model: account.voucher}: |
140     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 3'),('partner_id', '=', ref('base.res_partner_seagate'))])
141     voucher_id = self.browse(cr, uid, voucher[0])
142     assert (voucher_id.writeoff_amount == 0.00), "Writeoff amount is not 0.00"
143 -
144   I confirm the voucher
145 -
146   !python {model: account.voucher}: |
147     import netsvc
148     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 3'),('partner_id', '=', ref('base.res_partner_seagate'))])
149     wf_service = netsvc.LocalService("workflow")
150     wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
151 -
152   I check that the move of my first voucher is valid
153 -
154   !python {model: account.voucher}: |
155     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 3'),('partner_id', '=', ref('base.res_partner_seagate'))])
156     voucher_id = self.browse(cr, uid, voucher[0])
157     move_line_obj = self.pool.get('account.move.line')
158     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
159     for move_line in move_line_obj.browse(cr, uid, move_lines):
160         assert move_line.state == 'valid', "Voucher move is not valid"
161 -
162   I check that my debtor account is correct
163 -
164   I check that the debtor account has 2 new lines with 0.00 and 0.00 in amount_currency columns and their credit are 20 and 100 respectively
165 -
166   !python {model: account.voucher}: |
167     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 3'),('partner_id', '=', ref('base.res_partner_seagate'))])
168     voucher_id = self.browse(cr, uid, voucher[0])
169     move_line_obj = self.pool.get('account.move.line')
170     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
171     for move_line in move_line_obj.browse(cr, uid, move_lines):
172         if move_line.credit == 20.00:
173             assert move_line.amount_currency == 0.00, "Debtor account has wrong entry."
174         elif move_line.credit == 100.00:
175             assert move_line.amount_currency == 0.00, "Debtor account has wrong entry."
176 -
177   I check the residual amount of Invoice1 is 50
178 -
179   !python {model: account.invoice}: |
180     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_eur"))
181     move_line_obj = self.pool.get('account.move.line')
182     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)])
183     move_line = move_line_obj.browse(cr, uid, move_lines[0])
184     assert (move_line.amount_residual_currency == 50.0 and move_line.amount_residual == 50.0) , "Residual amount is not correct for first Invoice"
185 -    
186   I check the residual amuont of Invoice2 is 60
187 -
188    !python {model: account.invoice}: |
189     invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_eur"))
190     move_line_obj = self.pool.get('account.move.line')
191     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)])
192     move_line = move_line_obj.browse(cr, uid, move_lines[0])
193     assert (move_line.amount_residual_currency == 60.0 and move_line.amount_residual == 60.0) , "Residual amount is not correct for second Invoice"
194 -
195   I create the second voucher of payment and check to let open the debtor overpaid amount.
196   <create with values 120 EUR, journal EUR, and fill amounts 50 for the invoice of 150 EUR and 70 for the invoice of 80 EUR>
197 -
198   !python {model: account.voucher}: |
199     import netsvc, time
200     vals = {}
201     res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_EUR'), 120.00, False, ttype='receipt', date=False)
202     vals = {
203         'account_id': ref('account.cash'),
204         'amount': 120.00,
205         'company_id': ref('base.main_company'),
206         'currency_id': ref('base.EUR'),
207         'journal_id': ref('bank_journal_EUR'),
208         'partner_id': ref('base.res_partner_seagate'),
209         'period_id': ref('account.period_3'),
210         'type': 'receipt',
211         'date': time.strftime("%Y-04-01"),
212         'payment_option': 'with_writeoff',
213         'writeoff_acc_id': ref('account.a_expense'),
214         'comment': 'Write Off',
215         'name': 'Second payment: Case 3',
216     }
217     if not res['value']['line_cr_ids']:
218       res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
219     for item in res['value']['line_cr_ids']:
220         if item['amount_unreconciled'] == 50.00:
221             item['amount'] = 50.00
222         elif item['amount_unreconciled'] == 60.00:
223             item['amount'] = 70.00
224     vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
225     id = self.create(cr, uid, vals)
226     voucher_id = self.browse(cr, uid, id)
227     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
228 -
229   I check that writeoff amount computed is 0.00
230 -
231   !python {model: account.voucher}: |
232     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 3'),('partner_id', '=', ref('base.res_partner_seagate'))])
233     voucher_id = self.browse(cr, uid, voucher[0])
234     assert (voucher_id.writeoff_amount == 0.00), "Writeoff amount is not 0"
235 -
236   I confirm the voucher
237 -
238   !python {model: account.voucher}: |
239     import netsvc
240     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 3'), ('partner_id', '=', ref('base.res_partner_seagate'))])
241     wf_service = netsvc.LocalService("workflow")
242     wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
243 -
244   I check that the move of my second voucher is valid
245 -
246   !python {model: account.voucher}: |
247     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 3'), ('partner_id', '=', ref('base.res_partner_seagate'))])
248     voucher_id = self.browse(cr, uid, voucher[0])
249     move_line_obj = self.pool.get('account.move.line')
250     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
251     for move_line in move_line_obj.browse(cr, uid, move_lines):
252         assert move_line.state == 'valid', "Voucher move is not valid"
253 -
254   I check that my debtor account is correct
255 -
256   I check that the debtor account has 2 new lines with 0.00 and 0.00 in amount_currency columns and their credit are 70 and 50
257 -
258   !python {model: account.voucher}: |
259     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 3'), ('partner_id', '=', ref('base.res_partner_seagate'))])
260     voucher_id = self.browse(cr, uid, voucher[0])
261     move_line_obj = self.pool.get('account.move.line')
262     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
263     for move_line in move_line_obj.browse(cr, uid, move_lines):
264         if move_line.credit == 70.00:
265             assert move_line.amount_currency == 0.00, "Debtor account has wrong entry."
266         elif move_line.credit == 50.00:
267             assert move_line.amount_currency == 0.00, "Debtor account has wrong entry."
268 -
269   I check the residual amount of Invoice1 is 0
270 -
271   !python {model: account.invoice}: |
272     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_eur"))
273     move_line_obj = self.pool.get('account.move.line')
274     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)])
275     move_line = move_line_obj.browse(cr, uid, move_lines[0])
276     assert (move_line.amount_residual_currency == 0 and move_line.amount_residual == 0) , "Residual amount is not correct for first Invoice"
277 -    
278   I check the residual amuont of Invoice2 is -10
279 -
280    !python {model: account.invoice}: |
281     invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_eur"))
282     move_line_obj = self.pool.get('account.move.line')
283     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)])
284     move_line = move_line_obj.browse(cr, uid, move_lines[0])
285     assert (move_line.amount_residual_currency == -10.0 and move_line.amount_residual == -10.0) , "Residual amount is not correct for second Invoice"