diff --git a/account_banking_mandate/__manifest__.py b/account_banking_mandate/__manifest__.py index a7d0a871f..553c4f7df 100644 --- a/account_banking_mandate/__manifest__.py +++ b/account_banking_mandate/__manifest__.py @@ -7,7 +7,7 @@ { 'name': 'Account Banking Mandate', 'summary': 'Banking mandates', - 'version': '10.0.1.0.0', + 'version': '10.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 d9561ff8e..7c086d9f9 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], invoice, + ) + 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