Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

l10n_ch: Move ISR subscription fields under res.partner.bank #35873

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 24 additions & 24 deletions addons/l10n_ch/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
class AccountMove(models.Model):
_inherit = 'account.move'

l10n_ch_isr_postal = fields.Char(compute='_compute_l10n_ch_isr_postal', help='The postal reference identifying the bank managing this ISR.')
l10n_ch_isr_postal_formatted = fields.Char(compute='_compute_l10n_ch_isr_postal', help="Postal reference of the bank, formated with '-' and without the padding zeros, to generate ISR report.")
l10n_ch_isr_subscription = fields.Char(compute='_compute_l10n_ch_isr_subscription', help='ISR subscription number identifying your company or your bank to generate ISR.')
l10n_ch_isr_subscription_formatted = fields.Char(compute='_compute_l10n_ch_isr_subscription', help="ISR subscription number your company or your bank, formated with '-' and without the padding zeros, to generate ISR report.")

l10n_ch_isr_number = fields.Char(compute='_compute_l10n_ch_isr_number', store=True, help='The reference number associated with this invoice')
l10n_ch_isr_number_spaced = fields.Char(compute='_compute_l10n_ch_isr_number', help="ISR number split in blocks of 5 characters (right-justified), to generate ISR report.")
Expand All @@ -28,34 +28,34 @@ class AccountMove(models.Model):
l10n_ch_isr_sent = fields.Boolean(default=False, help="Boolean value telling whether or not the ISR corresponding to this invoice has already been printed or sent by mail.")
l10n_ch_currency_name = fields.Char(related='currency_id.name', readonly=True, string="Currency Name", help="The name of this invoice's currency") #This field is used in the "invisible" condition field of the 'Print ISR' button.

@api.depends('invoice_partner_bank_id.bank_id.l10n_ch_postal_eur', 'invoice_partner_bank_id.bank_id.l10n_ch_postal_chf')
def _compute_l10n_ch_isr_postal(self):
""" Computes the postal reference identifying the bank managing this ISR and formats it accordingly"""
def _format_isr_postal(isr_postal):
@api.depends('invoice_partner_bank_id.l10n_ch_isr_subscription_eur', 'invoice_partner_bank_id.l10n_ch_isr_subscription_chf')
def _compute_l10n_ch_isr_subscription(self):
""" Computes the ISR subscription identifying your company or the bank that allows to generate ISR. And formats it accordingly"""
def _format_isr_subscription(isr_subscription):
#format the isr as per specifications
currency_code = isr_postal[:2]
middle_part = isr_postal[2:-1]
trailing_cipher = isr_postal[-1]
currency_code = isr_subscription[:2]
middle_part = isr_subscription[2:-1]
trailing_cipher = isr_subscription[-1]
middle_part = re.sub('^0*', '', middle_part)
return currency_code + '-' + middle_part + '-' + trailing_cipher

def _format_isr_postal_scanline(isr_postal):
def _format_isr_subscription_scanline(isr_subscription):
# format the isr for scanline
return isr_postal[:2] + isr_postal[2:-1].rjust(6, '0') + isr_postal[-1:]
return isr_subscription[:2] + isr_subscription[2:-1].rjust(6, '0') + isr_subscription[-1:]

for record in self:
if record.invoice_partner_bank_id and record.invoice_partner_bank_id.bank_id:
if record.invoice_partner_bank_id:
if record.currency_id.name == 'EUR':
isr_postal = record.invoice_partner_bank_id.bank_id.l10n_ch_postal_eur
isr_subscription = record.invoice_partner_bank_id.l10n_ch_isr_subscription_eur
elif record.currency_id.name == 'CHF':
isr_postal = record.invoice_partner_bank_id.bank_id.l10n_ch_postal_chf
isr_subscription = record.invoice_partner_bank_id.l10n_ch_isr_subscription_chf
else:
#we don't format if in another currency as EUR or CHF
continue

if isr_postal:
record.l10n_ch_isr_postal = _format_isr_postal_scanline(isr_postal)
record.l10n_ch_isr_postal_formatted = _format_isr_postal(isr_postal)
if isr_subscription:
record.l10n_ch_isr_subscription = _format_isr_subscription_scanline(isr_subscription)
record.l10n_ch_isr_subscription_formatted = _format_isr_subscription(isr_subscription)

@api.depends('name', 'invoice_partner_bank_id.l10n_ch_postal')
def _compute_l10n_ch_isr_number(self):
Expand Down Expand Up @@ -93,8 +93,8 @@ def _space_isr_number(isr_number):
@api.depends(
'currency_id.name', 'amount_total', 'name',
'invoice_partner_bank_id.l10n_ch_postal',
'invoice_partner_bank_id.bank_id.l10n_ch_postal_eur',
'invoice_partner_bank_id.bank_id.l10n_ch_postal_chf')
'invoice_partner_bank_id.l10n_ch_isr_subscription_eur',
'invoice_partner_bank_id.l10n_ch_isr_subscription_chf')
def _compute_l10n_ch_isr_optical_line(self):
""" The optical reading line of the ISR looks like this :
left>isr_ref+ bank_ref>
Expand All @@ -113,7 +113,7 @@ def _compute_l10n_ch_isr_optical_line(self):
bank supporting the ISR (including the zeros).
"""
for record in self:
if record.l10n_ch_isr_number and record.l10n_ch_isr_postal and record.currency_id.name:
if record.l10n_ch_isr_number and record.l10n_ch_isr_subscription and record.currency_id.name:
#Left part
currency_code = None
if record.currency_id.name == 'CHF':
Expand All @@ -126,19 +126,19 @@ def _compute_l10n_ch_isr_optical_line(self):
left = currency_code + amount_ref
left = mod10r(left)
#Final assembly (the space after the '+' is no typo, it stands in the specs.)
record.l10n_ch_isr_optical_line = left + '>' + record.l10n_ch_isr_number + '+ ' + record.l10n_ch_isr_postal + '>'
record.l10n_ch_isr_optical_line = left + '>' + record.l10n_ch_isr_number + '+ ' + record.l10n_ch_isr_subscription + '>'

@api.depends(
'type', 'name', 'currency_id.name',
'invoice_partner_bank_id.l10n_ch_postal',
'invoice_partner_bank_id.bank_id.l10n_ch_postal_eur',
'invoice_partner_bank_id.bank_id.l10n_ch_postal_chf')
'invoice_partner_bank_id.l10n_ch_isr_subscription_eur',
'invoice_partner_bank_id.l10n_ch_isr_subscription_chf')
def _compute_l10n_ch_isr_valid(self):
"""Returns True if all the data required to generate the ISR are present"""
for record in self:
record.l10n_ch_isr_valid = record.type == 'out_invoice' and\
record.name and \
record.l10n_ch_isr_postal and \
record.l10n_ch_isr_subscription and \
record.invoice_partner_bank_id.l10n_ch_postal and \
record.l10n_ch_currency_name in ['EUR', 'CHF']

Expand Down
16 changes: 6 additions & 10 deletions addons/l10n_ch/models/res_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ def _is_l10n_ch_postal(account_ref):
return False


class ResBank(models.Model):
_inherit = 'res.bank'

l10n_ch_postal_chf = fields.Char(string='CHF ISR reference', help='The postal reference of the bank, used to generate ISR payment slips in CHF.')
l10n_ch_postal_eur = fields.Char(string='EUR ISR reference', help='The postal reference of the bank, used to generate ISR payment slips in EUR.')


class ResPartnerBank(models.Model):
_inherit = 'res.partner.bank'

l10n_ch_postal = fields.Char(string='ISR reference', help='The ISR number of the company within the bank')
l10n_ch_postal = fields.Char(string='Swiss postal account', help='Swiss postal account number eg. 01-162-8')
# fields to configure ISR payment slip generation
l10n_ch_isr_subscription_chf = fields.Char(string='CHF ISR subscription number', help='The subscription number provided by the bank or Postfinance, used to generate ISR in CHF. eg. 01-162-8')
l10n_ch_isr_subscription_eur = fields.Char(string='EUR ISR subscription number', help='The subscription number provided by the bank or Postfinance, used to generate ISR in EUR. eg. 03-162-5')

@api.model
def _get_supported_account_types(self):
Expand Down Expand Up @@ -136,7 +132,7 @@ def validate_swiss_code_arguments(self, currency, debitor):
t_street_deb = False

if(currency.name == 'EUR'):
return (self.bank_id.l10n_ch_postal_eur and
return (self.l10n_ch_postal_subscription_eur and
self.company_id.zip and
self.company_id.city and
self.company_id.country_id.code and
Expand All @@ -147,7 +143,7 @@ def validate_swiss_code_arguments(self, currency, debitor):
debitor.country_id.code and
(number != False) and (number_deb != False))
elif(currency.name == 'CHF'):
return (self.bank_id.l10n_ch_postal_chf and
return (self.l10n_ch_postal_subscription_chf and
self.company_id.zip and
self.company_id.city and
self.company_id.country_id.code and
Expand Down
5 changes: 3 additions & 2 deletions addons/l10n_ch/report/isr_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

<div id="voucher-bank" t-if="not print_bank or not invoice.company_id.l10n_ch_isr_preprinted_account">
<!--Konto/Compte/Conto-->
<p id="voucher-bank_ref" t-field="invoice.l10n_ch_isr_postal_formatted"/>
<p id="voucher-bank_ref" t-field="invoice.l10n_ch_isr_subscription_formatted"/>
</div>

<p id="voucher-amount_units" t-esc="split_total_amount[0]"/>
Expand Down Expand Up @@ -123,7 +123,8 @@

<div id="slip-bank" t-if="not print_bank or not invoice.company_id.l10n_ch_isr_preprinted_account">
<!--Konto/Compte/Conto-->
<p id="slip-bank_ref" t-field="invoice.l10n_ch_isr_postal_formatted"/>
<!--aka ISR Subscriber number provided by the financial institution-->
<p id="slip-bank_ref" t-field="invoice.l10n_ch_isr_subscription_formatted"/>
</div>

<p id="slip-amount_units" t-esc="split_total_amount[0]"/>
Expand Down
10 changes: 5 additions & 5 deletions addons/l10n_ch/report/swissqr_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>

<img class="swissqr" t-att-src="o.invoice_partner_bank_id.build_swiss_code_url(o.amount_residual, o.currency_id.name, o.invoice_date_due, o.partner_id, 'QRR',
(o.invoice_partner_bank_id.bank_id.l10n_ch_postal_eur) if (o.invoice_partner_bank_id.currency_id.name == 'EUR') else o.invoice_partner_bank_id.bank_id.l10n_ch_postal_chf,
(o.invoice_partner_bank_id.l10n_ch_isr_subscription_chf) if (o.invoice_partner_bank_id.currency_id.name == 'CHF') else o.invoice_partner_bank_id.l10n_ch_isr_subscription_chf,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I inverted the logic to have the default with CHF, as it is really more common to have CHF here.

(o.ref) if (o.ref) else o.name)"/>
<img class="ch_cross" src="/l10n_ch/static/src/img/CH-Cross_7mm.png"/>

Expand All @@ -33,10 +33,10 @@

<span class="swissqr_text title">Reference number</span><br/>
<t t-if="o.invoice_partner_bank_id.currency_id.name == 'EUR'">
<span class="swissqr_text content" t-field="o.invoice_partner_bank_id.bank_id.l10n_ch_postal_eur"/><br/>
<span class="swissqr_text content" t-field="o.invoice_partner_bank_id.l10n_ch_isr_subscription_eur"/><br/>
</t>
<t t-if="o.invoice_partner_bank_id.currency_id.name == 'CHF'">
<span class="swissqr_text content" t-field="o.invoice_partner_bank_id.bank_id.l10n_ch_postal_chf"/><br/>
<span class="swissqr_text content" t-field="o.invoice_partner_bank_id.l10n_ch_isr_subscription_chf"/><br/>
</t>

<span class="swissqr_text title">Additional information</span><br/>
Expand Down Expand Up @@ -68,8 +68,8 @@
<div class="swissqr_body" t-if="(o.invoice_partner_bank_id.validate_swiss_code_arguments(o.invoice_partner_bank_id.currency_id, o.partner_id) == False) and ((o.currency_id.name == 'EUR') or (o.currency_id.name == 'CHF'))">
<div class="swissqr_column_left procedure_zone">
<span>Some pieces of this information are not set correctly to display the Swiss QR Code.<br/>
-Bank > CHF ISR reference<br/>
-Bank > EUR ISR reference<br/>
-Bank > CHF ISR subscription<br/>
-Bank > EUR ISR subscription<br/>
-Your company > Street with number<br/>
-Your company > City<br/>
-Your company > Zip<br/>
Expand Down
14 changes: 2 additions & 12 deletions addons/l10n_ch/views/res_bank_view.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="isr_res_bank_form" model="ir.ui.view">
<field name="name">l10n_ch.res.bank.form</field>
<field name="model">res.bank</field>
<field name="inherit_id" ref="base.view_res_bank_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='bic']" position="after">
<field name="l10n_ch_postal_chf"/>
<field name="l10n_ch_postal_eur"/>
</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"/>
<field name="l10n_ch_isr_subscription_chf"/>
<field name="l10n_ch_isr_subscription_eur"/>
</xpath>
</field>
</record>
Expand Down