[IMP] l10n_ch: allow manual value for postal bank accounts
Previously, the ISR reference was computed from the iban number but it seems some banks (for example UBS) use arbitrary ISR references that needs to be manually set. Was task: 40975 Was PR #22931
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
from . import res_config_settings
|
||||
from . import account_invoice
|
||||
from . import account_journal
|
||||
from . import mail_template
|
||||
from . import res_bank
|
||||
from . import res_company
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models, fields, api
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from odoo.addons.base_iban.models.res_partner_bank import validate_iban
|
||||
from odoo.addons.base.models.res_bank import sanitize_account_number
|
||||
|
||||
|
||||
class AccountJournal(models.Model):
|
||||
_inherit = 'account.journal'
|
||||
|
||||
# creation of bank journals by giving the account number, allow craetion of the
|
||||
l10n_ch_postal = fields.Char(related='bank_account_id.l10n_ch_postal')
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
rslt = super(AccountJournal, self).create(vals)
|
||||
|
||||
# The call to super() creates the related bank_account_id field
|
||||
if 'l10n_ch_postal' in vals:
|
||||
rslt.l10n_ch_postal = vals['l10n_ch_postal']
|
||||
return rslt
|
||||
|
||||
def write(self, vals):
|
||||
rslt = super(AccountJournal, self).write(vals)
|
||||
|
||||
# The call to super() creates the related bank_account_id field if necessary
|
||||
if 'l10n_ch_postal' in vals:
|
||||
for record in self:
|
||||
record.bank_account_id.l10n_ch_postal = vals['l10n_ch_postal']
|
||||
return rslt
|
||||
|
||||
@api.onchange('bank_acc_number')
|
||||
def _onchange_set_l10n_ch_postal(self):
|
||||
try:
|
||||
validate_iban(self.bank_acc_number)
|
||||
is_iban = True
|
||||
except ValidationError:
|
||||
is_iban = False
|
||||
|
||||
if is_iban:
|
||||
self.l10n_ch_postal = self.env['res.partner.bank']._retrieve_l10n_ch_postal(sanitize_account_number(self.bank_acc_number))
|
||||
else:
|
||||
self.l10n_ch_postal = self.bank_acc_number
|
||||
@@ -29,7 +29,7 @@ class ResPartnerBank(models.Model):
|
||||
_inherit = 'res.partner.bank'
|
||||
|
||||
acc_type = fields.Selection(selection_add=[("postal", "Postal")])
|
||||
l10n_ch_postal = fields.Char(help='The ISR number of the company within the bank', compute='_compute_l10n_ch_postal')
|
||||
l10n_ch_postal = fields.Char(string='ISR reference', help='The ISR number of the company within the bank')
|
||||
|
||||
@api.depends('acc_number')
|
||||
def _compute_acc_type(self):
|
||||
@@ -42,14 +42,14 @@ class ResPartnerBank(models.Model):
|
||||
else:
|
||||
super(ResPartnerBank, record)._compute_acc_type()
|
||||
|
||||
@api.depends('acc_number')
|
||||
def _compute_l10n_ch_postal(self):
|
||||
for record in self:
|
||||
if record.acc_type == 'iban':
|
||||
record.l10n_ch_postal = record._retrieve_l10n_ch_postal(record.sanitized_acc_number)
|
||||
else:
|
||||
record.l10n_ch_postal = record.sanitized_acc_number
|
||||
@api.onchange('acc_number')
|
||||
def _onchange_set_l10n_ch_postal(self):
|
||||
if self.acc_type == 'iban':
|
||||
self.l10n_ch_postal = self._retrieve_l10n_ch_postal(self.sanitized_acc_number)
|
||||
else:
|
||||
self.l10n_ch_postal = self.sanitized_acc_number
|
||||
|
||||
@api.model
|
||||
def _retrieve_l10n_ch_postal(self, iban):
|
||||
""" Reads a swiss postal account number from a an IBAN and returns it as
|
||||
a string. Returns None if no valid postal account number was found, or
|
||||
|
||||
@@ -12,5 +12,27 @@
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="isr_partner_bank_form" model="ir.ui.view">
|
||||
<field name="name">l10n_ch.res.partner.bank.form</field>
|
||||
<field name="model">res.partner.bank</field>
|
||||
<field name="inherit_id" ref="base.view_partner_bank_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='acc_number']" position="after">
|
||||
<field name="l10n_ch_postal"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="isr_bank_journal_form" model="ir.ui.view">
|
||||
<field name="name">l10n_ch.bank.journal.form</field>
|
||||
<field name="model">account.journal</field>
|
||||
<field name="inherit_id" ref="account.view_account_bank_journal_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='bank_acc_number']" position="after">
|
||||
<field name="l10n_ch_postal"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user