From a10188c7c428434ea91080bcc1453220ddc9c7bd Mon Sep 17 00:00:00 2001 From: Thomas Winteler Date: Tue, 9 May 2023 11:34:04 +0200 Subject: [PATCH] [IMP] account_banking_pain_base: add needed QRR information to generate correct XML file structure --- .../models/account_payment_line.py | 18 +++++- .../models/account_payment_order.py | 56 ++++++++++++------- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/account_banking_pain_base/models/account_payment_line.py b/account_banking_pain_base/models/account_payment_line.py index 40f13da..56f90c5 100644 --- a/account_banking_pain_base/models/account_payment_line.py +++ b/account_banking_pain_base/models/account_payment_line.py @@ -3,7 +3,7 @@ # Copyright 2021 Tecnativa - Carlos Roca # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from flectra import fields, models +from flectra import fields, models, api, _ class AccountPaymentLine(models.Model): @@ -173,3 +173,19 @@ class AccountPaymentLine(models.Model): communication_type = fields.Selection( selection_add=[("ISO", "ISO")], ondelete={"ISO": "cascade"} ) + + @api.model + def create(self, vals): + if vals.get("name", "New") == "New": + vals["name"] = ( + self.env["ir.sequence"].next_by_code("account.payment.line") or "New" + ) + result = super(AccountPaymentLine, self).create(vals) + + # set proper communication type + if result.communication.startswith('RF'): + result.communication_type = 'SCOR' + elif result.partner_bank_id._is_qr_iban(): + result.communication_type = 'QRR' + + return result diff --git a/account_banking_pain_base/models/account_payment_order.py b/account_banking_pain_base/models/account_payment_order.py index 0dc72e3..1259461 100644 --- a/account_banking_pain_base/models/account_payment_order.py +++ b/account_banking_pain_base/models/account_payment_order.py @@ -12,6 +12,7 @@ from lxml import etree from flectra import _, api, fields, models, tools from flectra.exceptions import UserError from flectra.tools.safe_eval import safe_eval +import flectra.release try: from unidecode import unidecode @@ -397,6 +398,11 @@ class AccountPaymentOrder(models.Model): initiating_party = etree.SubElement(parent_node, "InitgPty") initiating_party_name = etree.SubElement(initiating_party, "Nm") initiating_party_name.text = my_company_name + initiating_party_software = etree.SubElement(initiating_party, 'CtctDtls') + initiating_party_software_name = etree.SubElement(initiating_party_software, 'Nm') + initiating_party_software_name.text = 'Flectra Open Source ERP and CRM' + initiating_party_software_version = etree.SubElement(initiating_party_software, 'Othr') + initiating_party_software_version.text = 'Version ' + flectra.release.version initiating_party_identifier = ( self.payment_mode_id.initiating_party_identifier or self.payment_mode_id.company_id.initiating_party_identifier @@ -635,31 +641,43 @@ class AccountPaymentOrder(models.Model): creditor_ref_information, "CdtrRef" ) else: - if gen_args.get("structured_remittance_issuer", True): + if line.communication_type == 'QRR': creditor_ref_info_type = etree.SubElement( - creditor_ref_information, "Tp" - ) + creditor_ref_information, 'Tp') creditor_ref_info_type_or = etree.SubElement( - creditor_ref_info_type, "CdOrPrtry" - ) + creditor_ref_info_type, 'CdOrPrtry') creditor_ref_info_type_code = etree.SubElement( - creditor_ref_info_type_or, "Cd" - ) - creditor_ref_info_type_code.text = "SCOR" + creditor_ref_info_type_or, 'Prtry') + creditor_ref_info_type_code.text = 'QRR' + elif line.communication_type == 'SCOR': + creditor_ref_info_type = etree.SubElement( + creditor_ref_information, 'Tp') + creditor_ref_info_type_or = etree.SubElement( + creditor_ref_info_type, 'CdOrPrtry') + creditor_ref_info_type_code = etree.SubElement( + creditor_ref_info_type_or, 'Cd') + creditor_ref_info_type_code.text = 'SCOR' + elif gen_args.get('structured_remittance_issuer', True): + creditor_ref_info_type = etree.SubElement( + creditor_ref_information, 'Tp') + creditor_ref_info_type_or = etree.SubElement( + creditor_ref_info_type, 'CdOrPrtry') + creditor_ref_info_type_code = etree.SubElement( + creditor_ref_info_type_or, 'Cd') + creditor_ref_info_type_code.text = 'SCOR' creditor_ref_info_type_issuer = etree.SubElement( - creditor_ref_info_type, "Issr" - ) - creditor_ref_info_type_issuer.text = line.communication_type + creditor_ref_info_type, 'Issr') + creditor_ref_info_type_issuer.text = \ + line.communication_type - creditor_reference = etree.SubElement(creditor_ref_information, "Ref") + creditor_reference = etree.SubElement( + creditor_ref_information, 'Ref') - creditor_reference.text = self._prepare_field( - "Creditor Structured Reference", - "line.communication", - {"line": line}, - 35, - gen_args=gen_args, - ) + creditor_reference.text = \ + self._prepare_field( + 'Creditor Structured Reference', + 'line.communication', {'line': line}, 35, + gen_args=gen_args) return True @api.model