Skip to content

Commit

Permalink
[IMP] account_banking_mandate: Fill mandate in invoices if none is pr…
Browse files Browse the repository at this point in the history
…ovided

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.
  • Loading branch information
pedrobaeza authored and alexis-via committed Jan 4, 2022
1 parent d1148c1 commit c63c546
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion account_banking_mandate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down
18 changes: 18 additions & 0 deletions account_banking_mandate/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ def line_get_convert(self, line, part):
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
Expand Down

0 comments on commit c63c546

Please sign in to comment.