972b09702be84f107057ec34b2d993395b5a5317
[odoo/odoo.git] / addons / account_voucher / test / case4_cad_chf.yml
1 -
2   In order to check the Account_voucher module with multi-currency in OpenERP,
3   I create an invoice in CAD and make its Payment in CHF based on the currency rating on that particular date.
4 -
5   I create currency CAD in OpenERP for January of 1.338800 Rate
6 -
7   !record {model: res.currency.rate, id: jan_cad}:
8     currency_id: base.CAD
9     name: !eval "'%s-01-01' %(datetime.now().year)"
10     rate: 1.338800
11 -
12   I create currency CAD in OpenERP for March of 2.000000 Rate
13 -
14   !record {model: res.currency.rate, id: mar_cad}:
15     currency_id: base.CAD
16     name: !eval "'%s-03-01' %(datetime.now().year)"
17     rate: 2.000000
18 -
19   I create currency CHF in OpenERP for January of 1.308600 Rate
20 -
21   !record {model: res.currency.rate, id: jan_chf}:
22     currency_id: base.CHF
23     name: !eval "'%s-01-01' %(datetime.now().year)"
24     rate: 1.308600
25 -
26   I create currency CHF in OpenERP for March of 1.250000 Rate
27 -
28   !record {model: res.currency.rate, id: mar_chf}:
29     currency_id: base.CHF
30     name: !eval "'%s-03-01' %(datetime.now().year)"
31     rate: 1.25000
32 -
33   I create a bank journal with CHF as currency
34 -
35   !record {model: account.journal, id: bank_journal_CHF}:
36     name: Bank Journal(CHF)
37     code: BCHF
38     type: bank
39     analytic_journal_id: account.sit
40     sequence_id: account.sequence_bank_journal
41     default_debit_account_id: account.cash
42     default_credit_account_id: account.cash
43     currency: base.CHF
44     company_id: base.main_company
45     view_id: account.account_journal_bank_view
46 -
47   I create the first invoice on 1st January for 200 CAD
48 -
49   !record {model: account.invoice, id: account_first_invoice_jan_cad}:
50     account_id: account.a_recv
51     address_contact_id: base.res_partner_address_3000
52     address_invoice_id: base.res_partner_address_3000
53     company_id: base.main_company
54     currency_id: base.CAD
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: '[PC1] Basic PC'
60         price_unit: 200.0
61         quantity: 1.0
62         product_id: product.product_product_pc1
63         uos_id: product.product_uom_unit
64     journal_id: account.sales_journal
65     partner_id: base.res_partner_seagate
66     reference_type: none
67 -
68   I Validate invoice by clicking on Validate button
69 -
70   !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_cad}
71 -
72   I check that first invoice move is correct for debtor account (debit - credit == 149.39)
73 -
74   !python {model: account.invoice}: |
75     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad"))
76     assert invoice_id.move_id, "Move not created for open invoice"
77     move_line_obj = self.pool.get('account.move.line')
78     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
79     move_line = move_line_obj.browse(cr, uid, move_lines[0])
80     assert (move_line.debit - move_line.credit == 149.39), "Invoice move is incorrect for debtors account"
81 -
82   I create the first voucher of payment
83   <create with values 200 CHF, journal CHF, and completly pat the invoice of 200 CAD>
84 -
85   !python {model: account.voucher}: |
86     import netsvc, time
87     vals = {}
88     res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_CHF'), 200.00, ref('base.CHF'), ttype='receipt', date=False)
89     vals = {
90         'account_id': ref('account.cash'),
91         'amount': 200.00,
92         'company_id': ref('base.main_company'),
93         'currency_id': ref('base.CHF'),
94         'journal_id': ref('bank_journal_CHF'),
95         'partner_id': ref('base.res_partner_seagate'),
96         'period_id': ref('account.period_3'),
97         'type': 'receipt',
98         'date': time.strftime("%Y-%m-%d"),
99         'payment_option': 'with_writeoff',
100         'writeoff_acc_id': ref('account.a_expense'),
101         'exchange_acc_id': ref('account.o_expense'),
102         'comment': 'Write Off',
103         'name': 'First payment: Case 4',
104     }
105     vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-03-01'), ref('base.CHF'), 200.0)['value'])
106     if not res['value']['line_cr_ids']:
107       res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
108     for item in res['value']['line_cr_ids']:
109         if item['amount_unreconciled'] == 186.74:
110             item['amount'] = 186.74
111     vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
112     id = self.create(cr, uid, vals)
113     voucher_id = self.browse(cr, uid, id)
114     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
115 -
116   I check that writeoff amount computed is 13.26
117 -
118   !python {model: account.voucher}: |
119     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_seagate'))])
120     voucher_id = self.browse(cr, uid, voucher[0])
121     assert (round(voucher_id.writeoff_amount,2) == 13.26), "Writeoff amount is not 13.26 CHF"
122 -
123   I confirm the voucher
124 -
125   !python {model: account.voucher}: |
126     import netsvc
127     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_seagate'))])
128     wf_service = netsvc.LocalService("workflow")
129     wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
130 -
131   I check that the move of my voucher is valid
132 -
133   !python {model: account.voucher}: |
134     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_seagate'))])
135     voucher_id = self.browse(cr, uid, voucher[0])
136     move_line_obj = self.pool.get('account.move.line')
137     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
138     for move_line in move_line_obj.browse(cr, uid, move_lines):
139         assert move_line.state == 'valid', "Voucher move is not valid"
140     assert voucher_id.state == 'posted', "Voucher state is not posted"
141 -
142   I check that my debtor account is correct
143 -
144   I check that the debtor account has 1 new line with -186.74 as amount_currency columns and 149.39 of credit and currency is CHF.
145 -
146   I check that my currency rate difference is correct. 0 in debit with no amount_currency
147 -
148   I check that my writeoff is correct. 11.05 credit and 13.26 amount_currency
149 -
150   !python {model: account.voucher}: |
151     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_seagate'))])
152     voucher_id = self.browse(cr, uid, voucher[0])
153     move_line_obj = self.pool.get('account.move.line')
154     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
155     for move_line in move_line_obj.browse(cr, uid, move_lines):
156         if move_line.amount_currency == 200:
157             assert move_line.debit == 160.00, "Bank account has wrong entry."
158         elif move_line.amount_currency == -186.74:
159             assert move_line.credit == 149.39, "Debtor account has wrong entry."
160         elif move_line.debit == 0.00 and move_line.credit == 0.00:
161             assert move_line.amount_currency == 0.00, "Incorrect Currency Difference."
162         elif move_line.credit == 10.61:
163             assert move_line.amount_currency == 13.26, "Writeoff amount is wrong."
164         else:
165             assert False, "Wrong entry"
166 -
167   I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
168 -
169   !python {model: account.invoice}: |
170     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad"))
171     move_line_obj = self.pool.get('account.move.line')
172     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)])
173     move_line = move_line_obj.browse(cr, uid, move_lines[0])
174     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"