From 3f930a3c4e20ca8b970b1cdd00e99819c4f4aec2 Mon Sep 17 00:00:00 2001 From: david Date: Wed, 25 Nov 2020 08:58:19 +0100 Subject: [PATCH] # This is a combination of 4 commits. # This is the 1st commit message: 85a93e806e5b41883375082d5036f63c2dc78e5c # This is the commit message #2: use qr_iban validation methode # This is the commit message #3: fix commit # This is the commit message #4: remove debug info --- l10n_ch_pain_base/models/account_move_line.py | 8 ++++--- .../models/account_payment_line.py | 2 +- .../models/account_payment_order.py | 22 +++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/l10n_ch_pain_base/models/account_move_line.py b/l10n_ch_pain_base/models/account_move_line.py index 3882b42d9..ddb6663a9 100644 --- a/l10n_ch_pain_base/models/account_move_line.py +++ b/l10n_ch_pain_base/models/account_move_line.py @@ -3,7 +3,6 @@ from odoo import models, api - class AccountMoveLine(models.Model): _inherit = 'account.move.line' @@ -11,8 +10,11 @@ class AccountMoveLine(models.Model): def _prepare_payment_line_vals(self, payment_order): vals = super()._prepare_payment_line_vals(payment_order) if self.invoice_id and self.invoice_id._is_isr_reference(): - vals['local_instrument'] = 'CH01' - vals['communication_type'] = 'isr' + if self.invoice_id.partner_bank_id._is_qr_iban(): + vals['communication_type'] = 'qrr' + else: + vals['local_instrument'] = 'CH01' + vals['communication_type'] = 'isr' if vals['communication']: vals['communication'] = vals['communication'].replace(' ', '') return vals diff --git a/l10n_ch_pain_base/models/account_payment_line.py b/l10n_ch_pain_base/models/account_payment_line.py index 28cd4c063..a63c28a32 100644 --- a/l10n_ch_pain_base/models/account_payment_line.py +++ b/l10n_ch_pain_base/models/account_payment_line.py @@ -9,7 +9,7 @@ class AccountPaymentLine(models.Model): local_instrument = fields.Selection( selection_add=[('CH01', 'CH01 (ISR)')]) - communication_type = fields.Selection(selection_add=[('isr', 'ISR')]) + communication_type = fields.Selection(selection_add=[('isr', 'ISR'), ('qrr', 'QRR')]) def invoice_reference_type2communication_type(self): res = super().invoice_reference_type2communication_type() diff --git a/l10n_ch_pain_base/models/account_payment_order.py b/l10n_ch_pain_base/models/account_payment_order.py index a8468a326..9a3047e64 100644 --- a/l10n_ch_pain_base/models/account_payment_order.py +++ b/l10n_ch_pain_base/models/account_payment_order.py @@ -127,3 +127,25 @@ def generate_address_block( adrline2.text = ' '.join([partner.zip, partner.city]) return True + + @api.model + def generate_remittance_info_block(self, parent_node, line, gen_args): + if line.communication_type == "qrr": + remittance_info = etree.SubElement( + parent_node, 'RmtInf') + remittance_info_structured = etree.SubElement( + remittance_info, 'Strd') + creditor_ref_information = etree.SubElement( + remittance_info_structured, 'CdtrRefInf') + 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, 'Prtry') + creditor_ref_info_type_code.text = 'QRR' + creditor_reference = etree.SubElement( + creditor_ref_information, 'Ref') + creditor_reference.text = line.payment_line_ids[0].communication + else: + super().generate_remittance_info_block(parent_node, line, gen_args)