[IMP] account_voucher, usability: reset the amount to 0 in the 'pay invoice wizard...
authorQuentin (OpenERP) <qdp-launchpad@openerp.com>
Mon, 13 May 2013 14:21:16 +0000 (16:21 +0200)
committerQuentin (OpenERP) <qdp-launchpad@openerp.com>
Mon, 13 May 2013 14:21:16 +0000 (16:21 +0200)
bzr revid: qdp-launchpad@openerp.com-20130513142116-wyuud8n9fcnafc7l

addons/account_voucher/account_voucher.py
addons/account_voucher/invoice.py

index f8b380a..322d9da 100644 (file)
@@ -880,6 +880,12 @@ class account_voucher(osv.osv):
         else:
             currency_id = journal.company_id.currency_id.id
         vals['value'].update({'currency_id': currency_id})
+        #in case we want to register the payment directly from an invoice, it's confusing to allow to switch the journal 
+        #without seeing that the amount is expressed in the journal currency, and not in the invoice currency. So to avoid
+        #this common mistake, we simply reset the amount to 0 if the currency is not the invoice currency.
+        if context.get('payment_expected_currency') and currency_id != context.get('payment_expected_currency'):
+            vals['value']['amount'] = 0
+            amount = 0
         res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context)
         for key in res.keys():
             vals[key].update(res[key])
index c0584dd..a38a3d3 100644 (file)
@@ -41,6 +41,7 @@ class invoice(osv.osv):
             'target': 'new',
             'domain': '[]',
             'context': {
+                'payment_expected_currency': inv.currency_id.id,
                 'default_partner_id': self.pool.get('res.partner')._find_accounting_partner(inv.partner_id).id,
                 'default_amount': inv.type in ('out_refund', 'in_refund') and -inv.residual or inv.residual,
                 'default_reference': inv.name,