From 1c8e7d24d548b613e57de276cdd994f57a87d1b0 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sun, 2 Apr 2017 22:14:14 +0200 Subject: [PATCH 1/2] [IMP] account_payment_partner: Fill payment mode in invoices if none is provided Using same method as in upstream, payment mode is filled on invoice creation if no payment method is provided. This way, we don't need to install account_payment_sale if we don't want to handle several payment modes at sales level. Even more, if we install the module later and we have already existing sales orders without payment mode filled, those orders will be invoiced with the customer payment mode. --- account_payment_partner/__openerp__.py | 2 +- .../models/account_invoice.py | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/account_payment_partner/__openerp__.py b/account_payment_partner/__openerp__.py index 8eac220f8..d30778b08 100644 --- a/account_payment_partner/__openerp__.py +++ b/account_payment_partner/__openerp__.py @@ -5,7 +5,7 @@ { 'name': 'Account Payment Partner', - 'version': '9.0.1.0.0', + 'version': '9.0.1.1.0', 'category': 'Banking addons', 'license': 'AGPL-3', 'summary': 'Adds payment mode on partners and invoices', diff --git a/account_payment_partner/models/account_invoice.py b/account_payment_partner/models/account_invoice.py index 14ac17a77..d2b382246 100644 --- a/account_payment_partner/models/account_invoice.py +++ b/account_payment_partner/models/account_invoice.py @@ -19,7 +19,7 @@ class AccountInvoice(models.Model): @api.onchange('partner_id', 'company_id') def _onchange_partner_id(self): - super(AccountInvoice, self)._onchange_partner_id() + res = super(AccountInvoice, self)._onchange_partner_id() if self.partner_id: if self.type == 'in_invoice': pay_mode = self.partner_id.supplier_payment_mode_id @@ -41,6 +41,25 @@ class AccountInvoice(models.Model): self.payment_mode_id = False if self.type == 'in_invoice': self.partner_bank_id = False + return res + + @api.model + def create(self, vals): + """Fill the payment_mode_id from the partner if none is provided on + creation, using same method as upstream.""" + onchanges = { + '_onchange_partner_id': ['payment_mode_id'], + } + for onchange_method, changed_fields in onchanges.items(): + if any(f not in vals for f in changed_fields): + invoice = self.new(vals) + getattr(invoice, onchange_method)() + for field in changed_fields: + if field not in vals and invoice[field]: + vals[field] = invoice._fields[field].convert_to_write( + invoice[field], + ) + return super(AccountInvoice, self).create(vals) @api.onchange('payment_mode_id') def payment_mode_id_change(self): From 56d2c5c0746e9c1b3b26aa92274af276eb157391 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sun, 2 Apr 2017 22:14:57 +0200 Subject: [PATCH 2/2] [IMP] account_banking_mandate: Fill mandate in invoices if none is provided Using same method as in upstream, mandate is filled on invoice creation if no one is provided. This way, we don't need to install account_banking_mandate_sale if we don't want to handle several mandates at sales level. --- account_banking_mandate/__openerp__.py | 2 +- .../models/account_invoice.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/account_banking_mandate/__openerp__.py b/account_banking_mandate/__openerp__.py index 239d96966..dbfb8b35c 100644 --- a/account_banking_mandate/__openerp__.py +++ b/account_banking_mandate/__openerp__.py @@ -7,7 +7,7 @@ { 'name': 'Account Banking Mandate', 'summary': 'Banking mandates', - 'version': '9.0.1.0.0', + 'version': '9.0.1.1.0', 'license': 'AGPL-3', 'author': "Compassion CH, " "Tecnativa, " diff --git a/account_banking_mandate/models/account_invoice.py b/account_banking_mandate/models/account_invoice.py index d821ee3e2..4b7f38aa2 100644 --- a/account_banking_mandate/models/account_invoice.py +++ b/account_banking_mandate/models/account_invoice.py @@ -29,6 +29,24 @@ class AccountInvoice(models.Model): res['mandate_id'] = invoice.mandate_id.id or False return res + @api.model + def create(self, vals): + """Fill the mandate_id from the partner if none is provided on + creation, using same method as upstream.""" + onchanges = { + '_onchange_partner_id': ['mandate_id'], + } + for onchange_method, changed_fields in onchanges.items(): + if any(f not in vals for f in changed_fields): + invoice = self.new(vals) + getattr(invoice, onchange_method)() + for field in changed_fields: + if field not in vals and invoice[field]: + vals[field] = invoice._fields[field].convert_to_write( + invoice[field], + ) + return super(AccountInvoice, self).create(vals) + # If a customer pays via direct debit, it's refunds should # be deducted form the next debit by default. The module # account_payment_partner copies payment_mode_id from invoice