From 85a93e806e5b41883375082d5036f63c2dc78e5c Mon Sep 17 00:00:00 2001 From: Elico Corp - Odoo Docker Date: Tue, 24 Nov 2020 04:19:02 +0000 Subject: [PATCH] add QRR field and QRR in the pain message --- l10n_ch_pain_base/models/account_move_line.py | 12 +++++++--- .../models/account_payment_line.py | 2 +- .../models/account_payment_order.py | 22 +++++++++++++++++++ 3 files changed, 32 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 3882b42d9a..d4573caf68 100644 --- a/l10n_ch_pain_base/models/account_move_line.py +++ b/l10n_ch_pain_base/models/account_move_line.py @@ -2,7 +2,8 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import models, api - +import logging +_logger = logging.getLogger(__name__) class AccountMoveLine(models.Model): _inherit = 'account.move.line' @@ -11,8 +12,13 @@ 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' + _logger.info('PREPARE '+self.invoice_id.partner_bank_id.sanitized_acc_number[4:6]) + if self.invoice_id.partner_bank_id.sanitized_acc_number[4:6] in ['30', '31'] \ + and self.invoice_id.partner_bank_id.acc_type == '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 28cd4c063b..a63c28a321 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 2bf4a29325..aac888a6e4 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)