From 8a8352aae8f5d040e903d7dc479d785059813e3a Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 30 Sep 2015 03:37:28 +0200 Subject: [PATCH] [FIX] account_banking_payment_export: Correct communication type for customer invoices in payment lines --- account_banking_payment_export/__openerp__.py | 2 +- .../models/account_invoice.py | 32 +++++++++++++++++++ .../wizard/payment_order_create.py | 25 +++++++-------- 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/account_banking_payment_export/__openerp__.py b/account_banking_payment_export/__openerp__.py index 0e1c7c1ac..fadcdeb21 100644 --- a/account_banking_payment_export/__openerp__.py +++ b/account_banking_payment_export/__openerp__.py @@ -7,7 +7,7 @@ { 'name': 'Account Banking - Payments Export Infrastructure', - 'version': '8.0.0.2.0', + 'version': '8.0.0.3.0', 'license': 'AGPL-3', 'author': "ACSONE SA/NV, " "Therp BV, " diff --git a/account_banking_payment_export/models/account_invoice.py b/account_banking_payment_export/models/account_invoice.py index ce60117a8..f500e99fd 100644 --- a/account_banking_payment_export/models/account_invoice.py +++ b/account_banking_payment_export/models/account_invoice.py @@ -4,6 +4,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import api, models, _ +from lxml import etree class AccountInvoice(models.Model): @@ -14,3 +15,34 @@ class AccountInvoice(models.Model): rt = super(AccountInvoice, self)._get_reference_type() rt.append(('structured', _('Structured Reference'))) return rt + + @api.model + def fields_view_get(self, view_id=None, view_type=False, toolbar=False, + submenu=False): + """This adds the field 'reference_type' only if the view doesn't + contain this field (this is for customer invoice and with + l10n_be_invoice_bba not installed). + """ + res = super(AccountInvoice, self).fields_view_get( + view_id=view_id, view_type=view_type, toolbar=toolbar, + submenu=submenu) + if view_type != 'form': + return res + field_name = 'reference_type' + doc = etree.XML(res['arch']) + if not doc.xpath("//field[@name='%s']" % field_name): + nodes = doc.xpath("//field[@name='origin']") + if nodes: + field = self.fields_get([field_name])[field_name] + field_xml = etree.Element( + 'field', {'name': field_name, + 'widget': 'selection', + 'states': str(field['states']), + 'selection': str(field['selection']), + 'required': '1' if field['required'] else '0', + 'string': field['string'], + 'nolabel': '0'}) + nodes[0].addnext(field_xml) + res['arch'] = etree.tostring(doc) + res['fields'][field_name] = field + return res diff --git a/account_banking_payment_export/wizard/payment_order_create.py b/account_banking_payment_export/wizard/payment_order_create.py index 0ef18563e..6fea3a8fe 100644 --- a/account_banking_payment_export/wizard/payment_order_create.py +++ b/account_banking_payment_export/wizard/payment_order_create.py @@ -186,20 +186,19 @@ class PaymentOrderCreate(models.TransientModel): state = 'normal' communication = line.ref or '-' if line.invoice: - if line.invoice.type in ('in_invoice', 'in_refund'): - if line.invoice.reference_type == 'structured': - state = 'structured' - communication = line.invoice.reference - else: - if line.invoice.reference: - communication = line.invoice.reference - elif line.invoice.supplier_invoice_number: - communication = line.invoice.supplier_invoice_number - else: - # Make sure that the communication includes the - # customer invoice number (in the case of debit order) - communication = line.invoice.number.replace('/', '') + if line.invoice.reference_type == 'structured': state = 'structured' + # Fallback to invoice number to keep previous behaviour + communication = line.invoice.reference or line.invoice.number + else: + if line.invoice.type in ('in_invoice', 'in_refund'): + communication = ( + line.invoice.reference or + line.invoice.supplier_invoice_number or line.ref) + else: + # Make sure that the communication includes the + # customer invoice number (in the case of debit order) + communication = line.invoice.number # support debit orders when enabled if line.debit > 0: amount_currency = line.amount_residual_currency * -1