summaryrefslogtreecommitdiff
path: root/addons/account_qr_code_sepa/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/account_qr_code_sepa/models
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/account_qr_code_sepa/models')
-rw-r--r--addons/account_qr_code_sepa/models/__init__.py3
-rw-r--r--addons/account_qr_code_sepa/models/res_bank.py59
2 files changed, 62 insertions, 0 deletions
diff --git a/addons/account_qr_code_sepa/models/__init__.py b/addons/account_qr_code_sepa/models/__init__.py
new file mode 100644
index 00000000..6570df4c
--- /dev/null
+++ b/addons/account_qr_code_sepa/models/__init__.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+from . import res_bank \ No newline at end of file
diff --git a/addons/account_qr_code_sepa/models/res_bank.py b/addons/account_qr_code_sepa/models/res_bank.py
new file mode 100644
index 00000000..6f97df14
--- /dev/null
+++ b/addons/account_qr_code_sepa/models/res_bank.py
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+
+from odoo import models, fields, api, _
+
+import werkzeug
+
+
+class ResPartnerBank(models.Model):
+ _inherit = 'res.partner.bank'
+
+ def _get_qr_code_url(self, qr_method, amount, currency, debtor_partner, free_communication, structured_communication):
+ if qr_method == 'sct_qr':
+
+ comment = (free_communication or '') if not structured_communication else ''
+
+ qr_code_vals = [
+ 'BCD', # Service Tag
+ '002', # Version
+ '1', # Character Set
+ 'SCT', # Identification Code
+ self.bank_bic or '', # BIC of the Beneficiary Bank
+ (self.acc_holder_name or self.partner_id.name)[:71], # Name of the Beneficiary
+ self.sanitized_acc_number, # Account Number of the Beneficiary
+ str(amount), # Amount of the Transfer in EUR
+ '', # Purpose of the Transfer
+ (structured_communication or '')[:36], # Remittance Information (Structured)
+ comment[:141], # Remittance Information (Unstructured) (can't be set if there is a structured one)
+ '', # Beneficiary to Originator Information
+ ]
+
+ return '/report/barcode/?' + werkzeug.urls.url_encode({'type': 'QR', 'value': '\n'.join(qr_code_vals), 'width': 128, 'height': 128, 'humanreadable': 1})
+
+ return super()._get_qr_code_url(qr_method, amount, currency, debtor_partner, free_communication, structured_communication)
+
+ def _eligible_for_qr_code(self, qr_method, debtor_partner, currency):
+ if qr_method == 'sct_qr':
+
+ # Some countries share the same IBAN country code
+ # (e.g. Åland Islands and Finland IBANs are 'FI', but Åland Islands' code is 'AX').
+ sepa_country_codes = self.env.ref('base.sepa_zone').country_ids.mapped('code')
+ non_iban_codes = {'AX', 'NC', 'YT', 'TF', 'BL', 'RE', 'MF', 'GP', 'PM', 'PF', 'GF', 'MQ', 'JE', 'GG', 'IM'}
+ sepa_iban_codes = {code for code in sepa_country_codes if code not in non_iban_codes}
+
+ return currency.name == 'EUR' and self.acc_type == 'iban' and self.sanitized_acc_number[:2] in sepa_iban_codes
+
+ return super()._eligible_for_qr_code(qr_method, debtor_partner, currency)
+
+ def _check_for_qr_code_errors(self, qr_method, amount, currency, debtor_partner, free_communication, structured_communication):
+ if qr_method == 'sct_qr':
+ if not self.acc_holder_name and not self.partner_id.name:
+ return _("The account receiving the payment must have an account holder name or partner name set.")
+
+ return super()._check_for_qr_code_errors(qr_method, amount, currency, debtor_partner, free_communication, structured_communication)
+
+ @api.model
+ def _get_available_qr_methods(self):
+ rslt = super()._get_available_qr_methods()
+ rslt.append(('sct_qr', _("SEPA Credit Transfer QR"), 20))
+ return rslt