[IMP] put back commit_value
[odoo/odoo.git] / addons / account_voucher / test / case_eur_usd.yml
1 ##YAML test on the account_voucher as depicted in this bug report: https://bugs.launchpad.net/openobject-addons/+bug/954155
2 -
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.
5 -
6   I update the Currency USD in OpenERP for January with rate 1.200000
7 -
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})
14 -
15   I update the Currency USD in OpenERP for February with rate 1.400000
16 -
17   !record {model: res.currency.rate, id: feb_usd}:
18     currency_id: base.USD
19     name: !eval "'%s-02-01' %(datetime.now().year)"
20     rate: 1.400000
21 -
22   I create a bank account with USD as currency
23 -
24   !record {model: account.account, id: account_eur_usd_id}:
25     currency_id: base.USD
26     name: "Bank usd"
27     code: "BUSD"
28     type: 'liquidity'
29     user_type: account.data_account_type_asset
30 -
31   I create a bank journal with USD as currency
32 -
33   !record {model: account.journal, id: bank_journal_USD1}:
34     name: Bank Journal Test(USD)
35     code: BEUSD
36     type: bank
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
41     currency: base.USD
42     company_id: base.main_company
43     view_id: account.account_journal_bank_view
44 -
45   I create an invoice 
46 -
47   !record {model: account.invoice, id: account_invoice_eur_usd}:
48     account_id: account.a_recv
49     company_id: base.main_company
50     currency_id: base.EUR
51     date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
52     period_id: account.period_1
53     invoice_line:
54       - account_id: account.a_sale
55         name: '[PCSC234] PC Assemble SC234'
56         price_unit: 1000.0
57         quantity: 1.0
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
62 -
63   I validate the invoice.
64 -
65   !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_eur_usd}
66 -
67   I check that invoice move is correct
68 -
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"
77 -
78   I set the type receipt for this voucher
79 -
80   !context
81     'type': 'receipt'
82 -
83   I create the voucher of payment with values 1350 USD, journal USD,
84 -
85   !record {model: account.voucher, id: account_voucher_eur_usd_case, view: view_vendor_receipt_form}:
86     account_id: account.cash
87     amount: 1350.0
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
96     comment: 'Write Off'
97 -
98   I fill amount 1400 for the invoice of 1400$
99 -
100   !python {model: account.voucher}: |
101     data = []
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"
109 -
110   I check that writeoff amount computed is -50.0
111 -
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"
115 -
116   I confirm the voucher
117 -
118   !workflow {model: account.voucher, action: proforma_voucher, ref: account_voucher_eur_usd_case}
119 -
120   I check that the voucher state is "Posted"
121 -
122   !assert {model: account.voucher, id: account_voucher_eur_usd_case}:
123     - state == 'posted'
124 -
125   I check that the move of voucher is valid
126 -
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"
134 -
135   I check that my debtor account is correct
136 -
137   I check that my currency rate difference is correct. 1000 in credit with no amount_currency
138 -
139   I  check that the total reconcilation created entries as expected
140 -
141   I check that my writeoff is correct. 35.71 debit and 50 amount_currency
142 -
143   I check that my bank account is correct. 964.29 debit and 1350 amount_currency
144 -
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"
154 -
155   I check that the move of payment in invoice is valid
156 -
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"
161 -
162   I check the residual amount of invoice should be 0 in residual currency and 0 in amount_residual and paid
163 -
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"
170