~tempo-openerp/+junk/loewert-report-name

« back to all changes in this revision

Viewing changes to addons/account_voucher/test/case1_usd_usd.yml

  • Committer: jbe at tempo-consulting
  • Date: 2013-08-21 08:48:11 UTC
  • Revision ID: jbe@tempo-consulting.fr-20130821084811-913uo4l7b5ayxq8m
[NEW] Création de la branche trunk Loewert

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-
 
2
  In order to check the Account_voucher module with multi-currency in OpenERP, 
 
3
  I create 2 Invoices in USD and make 2 Payments in USD based on the currency rating on that particular date
 
4
-
 
5
  I set the income and expense currency accounts on the main company
 
6
-
 
7
  !python {model: res.company}: |
 
8
    from datetime import datetime
 
9
    vals = {
 
10
      'income_currency_exchange_account_id': ref('account.o_expense'),
 
11
      'expense_currency_exchange_account_id': ref('account.o_expense')}
 
12
    self.write(cr, uid, ref('base.main_company'), vals)
 
13
-
 
14
  I create currency USD in OpenERP for January of 1.333333 Rate
 
15
-
 
16
  !python {model: res.currency.rate}: |
 
17
    from datetime import datetime
 
18
    curr_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'USD')])[0]
 
19
    date = '%s-01-01' %(datetime.now().year)
 
20
    ids = self.search(cr, uid, [('currency_id','=',curr_id), ('name', '=', date)])
 
21
    self.write(cr, uid, ids, {'rate': 1.333333})
 
22
-
 
23
  I create currency USD in OpenERP for February of 1.250000 Rate
 
24
-
 
25
  !record {model: res.currency.rate, id: feb_usd}:
 
26
    currency_id: base.USD
 
27
    name: !eval "'%s-02-01' %(datetime.now().year)"
 
28
    rate: 1.250000
 
29
 
 
30
-
 
31
  I create currency USD in OpenERP for March of 1.111111 Rate
 
32
-
 
33
  !record {model: res.currency.rate, id: mar_usd}:
 
34
    currency_id: base.USD
 
35
    name: !eval "'%s-03-01' %(datetime.now().year)"
 
36
    rate: 1.111111
 
37
 
 
38
-
 
39
  I create currency USD in OpenERP for April of 1.052632 Rate
 
40
-
 
41
  !record {model: res.currency.rate, id: apr_usd}:
 
42
    currency_id: base.USD
 
43
    name: !eval "'%s-04-01' %(datetime.now().year)"
 
44
    rate: 1.052632
 
45
 
 
46
-
 
47
  I create a cash account with currency USD
 
48
-
 
49
  !record {model: account.account, id: account_cash_usd_id}:
 
50
    currency_id: base.USD
 
51
    name: "cash account in usd"
 
52
    code: "Xcash usd"
 
53
    type: 'liquidity'
 
54
    user_type: "account.data_account_type_cash"
 
55
 
 
56
-
 
57
  I create a bank journal with USD as currency
 
58
-
 
59
  !record {model: account.journal, id: bank_journal_USD}:
 
60
    name: Bank Journal(USD)
 
61
    code: BUSD
 
62
    type: bank
 
63
    analytic_journal_id: account.sit
 
64
    sequence_id: account.sequence_bank_journal
 
65
    default_debit_account_id: account_cash_usd_id
 
66
    default_credit_account_id: account_cash_usd_id
 
67
    currency: base.USD
 
68
    company_id: base.main_company
 
69
 
 
70
-
 
71
  I create the first invoice on 1st January  for 200 USD
 
72
-
 
73
  !record {model: account.invoice, id: account_invoice_jan}:
 
74
    account_id: account.a_recv
 
75
    company_id: base.main_company
 
76
    currency_id: base.USD
 
77
    date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
 
78
    period_id: account.period_1
 
79
    invoice_line:
 
80
      - account_id: account.a_sale
 
81
        name: '[PCSC234] PC Assemble SC234'
 
82
        price_unit: 200.0
 
83
        quantity: 1.0
 
84
        product_id: product.product_product_3
 
85
        uos_id: product.product_uom_unit
 
86
    journal_id: account.sales_journal
 
87
    partner_id: base.res_partner_19
 
88
    reference_type: none
 
89
-
 
90
  I Validate invoice by clicking on Validate button
 
91
-
 
92
  !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_jan}
 
93
-
 
94
  I check that first invoice move is correct for debtor account (debit - credit == 150.0)
 
95
-
 
96
  !python {model: account.invoice}: |
 
97
    invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
 
98
    assert invoice_id.move_id, "Move not created for open invoice"
 
99
    move_line_obj = self.pool.get('account.move.line')
 
100
    move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
 
101
    move_line = move_line_obj.browse(cr, uid, move_lines[0])
 
102
    assert (move_line.debit - move_line.credit == 150.0), "Invoice move is not correct for debtors account"
 
103
-
 
104
  I create the second invoice on 1st February for 100 USD
 
105
-
 
106
  !record {model: account.invoice, id: account_invoice_feb}:
 
107
    account_id: account.a_recv
 
108
    company_id: base.main_company
 
109
    currency_id: base.USD
 
110
    date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
 
111
    period_id: account.period_2
 
112
    invoice_line:
 
113
      - account_id: account.a_sale
 
114
        name: '[PCSC234] PC Assemble SC234'
 
115
        price_unit: 100.0
 
116
        quantity: 1.0
 
117
        product_id: product.product_product_3
 
118
        uos_id: product.product_uom_unit
 
119
    journal_id: account.sales_journal
 
120
    partner_id: base.res_partner_19
 
121
    reference_type: none
 
122
-
 
123
  I Validate invoice by clicking on Validate button
 
124
-
 
125
  !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_feb}
 
126
-
 
127
  I check that second invoice move is correct for debtor account (debit - credit == 80)
 
128
-
 
129
  !python {model: account.invoice}: |
 
130
    invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
 
131
    assert invoice_id.move_id, "Move not created for open invoice"
 
132
    move_line_obj = self.pool.get('account.move.line')
 
133
    move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
 
134
    move_line = move_line_obj.browse(cr, uid, move_lines[0])
 
135
    assert (move_line.debit - move_line.credit == 80), "Invoice move is not correct for debtors account"
 
136
 
 
137
-
 
138
  I set the context that will be used for the encoding of all the vouchers of this file
 
139
-
 
140
  !context
 
141
    'type': 'receipt'
 
142
-
 
143
  On the first March, I create the first voucher of payment with values 240 USD, journal USD, 
 
144
-
 
145
  !record {model: account.voucher, id: account_voucher_1_case1, view: view_vendor_receipt_form}:
 
146
    account_id: account.cash
 
147
    amount: 240.0
 
148
    company_id: base.main_company
 
149
    journal_id: bank_journal_USD
 
150
    name: 'First payment: Case 1 USD/USD'
 
151
    partner_id: base.res_partner_19
 
152
    period_id: account.period_3
 
153
    date: !eval time.strftime("%Y-03-01")
 
154
    payment_option: 'with_writeoff'
 
155
    writeoff_acc_id: account.a_expense
 
156
    comment: 'Write Off'
 
157
 
 
158
-
 
159
  I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$>
 
160
-
 
161
  !python {model: account.voucher}: |
 
162
    import netsvc, time
 
163
    vals = {}
 
164
    voucher_id = self.browse(cr, uid, ref('account_voucher_1_case1'))
 
165
    data = []
 
166
    for item in voucher_id.line_cr_ids:
 
167
        if item.amount_unreconciled == 200.00:
 
168
            data += [(item.id, 180.0)]
 
169
        else:
 
170
            data += [(item.id, 70.0)]
 
171
    for line_id, amount in data:
 
172
        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
 
173
    assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 
174
-
 
175
  I check that writeoff amount computed is -10.0
 
176
-
 
177
  !python {model: account.voucher}: |
 
178
    voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
 
179
    voucher_id = self.browse(cr, uid, voucher[0])
 
180
    assert (voucher_id.writeoff_amount == -10.0), "Writeoff amount is not -10.0"
 
181
-
 
182
  I confirm the voucher
 
183
-
 
184
  !python {model: account.voucher}: |
 
185
    import netsvc
 
186
    voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
 
187
    wf_service = netsvc.LocalService("workflow")
 
188
    wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
 
189
-
 
190
  I check that the move of my first voucher is valid
 
191
-
 
192
  !python {model: account.voucher}: |
 
193
    voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
 
194
    voucher_id = self.browse(cr, uid, voucher[0])
 
195
    move_line_obj = self.pool.get('account.move.line')
 
196
    move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
 
197
    for move_line in move_line_obj.browse(cr, uid, move_lines):
 
198
        assert move_line.state == 'valid', "Voucher move is not valid"
 
199
-
 
200
  I check that my debtor account is correct
 
201
-
 
202
  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 162 and 63
 
203
-
 
204
  I check that my write-off is correct. 9 debit and 10 amount_currency
 
205
-
 
206
  !python {model: account.voucher}: |
 
207
    voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
 
208
    voucher_id = self.browse(cr, uid, voucher[0])
 
209
    move_line_obj = self.pool.get('account.move.line')
 
210
    move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
 
211
    for move_line in move_line_obj.browse(cr, uid, move_lines):
 
212
        if move_line.amount_currency == -180.00:
 
213
            assert move_line.credit == 162.00, "Debtor account has wrong entry."
 
214
        elif move_line.amount_currency == -70.00:
 
215
            assert move_line.credit == 63.00, "Debtor account has wrong entry."
 
216
        elif move_line.amount_currency == 10.00:
 
217
            assert move_line.debit == 9.00, "Writeoff amount is wrong."
 
218
        elif move_line.amount_currency == 240.00:
 
219
            assert move_line.debit == 216.00, "Bank entry is wrong."
 
220
        else:
 
221
            assert False, "Unrecognized journal entry"
 
222
-
 
223
  I check the residual amount of Invoice1, should be 20 in amount_currency
 
224
-
 
225
  !python {model: account.invoice}: |
 
226
    invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
 
227
    move_line_obj = self.pool.get('account.move.line')
 
228
    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)])
 
229
    move_line = move_line_obj.browse(cr, uid, move_lines[0])
 
230
    assert (move_line.amount_residual_currency == 20.0) , "Residual amount is not correct for first Invoice"
 
231
-
 
232
  I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
 
233
-
 
234
  !python {model: account.invoice}: |
 
235
    invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
 
236
    move_line_obj = self.pool.get('account.move.line')
 
237
    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)])
 
238
    move_line = move_line_obj.browse(cr, uid, move_lines[0])
 
239
    assert (move_line.amount_residual_currency == 30.0) , "Residual amount is not correct for first Invoice"
 
240
-
 
241
  On the first April, I create the second voucher of payment with values 45 USD, journal USD, 
 
242
-
 
243
  !record {model: account.voucher, id: account_voucher_2_case1, view: view_vendor_receipt_form}:
 
244
    account_id: account.cash
 
245
    amount: 45.0
 
246
    company_id: base.main_company
 
247
    journal_id: bank_journal_USD
 
248
    name: 'Second payment: Case 1'
 
249
    partner_id: base.res_partner_19
 
250
    period_id: account.period_3
 
251
    date: !eval time.strftime("%Y-04-01")
 
252
    payment_option: 'with_writeoff'
 
253
    writeoff_acc_id: account.a_expense
 
254
    comment: 'Write Off'
 
255
-
 
256
  I fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$
 
257
-
 
258
  !python {model: account.voucher}: |
 
259
    import netsvc, time
 
260
    vals = {}
 
261
    voucher_id = self.browse(cr, uid, ref('account_voucher_2_case1'))
 
262
    data = []
 
263
    for item in voucher_id.line_cr_ids:
 
264
        if item.amount_unreconciled == 20.00:
 
265
            data += [(item.id, 20.0)]
 
266
        else:
 
267
            data += [(item.id, 30.0)]
 
268
    for line_id, amount in data:
 
269
        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
 
270
    assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 
271
-
 
272
  I check that writeoff amount computed is -5.0
 
273
-
 
274
  !python {model: account.voucher}: |
 
275
    voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
 
276
    voucher_id = self.browse(cr, uid, voucher[0])
 
277
    assert (voucher_id.writeoff_amount == -5.0), "Writeoff amount is not -5.0"
 
278
-
 
279
  I confirm the voucher
 
280
-
 
281
  !python {model: account.voucher}: |
 
282
    import netsvc
 
283
    voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
 
284
    wf_service = netsvc.LocalService("workflow")
 
285
    wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
 
286
-
 
287
  I check that the move of my second voucher is valid
 
288
-
 
289
  !python {model: account.voucher}: |
 
290
    voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
 
291
    voucher_id = self.browse(cr, uid, voucher[0])
 
292
    move_line_obj = self.pool.get('account.move.line')
 
293
    move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
 
294
    for move_line in move_line_obj.browse(cr, uid, move_lines):
 
295
        assert move_line.state == 'valid', "Voucher move is not valid"
 
296
-
 
297
  I check that my debtor account is correct
 
298
-
 
299
  I check that the debtor account has 2 new lines with -20 and -30 as amount_currency columns and their credit columns are respectively 19 and 28.5
 
300
-
 
301
  I check that my currency rate difference is correct. 8.5 in credit with no amount_currency
 
302
-
 
303
  I  check that the total reconcilation created entries as expected
 
304
-
 
305
  I check that my writeoff is correct. 4.75 debit and 5 amount_currency
 
306
-
 
307
  !python {model: account.voucher}: |
 
308
    voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
 
309
    voucher_id = self.browse(cr, uid, voucher[0])
 
310
    move_line_obj = self.pool.get('account.move.line')
 
311
    move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
 
312
    reconcile_a = reconcile_b = False
 
313
    for move_line in move_line_obj.browse(cr, uid, move_lines):
 
314
        if move_line.amount_currency == -20.00:
 
315
            assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled"
 
316
            reconcile_b = move_line.reconcile_id.id
 
317
        elif move_line.amount_currency == -30.00:
 
318
            assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled"
 
319
            reconcile_a = move_line.reconcile_id.id
 
320
    for move_line in move_line_obj.browse(cr, uid, move_lines):
 
321
        if move_line.amount_currency == -20.00:
 
322
            assert move_line.credit == 19.00, "Debtor account has wrong entry."
 
323
        elif move_line.amount_currency == -30.00:
 
324
            assert move_line.credit == 28.50, "Debtor account has wrong entry."
 
325
        elif move_line.amount_currency == 5.00:
 
326
            assert move_line.debit == 4.75, "Writeoff amount is wrong."
 
327
        elif move_line.debit == 11.5 and move_line.account_id.reconcile:
 
328
            assert move_line.amount_currency == 0.0 and move_line.reconcile_id.id == reconcile_a, "Exchange difference entry for the invoice of 100$ is wrong"
 
329
        elif move_line.credit == 11.5:
 
330
            assert move_line.amount_currency == 0.0
 
331
        elif move_line.debit == 31.0 and move_line.account_id.reconcile:
 
332
            assert move_line.amount_currency == 0.0 and move_line.reconcile_id.id == reconcile_b, "Exchange difference entry for the invoice of 200$ is wrong"
 
333
        elif move_line.credit == 31.0:
 
334
            assert move_line.amount_currency == 0.0
 
335
        elif move_line.amount_currency == 45.00:
 
336
            assert move_line.debit == 42.75, "Bank entry is wrong."
 
337
        else:
 
338
            assert False, "Unrecognized journal entry"
 
339
-
 
340
  I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
 
341
-
 
342
  !python {model: account.invoice}: |
 
343
    invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
 
344
    move_line_obj = self.pool.get('account.move.line')
 
345
    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)])
 
346
    move_line = move_line_obj.browse(cr, uid, move_lines[0])
 
347
    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"
 
348
-
 
349
  I check the residual amuont of Invoice2, should be 0 in residual currency and 0 in amount_residual and paid
 
350
-
 
351
  !python {model: account.invoice}: |
 
352
    invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
 
353
    move_line_obj = self.pool.get('account.move.line')
 
354
    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)])
 
355
    move_line = move_line_obj.browse(cr, uid, move_lines[0])
 
356
    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"