From f3c1e6cfbe70f9dd37cc7c7b3b3464c5b9af280b Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Tue, 20 Aug 2019 15:14:21 +0000 Subject: [PATCH] Move ISR subscription fields under res.partner.bank An Inpayment Slip with Reference (ISR) subscription number is provided by the bank or by Postfinance ISR When the ISR subscription comes from Postfinance it is a direct subscription. ISR (bank) When the ISR subscription comes from a bank it is the bank subscription toward Postfinance. Having the subscription number on res.bank has 2 drawbacks: If you have multiple accounts at Postfinance or If you have multicompany and each company has a Postfinance account you won't be able to emit with different ISR subscriber numbers. This also renames the fields to be accurate on the meaning. An ISR reference is a Payment reference that will apear on the invoice. It is better to name it subscription number. closes odoo/odoo#35873 Signed-off-by: Josse Colpaert --- addons/l10n_ch/models/account_invoice.py | 48 ++++++++++++------------ addons/l10n_ch/models/res_bank.py | 16 +++----- addons/l10n_ch/report/isr_report.xml | 5 ++- addons/l10n_ch/report/swissqr_report.xml | 10 ++--- addons/l10n_ch/views/res_bank_view.xml | 14 +------ 5 files changed, 40 insertions(+), 53 deletions(-) diff --git a/addons/l10n_ch/models/account_invoice.py b/addons/l10n_ch/models/account_invoice.py index 775d206b7ae..194ec3869e7 100644 --- a/addons/l10n_ch/models/account_invoice.py +++ b/addons/l10n_ch/models/account_invoice.py @@ -15,8 +15,8 @@ l10n_ch_ISR_NUMBER_ISSUER_LENGTH = 12 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.") @@ -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): @@ -93,8 +93,8 @@ class AccountMove(models.Model): @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> @@ -113,7 +113,7 @@ class AccountMove(models.Model): 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': @@ -126,19 +126,19 @@ class AccountMove(models.Model): 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'] diff --git a/addons/l10n_ch/models/res_bank.py b/addons/l10n_ch/models/res_bank.py index 7fec01e1ddb..b8a1954fdd3 100644 --- a/addons/l10n_ch/models/res_bank.py +++ b/addons/l10n_ch/models/res_bank.py @@ -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): @@ -136,7 +132,7 @@ class ResPartnerBank(models.Model): 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 @@ -147,7 +143,7 @@ class ResPartnerBank(models.Model): 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 diff --git a/addons/l10n_ch/report/isr_report.xml b/addons/l10n_ch/report/isr_report.xml index bf25cf171e8..bbc3ed89641 100644 --- a/addons/l10n_ch/report/isr_report.xml +++ b/addons/l10n_ch/report/isr_report.xml @@ -81,7 +81,7 @@
-

+

@@ -123,7 +123,8 @@

-

+ +

diff --git a/addons/l10n_ch/report/swissqr_report.xml b/addons/l10n_ch/report/swissqr_report.xml index 8199ef8b9bf..a58d721bfbb 100644 --- a/addons/l10n_ch/report/swissqr_report.xml +++ b/addons/l10n_ch/report/swissqr_report.xml @@ -16,7 +16,7 @@ @@ -33,10 +33,10 @@ Reference number
-
+
-
+
Additional information
@@ -68,8 +68,8 @@

Some pieces of this information are not set correctly to display the Swiss QR Code.
- -Bank > CHF ISR reference
- -Bank > EUR ISR reference
+ -Bank > CHF ISR subscription
+ -Bank > EUR ISR subscription
-Your company > Street with number
-Your company > City
-Your company > Zip
diff --git a/addons/l10n_ch/views/res_bank_view.xml b/addons/l10n_ch/views/res_bank_view.xml index 90329ee4813..c4ed4ffaf70 100644 --- a/addons/l10n_ch/views/res_bank_view.xml +++ b/addons/l10n_ch/views/res_bank_view.xml @@ -1,18 +1,6 @@ - - l10n_ch.res.bank.form - res.bank - - - - - - - - - l10n_ch.res.partner.bank.form res.partner.bank @@ -20,6 +8,8 @@ + +