Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8.0 Add support for partner bank matching on invoice update #6

Merged
merged 2 commits into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions account_invoice_import_invoice2data/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<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
4 changes: 2 additions & 2 deletions account_invoice_import_ubl/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<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
4 changes: 2 additions & 2 deletions account_invoice_import_zugferd/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<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
4 changes: 2 additions & 2 deletions account_invoice_ubl/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<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
4 changes: 2 additions & 2 deletions account_invoice_zugferd/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
======================
Expand All @@ -48,7 +48,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
4 changes: 2 additions & 2 deletions base_business_document_import/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<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
30 changes: 30 additions & 0 deletions base_business_document_import/models/business_document_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it more tolerant, put chatter_msg as optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, it is that way in all the other methods of this module.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you can start with this one being more tolerant 😉 for reusing it in models without chatter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I'll change that, I'll change it everywhere ; I don't want to do it partially.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good moment for that 😉, but I know that you're not going to do it, hehe

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make this with SQL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need the replace() method in SQL because the IBAN can have spaces in res_partner_bank. In v9, this problem is solved by the acc_number_sanitized field, so I will remove this SQL request in v9 and use the ORM instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

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(_(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to modify the translations due to this file change I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Translations are handled automatically via transifex, no ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but you will lose any of the already present translations. It's just to check and modify translation files to see the comment line about the code that contains this sentence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no translation for this module so far.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

"The bank account <b>IBAN %s</b> has been automatically "
"added on the supplier <b>%s</b>") % (
iban, partner.name))
return partner_bank

@api.model
def _match_product(self, product_dict, chatter_msg, seller=False):
"""Example:
Expand Down
4 changes: 2 additions & 2 deletions base_business_document_import_phone/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<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
4 changes: 2 additions & 2 deletions base_business_document_import_stock/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<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
4 changes: 2 additions & 2 deletions base_ubl/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<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
4 changes: 2 additions & 2 deletions base_ubl_payment/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<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
4 changes: 2 additions & 2 deletions base_zugferd/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<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
4 changes: 2 additions & 2 deletions purchase_order_import/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://github.com/OCA/purchase-workflow/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
4 changes: 2 additions & 2 deletions purchase_order_import_ubl/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://github.com/OCA/purchase-workflow/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
4 changes: 2 additions & 2 deletions purchase_order_ubl/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://github.com/OCA/purchase-workflow/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
4 changes: 2 additions & 2 deletions sale_order_import/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://github.com/OCA/sale-workflow/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
4 changes: 2 additions & 2 deletions sale_order_import_csv/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://github.com/OCA/sale-workflow/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
Loading