1 ##YAML test on the account_voucher as depicted in this bug report: https://bugs.launchpad.net/openobject-addons/+bug/954155
3 In order to check the payment with multi-currency in OpenERP,
4 I create an invoice in EUR and make payment in USD based on the currency rating.
6 I update the Currency USD in OpenERP for January with rate 1.200000
8 !python {model: res.currency.rate}: |
9 from datetime import datetime
10 curr_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'USD')])[0]
11 date = '%s-01-01' %(datetime.now().year)
12 ids = self.search(cr, uid, [('currency_id','=',curr_id), ('name', '=', date)])
13 self.write(cr, uid, ids, {'rate': 1.200000})
15 I update the Currency USD in OpenERP for February with rate 1.400000
17 !record {model: res.currency.rate, id: feb_usd}:
19 name: !eval "'%s-02-01' %(datetime.now().year)"
22 I create a bank account with USD as currency
24 !record {model: account.account, id: account_eur_usd_id}:
29 user_type: account.data_account_type_asset
31 I create a bank journal with USD as currency
33 !record {model: account.journal, id: bank_journal_USD1}:
34 name: Bank Journal Test(USD)
37 analytic_journal_id: account.sit
38 sequence_id: account.sequence_bank_journal
39 default_debit_account_id: account_eur_usd_id
40 default_credit_account_id: account_eur_usd_id
42 company_id: base.main_company
43 view_id: account.account_journal_bank_view
47 !record {model: account.invoice, id: account_invoice_eur_usd}:
48 account_id: account.a_recv
49 company_id: base.main_company
51 date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
52 period_id: account.period_1
54 - account_id: account.a_sale
55 name: '[PCSC234] PC Assemble SC234'
58 product_id: product.product_product_3
59 uos_id: product.product_uom_unit
60 journal_id: account.sales_journal
61 partner_id: base.res_partner_19
63 I validate the invoice.
65 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_eur_usd}
67 I check that invoice move is correct
69 !python {model: account.invoice}: |
70 invoice = self.browse(cr, uid, ref("account_invoice_eur_usd"))
71 assert invoice.state == 'open', "invoice state is not open"
72 assert invoice.period_id, "Period is not created for open invoice"
73 assert invoice.move_id, "Move not created for open invoice"
74 assert invoice.move_id.state == 'posted', "Move state is not posted"
75 for move_line in invoice.move_id.line_id:
76 assert move_line.state == 'valid', "Move line state is not valid"
78 I set the type receipt for this voucher
83 I create the voucher of payment with values 1350 USD, journal USD,
85 !record {model: account.voucher, id: account_voucher_eur_usd_case, view: view_vendor_receipt_form}:
86 account_id: account.cash
88 company_id: base.main_company
89 journal_id: bank_journal_USD1
90 name: 'payment: Case EUR/USD'
91 partner_id: base.res_partner_19
92 period_id: account.period_5
93 date: !eval time.strftime("%Y-02-01")
94 payment_option: 'with_writeoff'
95 writeoff_acc_id: account.a_expense
98 I fill amount 1400 for the invoice of 1400$
100 !python {model: account.voucher}: |
102 voucher = self.browse(cr, uid, ref('account_voucher_eur_usd_case'))
103 for item in voucher.line_cr_ids:
104 if item.amount_unreconciled == 1400:
105 data += [(item.id, 1400)]
106 for line_id, amount in data:
107 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
108 assert (voucher.state=='draft'), "Voucher is not in draft state"
110 I check that writeoff amount computed is -50.0
112 !python {model: account.voucher}: |
113 voucher = self.browse(cr, uid, ref('account_voucher_eur_usd_case'))
114 assert (voucher.writeoff_amount == -50.0), "Writeoff amount is not -50.0"
116 I confirm the voucher
118 !workflow {model: account.voucher, action: proforma_voucher, ref: account_voucher_eur_usd_case}
120 I check that the voucher state is "Posted"
122 !assert {model: account.voucher, id: account_voucher_eur_usd_case}:
125 I check that the move of voucher is valid
127 !python {model: account.voucher}: |
128 voucher = self.browse(cr, uid, ref('account_voucher_eur_usd_case'))
129 assert voucher.move_ids, "Move line is not created for this voucher"
130 assert (voucher.number == voucher.move_ids[0].move_id.name), "referance number is not created"
131 assert voucher.period_id, "period is not created"
132 for move_line in voucher.move_ids:
133 assert move_line.state == 'valid', "Voucher move is not valid"
135 I check that my debtor account is correct
137 I check that my currency rate difference is correct. 1000 in credit with no amount_currency
139 I check that the total reconcilation created entries as expected
141 I check that my writeoff is correct. 35.71 debit and 50 amount_currency
143 I check that my bank account is correct. 964.29 debit and 1350 amount_currency
145 !python {model: account.voucher}: |
146 voucher = self.browse(cr, uid, ref('account_voucher_eur_usd_case'))
147 for move_line in voucher.move_ids:
148 if move_line.amount_currency == 1350:
149 assert move_line.debit == 964.29,"debtor account is not correct"
150 if move_line.amount_currency == 50:
151 assert move_line.debit == 35.71,"write off bank account is not correct"
152 if move_line.amount_currency == 0.0:
153 assert move_line.credit == 1000,"total reconcile is not correct of invoice"
155 I check that the move of payment in invoice is valid
157 !python {model: account.invoice}: |
158 invoice = self.browse(cr, uid, ref("account_invoice_eur_usd"))
159 for payment_line in invoice.payment_ids:
160 assert payment_line.state == 'valid', "payment move line state is not valid"
162 I check the residual amount of invoice should be 0 in residual currency and 0 in amount_residual and paid
164 !python {model: account.invoice}: |
165 invoice_id = self.browse(cr, uid, ref("account_invoice_eur_usd"))
166 move_line_obj = self.pool.get('account.move.line')
167 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)])
168 move_line = move_line_obj.browse(cr, uid, move_lines[0])
169 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 Invoice"