summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqdp-odoo <qdp@odoo.com>2015-08-19 11:50:43 +0200
committerqdp-odoo <qdp@odoo.com>2015-08-19 13:02:21 +0200
commitf9b13ca690e3d3392bb2f76b5936387b3e26cfde (patch)
treee5d5cd5d739575872c6428bfbb62489cb555ef39
parent95380777dc568749b5a24895cb698e99354b26fc (diff)
[FIX] account: multiple bugfixes on registering a payment on a single refund. The partner wasn't saved, the partner_type was wrong, the default_get was crashing because of rec['invoice_ids'][0][2] is not safe
-rw-r--r--addons/account/models/account_payment.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py
index 1abc98f9fff..ee03ea35fa1 100644
--- a/addons/account/models/account_payment.py
+++ b/addons/account/models/account_payment.py
@@ -218,17 +218,16 @@ class account_payment(models.Model):
def _onchange_partner_type(self):
# Set partner_id domain
if self.partner_type:
- if getattr(self.partner_id, self.partner_type) is False:
- self.partner_id = False
return {'domain': {'partner_id': [(self.partner_type, '=', True)]}}
@api.onchange('payment_type')
def _onchange_payment_type(self):
- # Set default partner type for the payment type
- if self.payment_type == 'inbound':
- self.partner_type = 'customer'
- elif self.payment_type == 'outbound':
- self.partner_type = 'supplier'
+ if not self.invoice_ids:
+ # Set default partner type for the payment type
+ if self.payment_type == 'inbound':
+ self.partner_type = 'customer'
+ elif self.payment_type == 'outbound':
+ self.partner_type = 'supplier'
# Set payment method domain
res = self._onchange_journal()
if not res.get('domain', {}):
@@ -240,15 +239,15 @@ class account_payment(models.Model):
@api.model
def default_get(self, fields):
rec = super(account_payment, self).default_get(fields)
- invoice_ids = rec.get('invoice_ids') and rec['invoice_ids'][0][2] or None
- if invoice_ids and len(invoice_ids) == 1:
- invoice = self.env['account.invoice'].browse(invoice_ids)
- rec['communication'] = invoice.reference
- rec['currency_id'] = invoice.currency_id.id
- rec['payment_type'] = invoice.type in ('out_invoice', 'in_refund') and 'inbound' or 'outbound'
- rec['partner_type'] = MAP_INVOICE_TYPE_PARTNER_TYPE[invoice.type]
- rec['partner_id'] = invoice.partner_id.id
- rec['amount'] = invoice.residual_signed
+ invoice_defaults = self.resolve_2many_commands('invoice_ids', rec.get('invoice_ids'))
+ if invoice_defaults and len(invoice_defaults) == 1:
+ invoice = invoice_defaults[0]
+ rec['communication'] = invoice['reference']
+ rec['currency_id'] = invoice['currency_id'][0]
+ rec['payment_type'] = invoice['type'] in ('out_invoice', 'in_refund') and 'inbound' or 'outbound'
+ rec['partner_type'] = MAP_INVOICE_TYPE_PARTNER_TYPE[invoice['type']]
+ rec['partner_id'] = invoice['partner_id'][0]
+ rec['amount'] = invoice['residual']
return rec
def _get_invoices(self):