[ADD] l10n_ch_qriban: QR-IBAN field on bank account
QR-IBAN can be different than IBAN, so we added a separate field to be able to put the QR-IBAN. It can be in handy in cases of reconciliation afterwards or when different systems are used at the same time. If this field is filled in, we will use it for generating the QR-IBAN barcode instead of the Account Number. Thanks to Ravi Gohil. closes odoo/odoo#57707 Task: 2307262 X-original-commit: 1cca4d9ec624b08cb85b1e53727fd67a3804c95a Signed-off-by: Josse Colpaert <jco@openerp.com>
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import models
|
||||
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
{
|
||||
'name': "Switzerland - QR-IBAN",
|
||||
'description': """
|
||||
Swiss localization
|
||||
==================
|
||||
Added a QR-IBAN field on bank account.
|
||||
If this field is empty, but the bank account number itself is a valid QR-IBAN number, it will still be used as QR-IBAN as before.
|
||||
But if you fill in the new QR-IBAN field, that one will be used as the QR-IBAN. This should help for reconciliation as
|
||||
on the bank statements, the old IBAN code is still used.
|
||||
""",
|
||||
'version': '1.0',
|
||||
'author': 'Odoo S.A',
|
||||
'category': 'Localization',
|
||||
'depends': ['l10n_ch'],
|
||||
'data': [
|
||||
'views/res_bank_views.xml',
|
||||
'views/swissqr_report.xml',
|
||||
],
|
||||
'auto_install': True,
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * l10n_ch_qriban
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 13.0+e\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-09-02 11:41+0000\n"
|
||||
"PO-Revision-Date: 2020-09-02 11:41+0000\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: l10n_ch_qriban
|
||||
#: model:ir.model,name:l10n_ch_qriban.model_res_partner_bank
|
||||
msgid "Bank Accounts"
|
||||
msgstr ""
|
||||
|
||||
#. module: l10n_ch_qriban
|
||||
#: model:ir.model.fields,help:l10n_ch_qriban.field_account_setup_bank_manual_config__l10n_ch_qr_iban
|
||||
#: model:ir.model.fields,help:l10n_ch_qriban.field_res_partner_bank__l10n_ch_qr_iban
|
||||
msgid ""
|
||||
"Put the QR-IBAN here for your own bank accounts. That way, you can still "
|
||||
"use the main IBAN in the Account Number while you will see the QR-IBAN for "
|
||||
"the barcode. "
|
||||
msgstr ""
|
||||
|
||||
#. module: l10n_ch_qriban
|
||||
#: model:ir.model.fields,field_description:l10n_ch_qriban.field_account_setup_bank_manual_config__l10n_ch_qr_iban
|
||||
#: model:ir.model.fields,field_description:l10n_ch_qriban.field_res_partner_bank__l10n_ch_qr_iban
|
||||
msgid "QR-IBAN"
|
||||
msgstr ""
|
||||
|
||||
#. module: l10n_ch_qriban
|
||||
#: code:addons/l10n_ch_qriban/models/res_bank.py:0
|
||||
#, python-format
|
||||
msgid "QR-IBAN '%s' is invalid."
|
||||
msgstr ""
|
||||
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import res_bank
|
||||
@@ -0,0 +1,47 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.addons.base_iban.models.res_partner_bank import normalize_iban, pretty_iban, validate_iban
|
||||
from odoo.addons.base.models.res_bank import sanitize_account_number
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
class ResPartnerBank(models.Model):
|
||||
_inherit = 'res.partner.bank'
|
||||
|
||||
l10n_ch_qr_iban = fields.Char(string='QR-IBAN', help="Put the QR-IBAN here for your own bank accounts. That way, you can "
|
||||
"still use the main IBAN in the Account Number while you will see the "
|
||||
"QR-IBAN for the barcode. ")
|
||||
|
||||
def _validate_qr_iban(self, qr_iban):
|
||||
# Check first if it's a valid IBAN.
|
||||
validate_iban(qr_iban)
|
||||
# We sanitize first so that _check_qr_iban_range() can extract correct IID from IBAN to validate it.
|
||||
sanitized_qr_iban = sanitize_account_number(qr_iban)
|
||||
# Now, check if it's valid QR-IBAN (based on its IID).
|
||||
if not self._check_qr_iban_range(sanitized_qr_iban):
|
||||
raise ValidationError(_("QR-IBAN '%s' is invalid.") % qr_iban)
|
||||
return True
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get('l10n_ch_qr_iban'):
|
||||
self._validate_qr_iban(vals['l10n_ch_qr_iban'])
|
||||
vals['l10n_ch_qr_iban'] = pretty_iban(normalize_iban(vals['l10n_ch_qr_iban']))
|
||||
return super().create(vals)
|
||||
|
||||
def write(self, vals):
|
||||
if vals.get('l10n_ch_qr_iban'):
|
||||
self._validate_qr_iban(vals['l10n_ch_qr_iban'])
|
||||
vals['l10n_ch_qr_iban'] = pretty_iban(normalize_iban(vals['l10n_ch_qr_iban']))
|
||||
return super().write(vals)
|
||||
|
||||
def _is_qr_iban(self):
|
||||
return super()._is_qr_iban() or self.l10n_ch_qr_iban
|
||||
|
||||
def _l10n_ch_get_qr_vals(self, amount, currency, debtor_partner, free_communication, structured_communication):
|
||||
qr_vals = super()._l10n_ch_get_qr_vals(amount, currency, debtor_partner, free_communication, structured_communication)
|
||||
# If there is a QR IBAN we use it for the barcode instead of the account number
|
||||
if self.l10n_ch_qr_iban:
|
||||
qr_vals[3] = sanitize_account_number(self.l10n_ch_qr_iban)
|
||||
return qr_vals
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="view_partner_bank_form" model="ir.ui.view">
|
||||
<field name="name">l10n_ch_qr.res.partner.bank.form</field>
|
||||
<field name="model">res.partner.bank</field>
|
||||
<field name="inherit_id" ref="l10n_ch.isr_partner_bank_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//label[@for='l10n_ch_postal']" position="before">
|
||||
<field name="l10n_ch_qr_iban" attrs="{'invisible': [('l10n_ch_show_subscription', '=', False)]}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Setup wizard view -->
|
||||
<record id="setup_bank_account_wizard_qr_inherit" model="ir.ui.view">
|
||||
<field name="name">account.setup.bank.manual.config.form.ch.qr.inherit</field>
|
||||
<field name="model">account.setup.bank.manual.config</field>
|
||||
<field name="inherit_id" ref="l10n_ch.setup_bank_account_wizard_inherit"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="l10n_ch_postal" position="after">
|
||||
<field name="l10n_ch_qr_iban" attrs="{'invisible': [('l10n_ch_show_subscription', '=', False)]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<template id="l10n_ch_swissqr_qriban_template" inherit_id="l10n_ch.l10n_ch_swissqr_template">
|
||||
<xpath expr="//div[@id='receipt_indication_zone']/div[hasclass('swissqr_text')]/span[@t-field='o.partner_bank_id.acc_number']" position="replace">
|
||||
<span class="content" t-field="o.partner_bank_id.acc_number" t-if="not o.partner_bank_id.l10n_ch_qr_iban"/>
|
||||
<span class="content" t-field="o.partner_bank_id.l10n_ch_qr_iban" t-if="o.partner_bank_id.l10n_ch_qr_iban"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='indications_zone']/div[hasclass('swissqr_text')]/span[@t-field='o.partner_bank_id.acc_number']" position="replace">
|
||||
<span class="content" t-field="o.partner_bank_id.acc_number" t-if="not o.partner_bank_id.l10n_ch_qr_iban"/>
|
||||
<span class="content" t-field="o.partner_bank_id.l10n_ch_qr_iban" t-if="o.partner_bank_id.l10n_ch_qr_iban"/>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user