2 I create a currency rate for USD for january of 1.333333
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})
11 I create a currency rate for USD for february of 1.250000
13 !record {model: res.currency.rate, id: feb_usd}:
15 name: !eval "'%s-02-01' %(datetime.now().year)"
19 I create a currency rate for USD for march of 1.111111
21 !record {model: res.currency.rate, id: mar_usd}:
23 name: !eval "'%s-03-01' %(datetime.now().year)"
27 I create a currency rate for USD for april of 1.052632
29 !record {model: res.currency.rate, id: apr_usd}:
31 name: !eval "'%s-04-01' %(datetime.now().year)"
35 I create a bank journal with USD as currency
37 !record {model: account.journal, id: bank_journal_USD}:
38 name: Bank Journal(USD)
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
46 company_id: base.main_company
47 view_id: account.account_journal_bank_view
50 I set up some accounts for currency rate expense/income in my company
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
56 I create new partner Mark Strauss.
58 !record {model: res.partner, id: res_partner_strauss0}:
63 street: 1 rue Rockfeller
66 name: Mr. Mark Strauss
68 I create the first invoice on 1st January for 200 USD
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
76 date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
77 period_id: account.period_1
79 - account_id: account.a_sale
80 name: '[PC1] Basic PC'
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
89 I Validate invoice by clicking on Validate button
91 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_jan}
93 I check that first invoice move is correct for debtor account (debit - credit == 150.0)
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"
103 I create the second invoice on 1st February for 100 USD
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
114 - account_id: account.a_sale
115 name: '[PC1] Basic PC'
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
124 I Validate invoice by clicking on Validate button
126 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_feb}
128 I check that second invoice move is correct for debtor account (debit - credit == 80)
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"
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$>
142 !python {model: account.voucher}: |
145 res = self.onchange_partner_id(cr, uid, [], ref("res_partner_strauss0"), ref('bank_journal_USD'), 240.00, 2, ttype='receipt', date=False)
147 'account_id': ref('account.cash'),
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'),
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',
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
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"
173 I check that writeoff amount computed is -10.0
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"
180 I check that currency rate difference is -34.0
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"
187 I confirm the voucher
189 !python {model: account.voucher}: |
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)
195 I check that the move of my first voucher is valid
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"
205 I check that my debtor account is correct
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
209 I check that my currency rate difference is correct. 34 in credit with no amount_currency
211 I check that my write-off is correct. 9 debit and 10 amount_currency
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."
228 I check the residual amount of Invoice1, should be 20 in amount_currency and 15 in company currency
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"
237 I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
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"
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$>
250 !python {model: account.voucher}: |
253 res = self.onchange_partner_id(cr, uid, [], ref("res_partner_strauss0"), ref('bank_journal_USD'), 45.00, 2, ttype='receipt', date=False)
255 'account_id': ref('account.cash'),
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'),
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',
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
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"
281 I check that writeoff amount computed is -5.0
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"
288 I check that currency rate difference is -8.50
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"
295 I confirm the voucher
297 !python {model: account.voucher}: |
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)
303 I check that the move of my second voucher is valid
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"
313 I check that my debtor account is correct
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.
317 I check that my currency rate difference is correct. 8.5 in credit with no amount_currency
319 I check that my writeoff is correct. 4.75 debit and 5 amount_currency
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."
336 I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
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"
345 I check the residual amuont of Invoice2, should be 0 in residual currency and 0 in amount_residual and paid
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"