Skip to content

Commit

Permalink
8.0 Add support for partner bank matching on invoice update (OCA#6)
Browse files Browse the repository at this point in the history
Add support for partner bank matching on invoice update (before, it was only supported on invoice creation)
  • Loading branch information
Alexis de Lattre authored and V3st1g3 committed Dec 11, 2024
1 parent f69cfcf commit 23f492b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
4 changes: 2 additions & 2 deletions account_invoice_import/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ To use this module, go to the menu *Accounting > Suppliers > Import Invoices* an

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/95/8.0
:target: https://runbot.odoo-community.org/runbot/226/8.0

Known issues / Roadmap
======================
Expand All @@ -60,7 +60,7 @@ Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/account-invoicing/issues>`_. In case of trouble, please
<https://github.com/OCA/edi/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Expand Down
38 changes: 15 additions & 23 deletions account_invoice_import/wizard/account_invoice_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def _prepare_create_invoice_vals(self, parsed_inv):
aio = self.env['account.invoice']
ailo = self.env['account.invoice.line']
bdio = self.env['business.document.import']
rpo = self.env['res.partner']
company = self.env.user.company_id
assert parsed_inv.get('amount_total'), 'Missing amount_total'
partner = bdio._match_partner(
Expand Down Expand Up @@ -146,28 +147,12 @@ def _prepare_create_invoice_vals(self, parsed_inv):
vals['date_due'] = parsed_inv.get('date_due')
# Bank info
if parsed_inv.get('iban'):
iban = parsed_inv.get('iban').replace(' ', '')
self._cr.execute(
"""SELECT id FROM res_partner_bank
WHERE replace(acc_number, ' ', '')=%s
AND state='iban'
AND partner_id=%s
""", (iban, vals['partner_id']))
rpb_res = self._cr.fetchall()
if rpb_res:
vals['partner_bank_id'] = rpb_res[0][0]
else:
partner_bank = self.env['res.partner.bank'].create({
'partner_id': vals['partner_id'],
'state': 'iban',
'acc_number': parsed_inv['iban'],
'bank_bic': parsed_inv.get('bic'),
})
partner = rpo.browse(vals['partner_id'])
partner_bank = bdio._match_partner_bank(
partner, parsed_inv['iban'], parsed_inv.get('bic'),
parsed_inv['chatter_msg'], create_if_not_found=True)
if partner_bank:
vals['partner_bank_id'] = partner_bank.id
parsed_inv['chatter_msg'].append(_(
"The bank account <b>IBAN %s</b> has been automatically "
"added on the supplier <b>%s</b>") % (
parsed_inv['iban'], partner.name))
config = partner.invoice_import_id
if config.invoice_line_method.startswith('1line'):
if config.invoice_line_method == '1line_no_product':
Expand Down Expand Up @@ -550,7 +535,8 @@ def _prepare_create_invoice_line(self, product, uom, import_line, invoice):
return vals

@api.model
def _prepare_update_invoice_vals(self, parsed_inv):
def _prepare_update_invoice_vals(self, parsed_inv, partner):
bdio = self.env['business.document.import']
vals = {
'supplier_invoice_number':
parsed_inv.get('invoice_number'),
Expand All @@ -559,6 +545,12 @@ def _prepare_update_invoice_vals(self, parsed_inv):
}
if parsed_inv.get('date_due'):
vals['date_due'] = parsed_inv['date_due']
if parsed_inv.get('iban'):
partner_bank = bdio._match_partner_bank(
partner, parsed_inv['iban'], parsed_inv.get('bic'),
parsed_inv['chatter_msg'], create_if_not_found=True)
if partner_bank:
vals['partner_bank_id'] = partner_bank.id
return vals

@api.multi
Expand Down Expand Up @@ -597,7 +589,7 @@ def update_invoice(self):
currency.name, invoice.currency_id.name))
# When invoice with embedded XML files will be more widely used,
# we should also update invoice lines
vals = self._prepare_update_invoice_vals(parsed_inv)
vals = self._prepare_update_invoice_vals(parsed_inv, partner)
logger.debug('Updating supplier invoice with vals=%s', vals)
self.invoice_id.write(vals)
if (
Expand Down

0 comments on commit 23f492b

Please sign in to comment.