mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Merge pull request #217 from pedrobaeza/8.0-reference_type-fix
[FIX] account_banking_payment_export: Correct communication type for customer invoices in payment lines
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user