[IMP] hr: onboarding
[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   Only manager can create and take decision about bank and currency there I checkd this test with user who is finance manager.
4 -
5   !context
6     uid: 'res_users_account_voucher_manager'
7 -
8   In order to check the payment with multi-currency in OpenERP, 
9   I create an invoice in EUR and make payment in USD based on the currency rating.
10 -
11   I update the Currency USD in OpenERP for January with rate 1.200000
12 -
13   !python {model: res.currency.rate}: |
14     from datetime import datetime
15     curr_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'USD')])[0]
16     date = '%s-01-01' %(datetime.now().year)
17     ids = self.search(cr, uid, [('currency_id','=',curr_id), ('name', '=', date)])
18     self.write(cr, uid, ids, {'rate': 1.200000})
19 -
20   I update the Currency USD in OpenERP for February with rate 1.400000
21 -
22   !record {model: res.currency.rate, id: feb_usd}:
23     currency_id: base.USD
24     name: !eval "'%s-02-01' %(datetime.now().year)"
25     rate: 1.400000
26 -
27   I create a bank account with USD as currency
28 -
29   !record {model: account.account, id: account_eur_usd_id}:
30     currency_id: base.USD
31     name: "Bank usd"
32     code: "BUSD"
33     type: 'liquidity'
34     user_type: account.data_account_type_asset
35 -
36   I create a bank journal with USD as currency
37 -
38   !record {model: account.journal, id: bank_journal_USD1}:
39     name: Bank Journal Test(USD)
40     code: BEUSD
41     type: bank
42     analytic_journal_id: analytic.sit
43     sequence_id: account.sequence_bank_journal
44     default_debit_account_id: account_eur_usd_id
45     default_credit_account_id: account_eur_usd_id
46     currency: base.USD
47     company_id: base.main_company
48 -
49   On the first of January, I create an invoice of 1000€
50 -
51   !record {model: account.invoice, id: account_invoice_eur_usd}:
52     account_id: account.a_recv
53     company_id: base.main_company
54     currency_id: base.EUR
55     date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
56     period_id: account.period_1
57     invoice_line:
58       - account_id: account.a_sale
59         name: '[PCSC234] PC Assemble SC234'
60         price_unit: 1000.0
61         quantity: 1.0
62         product_id: product.product_product_3
63         uos_id: product.product_uom_unit
64     journal_id: account.sales_journal
65     partner_id: base.res_partner_19
66 -
67   I validate the invoice.
68 -
69   !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_eur_usd}
70 -
71   I check that invoice move is correct
72 -
73   !python {model: account.invoice}: |
74     invoice = self.browse(cr, uid, ref("account_invoice_eur_usd"))
75     assert invoice.state == 'open', "invoice state is not open"
76     assert invoice.period_id, "Period is not created for open invoice"
77     assert invoice.move_id, "Move not created for open invoice"
78     assert invoice.move_id.state == 'posted', "Move state is not posted"
79     for move_line in invoice.move_id.line_id:
80         assert move_line.state == 'valid', "Move line state is not valid"
81 -
82   I set the type receipt for this voucher
83 -
84   !context
85     'type': 'receipt'
86 -
87   On the first of February, I create the voucher of payment with values 1350 USD, journal USD,
88 -
89   !record {model: account.voucher, id: account_voucher_eur_usd_case, view: view_vendor_receipt_form}:
90     account_id: account.cash
91     amount: 1350.0
92     company_id: base.main_company
93     journal_id: bank_journal_USD1
94     name: 'payment: Case EUR/USD'
95     partner_id: base.res_partner_19
96     period_id: account.period_5
97     date: !eval time.strftime("%Y-02-01")
98     payment_option: 'with_writeoff'
99     writeoff_acc_id: account.a_expense
100     comment: 'Write Off'
101 -
102   I fill amount 1400 for the invoice of 1400$
103 -
104   !python {model: account.voucher}: |
105     from openerp.tools import float_compare
106     data = []
107     voucher = self.browse(cr, uid, ref('account_voucher_eur_usd_case'))
108     for item in voucher.line_cr_ids:
109         if float_compare(item.amount_unreconciled, 1400, precision_digits=2) == 0:
110             data += [(item.id, 1400)]
111     assert data, "Credit line not found"
112     for line_id, amount in data:
113         self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
114     assert (voucher.state=='draft'), "Voucher is not in draft state"
115 -
116   I check that writeoff amount computed is -50.0
117 -
118   !python {model: account.voucher}: |
119     from openerp.tools import float_compare
120     voucher = self.browse(cr, uid, ref('account_voucher_eur_usd_case'))
121     assert (float_compare(voucher.writeoff_amount, -50.0, precision_digits=2) == 0), "Writeoff amount is not -50.0"
122 -
123   I confirm the voucher
124 -
125   !workflow {model: account.voucher, action: proforma_voucher, ref: account_voucher_eur_usd_case}
126 -
127   I check that the voucher state is "Posted"
128 -
129   !assert {model: account.voucher, id: account_voucher_eur_usd_case}:
130     - state == 'posted'
131 -
132   I check that the move of voucher is valid
133 -
134   !python {model: account.voucher}: |
135     voucher = self.browse(cr, uid, ref('account_voucher_eur_usd_case'))
136     assert voucher.move_ids, "Move line is not created for this voucher"
137     assert (voucher.number == voucher.move_ids[0].move_id.name), "referance number is not created"
138     assert voucher.period_id, "period is not created"
139     for move_line in voucher.move_ids:
140         assert move_line.state == 'valid', "Voucher move is not valid"
141 -
142   I check that my debtor account is correct
143 -
144   I check that my currency rate difference is correct. 1000 in credit with no amount_currency
145 -
146   I  check that the total reconcilation created entries as expected
147 -
148   I check that my writeoff is correct. 35.71 debit and 50 amount_currency
149 -
150   I check that my bank account is correct. 964.29 debit and 1350 amount_currency
151 -
152   !python {model: account.voucher}: |
153     from openerp.tools import float_compare
154     voucher = self.browse(cr, uid, ref('account_voucher_eur_usd_case'))
155     for move_line in voucher.move_ids:
156         if float_compare(move_line.amount_currency, 1350, precision_digits=2) == 0:
157             assert float_compare(move_line.debit, 964.29, precision_digits=2) == 0,"debtor account is not correct"
158         if float_compare(move_line.amount_currency, 50, precision_digits=2) == 0:
159             assert float_compare(move_line.debit, 35.71, precision_digits=2) == 0,"write off bank account is not correct"
160         if float_compare(move_line.amount_currency, 0.0, precision_digits=2) == 0:
161             assert float_compare(move_line.credit, 1000, precision_digits=2) == 0,"total reconcile is not correct of invoice"
162 -
163   I check that the move of payment in invoice is valid
164 -
165   !python {model: account.invoice}: |
166     invoice = self.browse(cr, uid, ref("account_invoice_eur_usd"))
167     for payment_line in invoice.payment_ids:
168         assert payment_line.state == 'valid', "payment move line state is not valid"
169 -
170   I check the residual amount of invoice should be 0 in residual currency and 0 in amount_residual and paid
171 -
172   !python {model: account.invoice}: |
173     from openerp.tools import float_compare
174     invoice_id = self.browse(cr, uid, ref("account_invoice_eur_usd"))
175     move_line_obj = self.pool.get('account.move.line')
176     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)])
177     move_line = move_line_obj.browse(cr, uid, move_lines[0])
178     assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for Invoice"