From 4ef7cb6ab3a50c37890128fee5a74520b500f17b Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 18 Oct 2016 23:02:55 +0200 Subject: [PATCH] 8.0 Add support for partner bank matching on invoice update (#6) Add support for partner bank matching on invoice update (before, it was only supported on invoice creation) --- account_invoice_import/README.rst | 4 +- .../wizard/account_invoice_import.py | 38 ++++++++----------- .../README.rst | 4 +- account_invoice_import_ubl/README.rst | 4 +- account_invoice_import_zugferd/README.rst | 4 +- account_invoice_ubl/README.rst | 4 +- account_invoice_zugferd/README.rst | 4 +- base_business_document_import/README.rst | 4 +- .../models/business_document_import.py | 30 +++++++++++++++ .../README.rst | 4 +- .../README.rst | 4 +- base_ubl/README.rst | 4 +- base_ubl_payment/README.rst | 4 +- base_zugferd/README.rst | 4 +- purchase_order_import/README.rst | 4 +- purchase_order_import_ubl/README.rst | 4 +- purchase_order_ubl/README.rst | 4 +- sale_order_import/README.rst | 4 +- sale_order_import_csv/README.rst | 4 +- sale_order_import_ubl/README.rst | 4 +- sale_order_ubl/README.rst | 4 +- sale_stock_order_import/README.rst | 4 +- 22 files changed, 85 insertions(+), 63 deletions(-) diff --git a/account_invoice_import/README.rst b/account_invoice_import/README.rst index 1cfbea356c..5f7f8d6c13 100644 --- a/account_invoice_import/README.rst +++ b/account_invoice_import/README.rst @@ -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 ====================== @@ -60,7 +60,7 @@ Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/account_invoice_import/wizard/account_invoice_import.py b/account_invoice_import/wizard/account_invoice_import.py index 1c85584456..2e38af48a1 100644 --- a/account_invoice_import/wizard/account_invoice_import.py +++ b/account_invoice_import/wizard/account_invoice_import.py @@ -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( @@ -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 IBAN %s has been automatically " - "added on the supplier %s") % ( - 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': @@ -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'), @@ -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 @@ -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 ( diff --git a/account_invoice_import_invoice2data/README.rst b/account_invoice_import_invoice2data/README.rst index a977f4a59a..cdad6462fd 100644 --- a/account_invoice_import_invoice2data/README.rst +++ b/account_invoice_import_invoice2data/README.rst @@ -90,13 +90,13 @@ Refer to the usage section of the module *account_invoice_import*. .. 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 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/account_invoice_import_ubl/README.rst b/account_invoice_import_ubl/README.rst index 9163ff2e79..5004dd05db 100644 --- a/account_invoice_import_ubl/README.rst +++ b/account_invoice_import_ubl/README.rst @@ -22,13 +22,13 @@ Refer to the usage section of the module *account_invoice_import*. .. 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 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/account_invoice_import_zugferd/README.rst b/account_invoice_import_zugferd/README.rst index 7405d45d18..723288478e 100644 --- a/account_invoice_import_zugferd/README.rst +++ b/account_invoice_import_zugferd/README.rst @@ -29,13 +29,13 @@ Refer to the usage section of the module *account_invoice_import*. .. 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 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/account_invoice_ubl/README.rst b/account_invoice_ubl/README.rst index d8c0305ac4..a482a9ae7a 100644 --- a/account_invoice_ubl/README.rst +++ b/account_invoice_ubl/README.rst @@ -25,13 +25,13 @@ Usage .. 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 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/account_invoice_zugferd/README.rst b/account_invoice_zugferd/README.rst index b7a42ed6bc..69e366d617 100644 --- a/account_invoice_zugferd/README.rst +++ b/account_invoice_zugferd/README.rst @@ -35,7 +35,7 @@ On the form view of a customer invoice/refund, just click on the *Print* button .. 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 ====================== @@ -48,7 +48,7 @@ Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/base_business_document_import/README.rst b/base_business_document_import/README.rst index 170cc01ea7..1f32b35033 100644 --- a/base_business_document_import/README.rst +++ b/base_business_document_import/README.rst @@ -22,13 +22,13 @@ Usage .. 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 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/base_business_document_import/models/business_document_import.py b/base_business_document_import/models/business_document_import.py index e69e0e0890..703d66fb9c 100644 --- a/base_business_document_import/models/business_document_import.py +++ b/base_business_document_import/models/business_document_import.py @@ -237,6 +237,36 @@ def _match_shipping_partner(self, shipping_dict, partner, chatter_msg): partner = partners[0] return partner + @api.model + def _match_partner_bank( + self, partner, iban, bic, chatter_msg, create_if_not_found=False): + assert iban, 'iban is a required arg' + assert partner, 'partner is a required arg' + partner = partner.commercial_partner_id + iban = iban.replace(' ', '') + rpbo = self.env['res.partner.bank'] + self._cr.execute( + """SELECT id FROM res_partner_bank + WHERE replace(acc_number, ' ', '')=%s + AND state='iban' + AND partner_id=%s + """, (iban, partner.id)) + rpb_res = self._cr.fetchall() + if rpb_res: + return rpbo.browse(rpb_res[0][0]) + elif create_if_not_found and bic: + partner_bank = rpbo.create({ + 'partner_id': partner.id, + 'state': 'iban', + 'acc_number': iban, + 'bank_bic': bic, + }) + chatter_msg.append(_( + "The bank account IBAN %s has been automatically " + "added on the supplier %s") % ( + iban, partner.name)) + return partner_bank + @api.model def _match_product(self, product_dict, chatter_msg, seller=False): """Example: diff --git a/base_business_document_import_phone/README.rst b/base_business_document_import_phone/README.rst index 61556fb0fe..b2a5ce165f 100644 --- a/base_business_document_import_phone/README.rst +++ b/base_business_document_import_phone/README.rst @@ -23,13 +23,13 @@ Usage .. 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 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/base_business_document_import_stock/README.rst b/base_business_document_import_stock/README.rst index 172a6ec08d..100a1b9b52 100644 --- a/base_business_document_import_stock/README.rst +++ b/base_business_document_import_stock/README.rst @@ -18,13 +18,13 @@ Usage .. 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 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/base_ubl/README.rst b/base_ubl/README.rst index 28b88906d9..ffa432ed4e 100644 --- a/base_ubl/README.rst +++ b/base_ubl/README.rst @@ -24,13 +24,13 @@ Usage .. 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 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/base_ubl_payment/README.rst b/base_ubl_payment/README.rst index 0b88d9ae84..0e70103fb5 100644 --- a/base_ubl_payment/README.rst +++ b/base_ubl_payment/README.rst @@ -18,13 +18,13 @@ Usage .. 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 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/base_zugferd/README.rst b/base_zugferd/README.rst index 95a216e02f..a42be2983c 100644 --- a/base_zugferd/README.rst +++ b/base_zugferd/README.rst @@ -29,13 +29,13 @@ This module doesn't do anything by itself, but it is used by 2 other modules: .. 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 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/purchase_order_import/README.rst b/purchase_order_import/README.rst index e764d13541..5d34043ae0 100644 --- a/purchase_order_import/README.rst +++ b/purchase_order_import/README.rst @@ -38,13 +38,13 @@ Once the quotation file is imported, you should read the messages in the chatter .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/142/8.0 + :target: https://runbot.odoo-community.org/runbot/226/8.0 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/purchase_order_import_ubl/README.rst b/purchase_order_import_ubl/README.rst index 493fd4d764..ee9df0038a 100644 --- a/purchase_order_import_ubl/README.rst +++ b/purchase_order_import_ubl/README.rst @@ -25,13 +25,13 @@ Refer to the README.rst of the module *purchase_order_import* for a detailed usa .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/142/8.0 + :target: https://runbot.odoo-community.org/runbot/226/8.0 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/purchase_order_ubl/README.rst b/purchase_order_ubl/README.rst index 4cf386007f..96a1fa921b 100644 --- a/purchase_order_ubl/README.rst +++ b/purchase_order_ubl/README.rst @@ -26,13 +26,13 @@ Usage .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/142/8.0 + :target: https://runbot.odoo-community.org/runbot/226/8.0 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/sale_order_import/README.rst b/sale_order_import/README.rst index a48930bf39..715d88de4e 100644 --- a/sale_order_import/README.rst +++ b/sale_order_import/README.rst @@ -31,13 +31,13 @@ Once the RFQ/order is imported, you should read the messages in the chatter of t .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/167/8.0 + :target: https://runbot.odoo-community.org/runbot/226/8.0 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/sale_order_import_csv/README.rst b/sale_order_import_csv/README.rst index 200ad059bd..dc701fe1f0 100644 --- a/sale_order_import_csv/README.rst +++ b/sale_order_import_csv/README.rst @@ -36,13 +36,13 @@ Read the description of the *sale_order_import* module for a detailed usage desc .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/167/8.0 + :target: https://runbot.odoo-community.org/runbot/226/8.0 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/sale_order_import_ubl/README.rst b/sale_order_import_ubl/README.rst index 9e05038ba0..c396ee8af9 100644 --- a/sale_order_import_ubl/README.rst +++ b/sale_order_import_ubl/README.rst @@ -25,13 +25,13 @@ Read the description of the *sale_order_import* module for a detailed usage desc .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/167/8.0 + :target: https://runbot.odoo-community.org/runbot/226/8.0 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/sale_order_ubl/README.rst b/sale_order_ubl/README.rst index b7563a52f0..12481a13ee 100644 --- a/sale_order_ubl/README.rst +++ b/sale_order_ubl/README.rst @@ -24,13 +24,13 @@ Usage .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/167/8.0 + :target: https://runbot.odoo-community.org/runbot/226/8.0 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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. diff --git a/sale_stock_order_import/README.rst b/sale_stock_order_import/README.rst index b970393c6e..628ad07158 100644 --- a/sale_stock_order_import/README.rst +++ b/sale_stock_order_import/README.rst @@ -20,13 +20,13 @@ Refer to the README.rst of the module *sale_order_import* for a detailed usage d .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/167/8.0 + :target: https://runbot.odoo-community.org/runbot/226/8.0 Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. 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.