[FIX] account_voucher: small fixes in account_voucher.py due to last commit and updat...
authorQuentin (OpenERP) <qdp-launchpad@openerp.com>
Wed, 23 Nov 2011 13:38:14 +0000 (14:38 +0100)
committerQuentin (OpenERP) <qdp-launchpad@openerp.com>
Wed, 23 Nov 2011 13:38:14 +0000 (14:38 +0100)
bzr revid: qdp-launchpad@openerp.com-20111123133814-w2vsqmklajtyonxk

addons/account_voucher/account_voucher.py
addons/account_voucher/test/case1_usd_usd.yml
addons/account_voucher/test/case2_suppl_usd_eur.yml
addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml
addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml
addons/account_voucher/test/case3_eur_eur.yml
addons/account_voucher/test/case4_cad_chf.yml

index 4b099ee..b2c87a5 100644 (file)
@@ -600,7 +600,6 @@ class account_voucher(osv.osv):
                         rs['amount'] = amount
                         total_credit -= amount
 
-            default['value']['line_ids'].append(rs)
             if rs['type'] == 'cr':
                 default['value']['line_cr_ids'].append(rs)
             else:
@@ -880,6 +879,7 @@ class account_voucher(osv.osv):
 
     def _convert_amount(self, cr, uid, amount, voucher_id, context=None):
         #TODO: doccument me
+        #TODO: rounding errors
         currency_obj = self.pool.get('res.currency')
         voucher = self.browse(cr, uid, voucher_id, context=context)
         res = amount
@@ -892,8 +892,7 @@ class account_voucher(osv.osv):
             rate_between_voucher_and_base = voucher.payment_rate or 1.0
             res = amount / rate_between_voucher_and_base * rate_between_base_and_company
         else:
-            res = currency_obj.compute(cr, uid, voucher.currency_id.id, voucher.company_id.currency_id.id, amount, context=ctx)
-        print 'res', res
+            res = currency_obj.compute(cr, uid, voucher.currency_id.id, voucher.company_id.currency_id.id, amount, context=context)
         return res
 
     def voucher_move_line_create(self, cr, uid, voucher_id, line_total, move_id, company_currency, current_currency, context=None):
index e19e7e3..96a0e07 100644 (file)
     assert (move_line.debit - move_line.credit == 80), "Invoice move is not correct for debtors account"
 
 -
-  I create the first voucher of payment
-  <create with values 240 USD, journal USD, and fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$>
+  I set the context that will be used for the encoding of all the vouchers of this file
+-
+  !context
+    'type': 'receipt'
+-
+  I create the first voucher of payment with values 240 USD, journal USD, 
+-
+  !record {model: account.voucher, id: account_voucher_1_case1, view: view_vendor_receipt_form}:
+    account_id: account.cash
+    amount: 240.0
+    company_id: base.main_company
+    journal_id: bank_journal_USD
+    name: 'First payment: Case 1 USD/USD'
+    partner_id: base.res_partner_seagate
+    period_id: account.period_3
+    date: !eval time.strftime("%Y-03-01")
+    payment_option: 'with_writeoff'
+    writeoff_acc_id: account.a_expense
+    comment: 'Write Off'
+
+-
+  I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$>
 -
   !python {model: account.voucher}: |
     import netsvc, time
     vals = {}
-    res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_USD'), 240.00, 2, ttype='receipt', date=False)
-    vals = {
-        'account_id': ref('account.cash'),
-        'amount': 240.00,
-        'company_id': ref('base.main_company'),
-        'currency_id': ref('base.USD'),
-        'journal_id': ref('bank_journal_USD'),
-        'partner_id': ref('base.res_partner_seagate'),
-        'period_id': ref('account.period_3'),
-        'type': 'receipt',
-        'date': time.strftime("%Y-%m-%d"),
-        'payment_option': 'with_writeoff',
-        'writeoff_acc_id': ref('account.a_expense'),
-        'comment': 'Write Off',
-        'name': 'First payment: Case 1 USD/USD',
-    }
-    vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-03-01'), ref('base.USD'), 240)['value'])
-    if not res['value']['line_cr_ids']:
-      res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
-    for item in res['value']['line_cr_ids']:
-        if item['amount_unreconciled'] == 200.00:
-            item['amount'] = 180.00
+    voucher_id = self.browse(cr, uid, ref('account_voucher_1_case1'))
+    data = []
+    for item in voucher_id.line_cr_ids:
+        if item.amount_unreconciled == 200.00:
+            data += [(item.id, 180.0)]
         else:
-            item['amount'] = 70.00
-    vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
-    id = self.create(cr, uid, vals)
-    voucher_id = self.browse(cr, uid, id)
+            data += [(item.id, 70.0)]
+    for line_id, amount in data:
+        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 -
   I check that writeoff amount computed is 10.0
     move_line = move_line_obj.browse(cr, uid, move_lines[0])
     assert (move_line.amount_residual_currency == 30.0) , "Residual amount is not correct for first Invoice"
 -
-  I create the second voucher of payment
-  <create with values 45 USD, journal USD, and fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$>
-  
+  I create the second voucher of payment with values 45 USD, journal USD, 
+-
+  !record {model: account.voucher, id: account_voucher_2_case1}:
+    account_id: account.cash
+    amount: 45.0
+    company_id: base.main_company
+    journal_id: bank_journal_USD
+    name: 'Second payment: Case 1'
+    partner_id: base.res_partner_seagate
+    period_id: account.period_3
+    date: !eval time.strftime("%Y-04-01")
+    payment_option: 'with_writeoff'
+    writeoff_acc_id: account.a_expense
+    exchange_acc_id: account.o_expense
+    comment: 'Write Off'
+-
+  I fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$
 -
   !python {model: account.voucher}: |
     import netsvc, time
     vals = {}
-    res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_USD'), 45.00, 2, ttype='receipt', date=False)
-    vals = {
-        'account_id': ref('account.cash'),
-        'amount': 45.00,
-        'exchange_acc_id': ref('account.o_expense'),
-        'company_id': ref('base.main_company'),
-        'currency_id': ref('base.USD'),
-        'journal_id': ref('bank_journal_USD'),
-        'partner_id': ref('base.res_partner_seagate'),
-        'period_id': ref('account.period_3'),
-        'type': 'receipt',
-        'date': time.strftime("%Y-%m-%d"),
-        'payment_option': 'with_writeoff',
-        'writeoff_acc_id': ref('account.a_expense'),
-        'comment': 'Write Off',
-        'name': 'Second payment: Case 1',
-    }
-    vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-04-01'), ref('base.USD'), 45.0)['value'])
-    if not res['value']['line_cr_ids']:
-      res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
-    for item in res['value']['line_cr_ids']:
-        if item['amount_unreconciled'] == 20.00:
-            item['amount'] = 20.00
+    voucher_id = self.browse(cr, uid, ref('account_voucher_2_case1'))
+    data = []
+    for item in voucher_id.line_cr_ids:
+        if item.amount_unreconciled == 20.00:
+            data += [(item.id, 20.0)]
         else:
-            item['amount'] = 30.00
-    vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
-    id = self.create(cr, uid, vals)
-    voucher_id = self.browse(cr, uid, id)
+            data += [(item.id, 30.0)]
+    for line_id, amount in data:
+        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 -
   I check that writeoff amount computed is 5.0
index 23f11d2..6d6f71b 100644 (file)
     move_line = move_line_obj.browse(cr, uid, move_lines[0])
     assert (move_line.debit - move_line.credit == -80), "Invoice move is incorrect for debtors account"
 -
-  I create the first voucher of payment
-  <create with values 240 EUR, journal EUR, and fills amount 180 for the invoice of 200$ and 70 for the invoice of 100$>
+  I set the context that will be used for the encoding of all the vouchers of this file
+-
+  !context
+    'type': 'payment'
+-
+  I create the first voucher of payment with values 240 EUR, journal EUR
+-
+  !record {model: account.voucher, id: account_voucher_1_case2_suppl, view: view_vendor_payment_form}:
+    account_id: account.cash
+    amount: 240.0
+    company_id: base.main_company
+    journal_id: bank_journal_EUR
+    name: 'First payment: Case 2 SUPPL USD/EUR',
+    partner_id: base.res_partner_seagate
+    period_id: account.period_3
+    date: !eval time.strftime("%Y-03-01")
+    payment_option: 'with_writeoff'
+    writeoff_acc_id: account.a_expense
+    comment: 'Write Off'
+
+-
+  I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$
 -
   !python {model: account.voucher}: |
     import netsvc, time
     vals = {}
-    res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_EUR'), 240.0, 2, ttype='payment', date=False)
-    vals = {
-        'account_id': ref('account.cash'),
-        'amount': 240.0,
-        'company_id': ref('base.main_company'),
-        'currency_id': ref('base.EUR'),
-        'journal_id': ref('bank_journal_EUR'),
-        'partner_id': ref('base.res_partner_seagate'),
-        'period_id': ref('account.period_3'),
-        'type': 'payment',
-        'date': time.strftime("%Y-03-01"),
-        'payment_option': 'with_writeoff',
-        'writeoff_acc_id': ref('account.a_expense'),
-        'comment': 'Write Off',
-        'name': 'First payment: Case 2 SUPPL USD/EUR',
-    }
-    if not res['value']['line_dr_ids']:
-      res['value']['line_dr_ids'] = [{'type': 'dr', 'account_id': ref('account.a_pay'),}]
-    for item in res['value']['line_dr_ids']:
-        if item['amount_unreconciled'] == 200.00:
-            item['amount'] = 180.00
+    voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2_suppl'))
+    data = []
+    for item in voucher_id.line_cr_ids:
+        if item.amount_unreconciled == 200.00:
+            data += [(item.id, 180.0)]
         else:
-            item['amount'] = 70.00
-    vals['line_dr_ids'] = [(0,0,i) for i in res['value']['line_dr_ids']]
-    id = self.create(cr, uid, vals)
-    voucher_id = self.browse(cr, uid, id)
+            data += [(item.id, 70.0)]
+    for line_id, amount in data:
+        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 -
   I check that writeoff amount computed is -15.0
     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)])
     move_line = move_line_obj.browse(cr, uid, move_lines[0])
     assert (move_line.amount_residual_currency == 20.0 and move_line.amount_residual == 15) , "Residual amount is not correct for first Invoice"
--    
+-
   I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
 -
    !python {model: account.invoice}: |
     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)])
     move_line = move_line_obj.browse(cr, uid, move_lines[0])
     assert (move_line.amount_residual_currency == 30 and move_line.amount_residual == 24) , "Residual amount is not correct for second Invoice"
--  
-  I create the second voucher of payment
-  <create with values 45 USD, journal USD, and fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$>
+-
+  I create the second voucher of payment with values 45 USD, journal USD, 
+-
+  !record {model: account.voucher, id: account_voucher_2_case2_suppl, view: view_vendor_payment_form}:
+    account_id: account.cash
+    amount: 45.0
+    company_id: base.main_company
+    journal_id: bank_journal_USD
+    partner_id: base.res_partner_seagate
+    period_id: account.period_3
+    date: !eval time.strftime("%Y-04-01")
+    payment_option: 'with_writeoff'
+    writeoff_acc_id: account.a_expense
+    comment: 'Write Off'
+    name: 'Second payment: Case 2 SUPPL USD/EUR'
+
+-
+  I fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$>
 -
   !python {model: account.voucher}: |
     import netsvc, time
     vals = {}
-    res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_EUR'), 45.0, 2, ttype='payment', date=False)
-    vals = {
-        'account_id': ref('account.cash'),
-        'amount': 45.0,
-        'company_id': ref('base.main_company'),
-        'currency_id': ref('base.USD'),
-        'journal_id': ref('bank_journal_USD'),
-        'partner_id': ref('base.res_partner_seagate'),
-        'period_id': ref('account.period_3'),
-        'type': 'payment',
-        'date': time.strftime("%Y-%m-%d"),
-        'payment_option': 'with_writeoff',
-        'writeoff_acc_id': ref('account.a_expense'),
-        'comment': 'Write Off',
-        'name': 'Second payment: Case 2 SUPPL USD/EUR',
-    }
-    vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-04-01'), ref('base.USD'), 45.0)['value'])
-    if not res['value']['line_dr_ids']:
-      res['value']['line_dr_ids'] = [{'type': 'dr', 'account_id': ref('account.a_pay'),}]
-    for item in res['value']['line_dr_ids']:
-        if item['amount_unreconciled'] == 20.00:
-            item['amount'] = 20.00
+    voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2_suppl'))
+    data = []
+    for item in voucher_id.line_cr_ids:
+        if item.amount_unreconciled == 20.00:
+            data += [(item.id, 20.0)]
         else:
-            item['amount'] = 30.00
-    vals['line_dr_ids'] = [(0,0,i) for i in res['value']['line_dr_ids']]
-    id = self.create(cr, uid, vals)
-    voucher_id = self.browse(cr, uid, id)
+            data += [(item.id, 30.0)]
+    for line_id, amount in data:
+        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 -
   I check that writeoff amount computed is -5.0
index 6728759..fa87fc1 100644 (file)
     move_line = move_line_obj.browse(cr, uid, move_lines[0])
     assert (move_line.debit - move_line.credit == 80), "Invoice move is incorrect for debtors account"
 -
-  I create the first voucher of payment
-  <create with values 200 EUR, journal EUR, and fills amount 130 EUR for the invoice of 200 USD and 70 EUR for the invoice of 100 USD>
+  I set the context that will be used for the encoding of all the vouchers of this file
+-
+  !context
+    'type': 'receipt'
+-
+  I create the first voucher of payment with values 200 EUR, journal EUR 
+-
+  !record {model: account.voucher, id: account_voucher_1_case2a, view: view_vendor_receipt_form}:
+    account_id: account.cash
+    amount: 200.0
+    company_id: base.main_company
+    journal_id: bank_journal_EUR
+    partner_id: base.res_partner_seagate
+    period_id: account.period_3
+    date: !eval time.strftime("%Y-03-01")
+    payment_option: 'with_writeoff'
+    writeoff_acc_id: account.a_expense
+    comment: 'Write Off'
+    name: 'First payment: Case 2 USD/EUR DR EUR'
+
+-
+  I fill amounts 130 for the invoice of 200$ and 70 for the invoice of 100$
 -
   !python {model: account.voucher}: |
     import netsvc, time
     vals = {}
-    res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_EUR'), 240.0, False, ttype='receipt', date=False)
-    vals = {
-        'account_id': ref('account.cash'),
-        'amount': 200.0,
-        'company_id': ref('base.main_company'),
-        'currency_id': False,
-        'journal_id': ref('bank_journal_EUR'),
-        'partner_id': ref('base.res_partner_seagate'),
-        'period_id': ref('account.period_3'),
-        'type': 'receipt',
-        'date': time.strftime("%Y-03-01"),
-        'payment_option': 'with_writeoff',
-        'writeoff_acc_id': ref('account.a_expense'),
-        'comment': 'Write Off',
-        'name': 'First payment: Case 2 USD/EUR DR EUR',
-    }
-    if not res['value']['line_cr_ids']:
-      res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
-    for item in res['value']['line_cr_ids']:
-        if item['amount_unreconciled'] == 150.00:
-            item['amount'] = 130.00
+    voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2a'))
+    data = []
+    for item in voucher_id.line_cr_ids:
+        if item.amount_unreconciled == 150.00:
+            data += [(item.id, 130.0)]
         else:
-            item['amount'] = 70.00
-    vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
-    id = self.create(cr, uid, vals)
-    voucher_id = self.browse(cr, uid, id)
+            data += [(item.id, 70.0)]
+    for line_id, amount in data:
+        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 -
   I confirm the voucher
     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)])
     move_line = move_line_obj.browse(cr, uid, move_lines[0])
     assert (move_line.amount_residual_currency == 22.22 and move_line.amount_residual == 10) , "Residual amount is not correct for second Invoice"
--  
-  I create the second voucher of payment
-  <create with values 80 USD, journal USD, and fully reconcile the 2 invoices>
+-
+  I create the second voucher of payment with values 80 USD, journal USD
+-
+  !record {model: account.voucher, id: account_voucher_2_case2a, view: view_vendor_receipt_form}:
+    account_id: account.cash
+    amount: 80
+    company_id: base.main_company
+    journal_id: bank_journal_USD
+    partner_id: base.res_partner_seagate
+    period_id: account.period_3
+    date: !eval time.strftime("%Y-04-01")
+    payment_option: 'with_writeoff'
+    writeoff_acc_id: account.a_expense
+    exchange_acc_id: account.o_expense
+    comment: 'Write Off'
+    name: 'Second payment: Case 2 SUPPL USD/EUR DR EUR'
+
+-
+  and I fully reconcile the 2 previous invoices
 -
   !python {model: account.voucher}: |
     import netsvc, time
     vals = {}
-    res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_USD'), 80.0, 2, ttype='receipt', date=False)
-    vals = {
-        'account_id': ref('account.cash'),
-        'amount': 80.0,
-        'company_id': ref('base.main_company'),
-        'currency_id': ref('base.USD'),
-        'journal_id': ref('bank_journal_USD'),
-        'partner_id': ref('base.res_partner_seagate'),
-        'period_id': ref('account.period_3'),
-        'type': 'receipt',
-        'date': time.strftime("%Y-%m-%d"),
-        'payment_option': 'with_writeoff',
-        'writeoff_acc_id': ref('account.a_expense'),
-        'exchange_acc_id': ref('account.o_expense'),
-        'comment': 'Write Off',
-        'name': 'Second payment: Case 2 SUPPL USD/EUR DR EUR',
-    }
-    vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-04-01'), ref('base.USD'), 80.0)['value'])
-    if not res['value']['line_cr_ids']:
-      res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
-    for item in res['value']['line_cr_ids']:
-        if item['amount_unreconciled'] == 55.56:
-            item['amount'] = 55.56
+    voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2a'))
+    data = []
+    for item in voucher_id.line_cr_ids:
+        if item.amount_unreconciled == 55.56:
+            data += [(item.id, 55.56)]
         else:
-            item['amount'] = 22.22
-    vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
-    id = self.create(cr, uid, vals)
-    voucher_id = self.browse(cr, uid, id)
+            data += [(item.id, 22.22)]
+    for line_id, amount in data:
+        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 -
   I check that writeoff amount computed is 2.22
index ec4d653..43c00a9 100644 (file)
     move_line = move_line_obj.browse(cr, uid, move_lines[0])
     assert (move_line.debit - move_line.credit == 80), "Invoice move is incorrect for debtors account"
 -
-  I create the first voucher of payment
-  <create with values 200 EUR (€), journal EUR, and fills amount 130€ for the invoice of 200$ and 70€ for the invoice of 100$>
+  I set the context that will be used for the encoding of all the vouchers of this file
+-
+  !context
+    'type': 'receipt'
+-
+  I create the first voucher of payment with values 200 EUR, journal EUR
+-
+  !record {model: account.voucher, id: account_voucher_1_case2b, view: view_vendor_receipt_form}:
+    account_id: account.cash
+    amount: 200.0
+    company_id: base.main_company
+    journal_id: bank_journal_EUR
+    partner_id: base.res_partner_seagate
+    period_id: account.period_3
+    date: !eval time.strftime("%Y-03-01")
+    payment_option: 'with_writeoff'
+    writeoff_acc_id: account.a_expense
+    comment: 'Write Off'
+    name: 'First payment: Case 2 USD/EUR DR USD'
+
+-
+  I fill amounts 130 for the invoice of 200$ and 70 for the invoice of 100$>
 -
   !python {model: account.voucher}: |
     import netsvc, time
     vals = {}
-    res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_EUR'), 200.0, False, ttype='receipt', date=False)
-    vals = {
-        'account_id': ref('account.cash'),
-        'amount': 200.0,
-        'company_id': ref('base.main_company'),
-        'currency_id': ref('base.EUR'),
-        'journal_id': ref('bank_journal_EUR'),
-        'partner_id': ref('base.res_partner_seagate'),
-        'period_id': ref('account.period_3'),
-        'type': 'receipt',
-        'date': time.strftime("%Y-03-01"),
-        'payment_option': 'with_writeoff',
-        'writeoff_acc_id': ref('account.a_expense'),
-        'comment': 'Write Off',
-        'name': 'First payment: Case 2 USD/EUR DR USD',
-    }
-    if not res['value']['line_cr_ids']:
-      res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
-    for item in res['value']['line_cr_ids']:
-        if item['amount_unreconciled'] == 150.00:
-            item['amount'] = 130.00
+    voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2b'))
+    data = []
+    for item in voucher_id.line_cr_ids:
+        if item.amount_unreconciled == 150.00:
+            data += [(item.id, 130.0)]
         else:
-            item['amount'] = 70.00
-    vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
-    id = self.create(cr, uid, vals)
-    voucher_id = self.browse(cr, uid, id)
+            data += [(item.id, 70.0)]
+    for line_id, amount in data:
+        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 -
   I confirm the voucher
     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)])
     move_line = move_line_obj.browse(cr, uid, move_lines[0])
     assert (move_line.amount_residual_currency == 22.22 and move_line.amount_residual == 10) , "Residual amount is not correct for second Invoice"
--  
-  I create the second voucher of payment
-  <create with values 80 USD, journal USD, and fully reconcile the 2 invoices>
+-
+  I create the second voucher of payment with values 80 USD, journal USD
+-
+  !record {model: account.voucher, id: account_voucher_2_case2b, view: view_vendor_receipt_form}:
+    account_id: account.cash
+    amount: 80.0
+    company_id: base.main_company
+    journal_id: bank_journal_USD
+    partner_id: base.res_partner_seagate
+    period_id: account.period_3
+    date: !eval time.strftime("%Y-04-01")
+    payment_option: 'with_writeoff'
+    writeoff_acc_id: account.a_expense
+    exchange_acc_id: account.o_expense
+    comment: 'Write Off'
+    name: 'Second payment: Case 2 SUPPL USD/EUR DR USD'
+
+-
+  and I fully reconcil the 2 previous invoices
 -
   !python {model: account.voucher}: |
     import netsvc, time
     vals = {}
-    res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_USD'), 80.0, ref('base.USD'), ttype='receipt', date=False)
-    vals = {
-        'account_id': ref('account.cash'),
-        'amount': 80.0,
-        'company_id': ref('base.main_company'),
-        'currency_id': ref('base.USD'),
-        'journal_id': ref('bank_journal_USD'),
-        'partner_id': ref('base.res_partner_seagate'),
-        'period_id': ref('account.period_3'),
-        'type': 'receipt',
-        'date': time.strftime("%Y-%m-%d"),
-        'payment_option': 'with_writeoff',
-        'writeoff_acc_id': ref('account.a_expense'),
-        'exchange_acc_id': ref('account.o_expense'),
-        'comment': 'Write Off',
-        'name': 'Second payment: Case 2 SUPPL USD/EUR DR USD',
-    }
-    vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-04-01'), ref('base.USD'), 80.0)['value'])
-    if not res['value']['line_cr_ids']:
-      res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
-    for item in res['value']['line_cr_ids']:
-        if item['amount_unreconciled'] == 55.56:
-            item['amount'] = 55.56
+    voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2b'))
+    data = []
+    for item in voucher_id.line_cr_ids:
+        if item.amount_unreconciled == 55.56:
+            data += [(item.id, 55.56)]
         else:
-            item['amount'] = 22.22
-    vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
-    id = self.create(cr, uid, vals)
-    voucher_id = self.browse(cr, uid, id)
+            data += [(item.id, 22.22)]
+    for line_id, amount in data:
+        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 -
   I check that writeoff amount computed is 2.22
index 09034fa..a2fc39e 100644 (file)
     move_line = move_line_obj.browse(cr, uid, move_lines[0])
     assert (move_line.debit - move_line.credit == 80.00), "Invoice move is incorrect for debtors account"
 -
-  I create the first voucher of payment
-  <create with values 120 EUR, journal EUR, and fill amounts 100 for the invoice of 150 EUR and 20 for the invoice of 80 EUR>
+  I set the context that will be used for the encoding of all the vouchers of this file
+-
+  !context
+    'type': 'receipt'
+-
+  I create the first voucher of payment with values 120 EUR, journal EUR
+-
+  !record {model: account.voucher, id: account_voucher_1_case3, view: view_vendor_receipt_form}:
+    account_id: account.cash
+    amount: 120.0
+    company_id: base.main_company
+    journal_id: bank_journal_EUR
+    partner_id: base.res_partner_seagate
+    period_id: account.period_3
+    date: !eval time.strftime("%Y-03-01")
+    payment_option: 'with_writeoff'
+    writeoff_acc_id: account.a_expense
+    comment: 'Write Off'
+    name: 'First payment: Case 3'
+
+-
+  I fill amounts 100 for the invoice of 150€ and 20 for the invoice of 80€
 -
   !python {model: account.voucher}: |
     import netsvc, time
     vals = {}
-    res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_EUR'), 120.00, False, ttype='receipt', date=False)
-    vals = {
-        'account_id': ref('account.cash'),
-        'amount': 120.00,
-        'company_id': ref('base.main_company'),
-        'currency_id': ref('base.EUR'),
-        'journal_id': ref('bank_journal_EUR'),
-        'partner_id': ref('base.res_partner_seagate'),
-        'period_id': ref('account.period_3'),
-        'type': 'receipt',
-        'date': time.strftime("%Y-03-01"),
-        'payment_option': 'with_writeoff',
-        'writeoff_acc_id': ref('account.a_expense'),
-        'comment': 'Write Off',
-        'name': 'First payment: Case 3',
-    }
-    if not res['value']['line_cr_ids']:
-      res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
-    for item in res['value']['line_cr_ids']:
-        if item['amount_unreconciled'] == 150.00:
-            item['amount'] = 100.00
+    voucher_id = self.browse(cr, uid, ref('account_voucher_1_case3'))
+    data = []
+    for item in voucher_id.line_cr_ids:
+        if item.amount_unreconciled == 150.00:
+            data += [(item.id, 100.0)]
         else:
-            item['amount'] = 20.00
-    vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
-    id = self.create(cr, uid, vals)
-    voucher_id = self.browse(cr, uid, id)
+            data += [(item.id, 20.0)]
+    for line_id, amount in data:
+        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 -
   I check that writeoff amount computed is 0.00
     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)])
     move_line = move_line_obj.browse(cr, uid, move_lines[0])
     assert (move_line.amount_residual_currency == 50.0 and move_line.amount_residual == 50.0) , "Residual amount is not correct for first Invoice"
--    
+-
   I check the residual amuont of Invoice2 is 60
 -
    !python {model: account.invoice}: |
     move_line = move_line_obj.browse(cr, uid, move_lines[0])
     assert (move_line.amount_residual_currency == 60.0 and move_line.amount_residual == 60.0) , "Residual amount is not correct for second Invoice"
 -
-  I create the second voucher of payment and check to let open the debtor overpaid amount.
-  <create with values 120 EUR, journal EUR, and fill amounts 50 for the invoice of 150 EUR and 70 for the invoice of 80 EUR>
+  I create the second voucher of payment with values 120€, journal EUR, and check to let open the debtor overpaid amount
+-
+  !record {model: account.voucher, id: account_voucher_2_case3, view: view_vendor_receipt_form}:
+    account_id: account.cash
+    amount: 120.0
+    company_id: base.main_company
+    journal_id: bank_journal_EUR
+    partner_id: base.res_partner_seagate
+    period_id: account.period_3
+    date: !eval time.strftime("%Y-04-01")
+    payment_option: 'with_writeoff'
+    writeoff_acc_id: account.a_expense
+    comment: 'Write Off'
+    name: 'Second payment: Case 3'
+
+-
+  I fill amounts 50 for the invoice of 150€ and 70 for the invoice of 80€
 -
   !python {model: account.voucher}: |
     import netsvc, time
     vals = {}
-    res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_EUR'), 120.00, False, ttype='receipt', date=False)
-    vals = {
-        'account_id': ref('account.cash'),
-        'amount': 120.00,
-        'company_id': ref('base.main_company'),
-        'currency_id': ref('base.EUR'),
-        'journal_id': ref('bank_journal_EUR'),
-        'partner_id': ref('base.res_partner_seagate'),
-        'period_id': ref('account.period_3'),
-        'type': 'receipt',
-        'date': time.strftime("%Y-04-01"),
-        'payment_option': 'with_writeoff',
-        'writeoff_acc_id': ref('account.a_expense'),
-        'comment': 'Write Off',
-        'name': 'Second payment: Case 3',
-    }
-    if not res['value']['line_cr_ids']:
-      res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
-    for item in res['value']['line_cr_ids']:
-        if item['amount_unreconciled'] == 50.00:
-            item['amount'] = 50.00
-        elif item['amount_unreconciled'] == 60.00:
-            item['amount'] = 70.00
-    vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
-    id = self.create(cr, uid, vals)
-    voucher_id = self.browse(cr, uid, id)
+    voucher_id = self.browse(cr, uid, ref('account_voucher_2_case3'))
+    data = []
+    for item in voucher_id.line_cr_ids:
+        if item.amount_unreconciled == 50.00:
+            data += [(item.id, 50.0)]
+        elif item.amount_unreconciled == 60.00:
+            data += [(item.id, 70.00)]
+    for line_id, amount in data:
+        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 -
   I check that writeoff amount computed is 0.00
index b3abbb2..2fe43b5 100644 (file)
     move_line = move_line_obj.browse(cr, uid, move_lines[0])
     assert (move_line.debit - move_line.credit == 149.39), "Invoice move is incorrect for debtors account"
 -
-  I create the first voucher of payment
-  <create with values 200 CHF, journal CHF, and completly pat the invoice of 200 CAD>
+  I set the context that will be used for the encoding of all the vouchers of this file
+-
+  !context
+    'type': 'receipt'
+-
+  I create the first voucher of payment with values 200 CHF, journal CHF
+-
+  !record {model: account.voucher, id: account_voucher_1_case4, view: view_vendor_receipt_form}:
+    account_id: account.cash
+    amount: 200
+    company_id: base.main_company
+    journal_id: bank_journal_CHF
+    partner_id: base.res_partner_seagate
+    period_id: account.period_3
+    date: !eval time.strftime("%Y-03-01")
+    payment_option: 'with_writeoff'
+    writeoff_acc_id: account.a_expense
+    exchange_acc_id: account.o_expense
+    comment: 'Write Off'
+    name: 'First payment: Case 4'
+-
+  I completly pay the invoice of 200 CAD
 -
   !python {model: account.voucher}: |
     import netsvc, time
     vals = {}
-    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)
-    vals = {
-        'account_id': ref('account.cash'),
-        'amount': 200.00,
-        'company_id': ref('base.main_company'),
-        'currency_id': ref('base.CHF'),
-        'journal_id': ref('bank_journal_CHF'),
-        'partner_id': ref('base.res_partner_seagate'),
-        'period_id': ref('account.period_3'),
-        'type': 'receipt',
-        'date': time.strftime("%Y-%m-%d"),
-        'payment_option': 'with_writeoff',
-        'writeoff_acc_id': ref('account.a_expense'),
-        'exchange_acc_id': ref('account.o_expense'),
-        'comment': 'Write Off',
-        'name': 'First payment: Case 4',
-    }
-    vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-03-01'), ref('base.CHF'), 200.0)['value'])
-    if not res['value']['line_cr_ids']:
-      res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
-    for item in res['value']['line_cr_ids']:
-        if item['amount_unreconciled'] == 186.74:
-            item['amount'] = 186.74
-    vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
-    id = self.create(cr, uid, vals)
-    voucher_id = self.browse(cr, uid, id)
+    voucher_id = self.browse(cr, uid, ref('account_voucher_1_case4'))
+    data = []
+    for item in voucher_id.line_cr_ids:
+        if item.amount_unreconciled == 186.74:
+            data += [(item.id, 186.74)]
+    for line_id, amount in data:
+        self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
 -
   I check that writeoff amount computed is 13.26