From f64f2af001f4ece32cba45e0751e15c91db64b82 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 27 Sep 2023 22:30:31 +0200 Subject: [PATCH] Add warning when payment order is not SEPA The field 'sepa' on account.payment.order is only display for SEPA payment methods. If the option "show warning if not SEPA" is enabled on the payment method, a warning banner is now displayed on payment orders with a SEPA payment method which are not SEPA. --- .../models/account_payment_method.py | 1 + .../models/account_payment_order.py | 67 +++++++++++++------ .../static/description/index.html | 14 ++-- .../views/account_payment_method.xml | 5 ++ .../views/account_payment_order.xml | 33 +++++---- .../__manifest__.py | 2 +- .../data/account_payment_method.xml | 1 + .../migrations/14.0.2.0.3/post-migration.py | 11 +++ .../tests/test_sct.py | 5 +- .../__manifest__.py | 2 +- .../data/account_payment_method.xml | 1 + .../migrations/14.0.2.1.2/post-migration.py | 11 +++ .../models/account_payment_line.py | 3 + .../views/account_payment_line.xml | 1 + 14 files changed, 113 insertions(+), 44 deletions(-) create mode 100644 account_banking_sepa_credit_transfer/migrations/14.0.2.0.3/post-migration.py create mode 100644 account_banking_sepa_direct_debit/migrations/14.0.2.1.2/post-migration.py diff --git a/account_banking_pain_base/models/account_payment_method.py b/account_banking_pain_base/models/account_payment_method.py index 067468c81..1172dd16c 100644 --- a/account_banking_pain_base/models/account_payment_method.py +++ b/account_banking_pain_base/models/account_payment_method.py @@ -16,6 +16,7 @@ class AccountPaymentMethod(models.Model): "the corresponding unaccented character, so that only ASCII " "characters are used in the generated PAIN file.", ) + warn_not_sepa = fields.Boolean(string="Warn If Not SEPA") def get_xsd_file_path(self): """This method is designed to be inherited in the SEPA modules""" diff --git a/account_banking_pain_base/models/account_payment_order.py b/account_banking_pain_base/models/account_payment_order.py index 854fb409f..b472507b1 100644 --- a/account_banking_pain_base/models/account_payment_order.py +++ b/account_banking_pain_base/models/account_payment_order.py @@ -24,7 +24,12 @@ logger = logging.getLogger(__name__) class AccountPaymentOrder(models.Model): _inherit = "account.payment.order" - sepa = fields.Boolean(compute="_compute_sepa", readonly=True, string="SEPA Payment") + sepa = fields.Boolean(compute="_compute_sepa", string="SEPA Payment") + sepa_payment_method = fields.Boolean( + compute="_compute_sepa", + string="SEPA Payment Method", + ) + show_warning_not_sepa = fields.Boolean(compute="_compute_sepa") charge_bearer = fields.Selection( [ ("SLEV", "Following Service Level"), @@ -105,6 +110,7 @@ class AccountPaymentOrder(models.Model): ] @api.depends( + "payment_mode_id", "company_partner_bank_id.acc_type", "company_partner_bank_id.sanitized_acc_number", "payment_line_ids.currency_id", @@ -115,30 +121,47 @@ class AccountPaymentOrder(models.Model): eur = self.env.ref("base.EUR") sepa_list = self._sepa_iban_prefix_list() for order in self: - sepa = True - if order.company_partner_bank_id.acc_type != "iban": - sepa = False - if ( - order.company_partner_bank_id - and order.company_partner_bank_id.sanitized_acc_number[:2] - not in sepa_list - ): - sepa = False - for pline in order.payment_line_ids: - if pline.currency_id != eur: - sepa = False - break - if pline.partner_bank_id.acc_type != "iban": - sepa = False - break + sepa_payment_method = False + sepa = False + warn_not_sepa = False + payment_method = order.payment_mode_id.payment_method_id + if payment_method.pain_version: + sepa_payment_method = True + sepa = True if ( - pline.partner_bank_id - and pline.partner_bank_id.sanitized_acc_number[:2] not in sepa_list + order.company_partner_bank_id + and order.company_partner_bank_id.acc_type != "iban" ): sepa = False - break - sepa = order.compute_sepa_final_hook(sepa) - self.sepa = sepa + if ( + order.company_partner_bank_id + and order.company_partner_bank_id.sanitized_acc_number[:2] + not in sepa_list + ): + sepa = False + for pline in order.payment_line_ids: + if pline.currency_id != eur: + sepa = False + break + if ( + pline.partner_bank_id + and pline.partner_bank_id.acc_type != "iban" + ): + sepa = False + break + if ( + pline.partner_bank_id + and pline.partner_bank_id.sanitized_acc_number[:2] + not in sepa_list + ): + sepa = False + break + sepa = order.compute_sepa_final_hook(sepa) + if not sepa and payment_method.warn_not_sepa: + warn_not_sepa = True + order.sepa = sepa + order.sepa_payment_method = sepa_payment_method + order.show_warning_not_sepa = warn_not_sepa def compute_sepa_final_hook(self, sepa): self.ensure_one() diff --git a/account_banking_pain_base/static/description/index.html b/account_banking_pain_base/static/description/index.html index 35c209333..d2ae85607 100644 --- a/account_banking_pain_base/static/description/index.html +++ b/account_banking_pain_base/static/description/index.html @@ -1,4 +1,3 @@ - @@ -9,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +275,7 @@ pre.literal-block, pre.doctest-block, pre.math, pre.code { margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +301,7 @@ span.option { span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -458,12 +458,16 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
  • Carlos Roca
  • +
  • Ooops404: +* Eduard Brahas <eduard@ooops404.com>
  • Maintainers

    This module is maintained by the OCA.

    -Odoo Community Association + +Odoo Community Association +

    OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

    diff --git a/account_banking_pain_base/views/account_payment_method.xml b/account_banking_pain_base/views/account_payment_method.xml index 266d9ff61..de0fd0127 100644 --- a/account_banking_pain_base/views/account_payment_method.xml +++ b/account_banking_pain_base/views/account_payment_method.xml @@ -10,10 +10,15 @@ + + diff --git a/account_banking_pain_base/views/account_payment_order.xml b/account_banking_pain_base/views/account_payment_order.xml index b06fdcacb..ff88a22b5 100644 --- a/account_banking_pain_base/views/account_payment_order.xml +++ b/account_banking_pain_base/views/account_payment_order.xml @@ -13,26 +13,31 @@ /> - + + + - - - - pain.base.account.payment.order.tree - account.payment.order - - - - - +
    + +
    diff --git a/account_banking_sepa_credit_transfer/__manifest__.py b/account_banking_sepa_credit_transfer/__manifest__.py index bafa6dbd6..bf82b6c18 100644 --- a/account_banking_sepa_credit_transfer/__manifest__.py +++ b/account_banking_sepa_credit_transfer/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Account Banking SEPA Credit Transfer", "summary": "Create SEPA XML files for Credit Transfers", - "version": "14.0.2.0.2", + "version": "14.0.2.0.3", "license": "AGPL-3", "author": "Akretion, Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/bank-payment", diff --git a/account_banking_sepa_credit_transfer/data/account_payment_method.xml b/account_banking_sepa_credit_transfer/data/account_payment_method.xml index 01b08910a..2d16c170a 100644 --- a/account_banking_sepa_credit_transfer/data/account_payment_method.xml +++ b/account_banking_sepa_credit_transfer/data/account_payment_method.xml @@ -6,5 +6,6 @@ outbound pain.001.001.03 + diff --git a/account_banking_sepa_credit_transfer/migrations/14.0.2.0.3/post-migration.py b/account_banking_sepa_credit_transfer/migrations/14.0.2.0.3/post-migration.py new file mode 100644 index 000000000..c41e4b774 --- /dev/null +++ b/account_banking_sepa_credit_transfer/migrations/14.0.2.0.3/post-migration.py @@ -0,0 +1,11 @@ +# Copyright 2023 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + sct_method = env.ref("account_banking_sepa_credit_transfer.sepa_credit_transfer") + sct_method.write({"warn_not_sepa": True}) diff --git a/account_banking_sepa_credit_transfer/tests/test_sct.py b/account_banking_sepa_credit_transfer/tests/test_sct.py index 49a1addb3..668c4841d 100644 --- a/account_banking_sepa_credit_transfer/tests/test_sct.py +++ b/account_banking_sepa_credit_transfer/tests/test_sct.py @@ -192,7 +192,10 @@ class TestSCT(SavepointCase): self.assertEqual(agrolait_pay_line1.communication, "F1341") self.payment_order.draft2open() self.assertEqual(self.payment_order.state, "open") - self.assertEqual(self.payment_order.sepa, True) + if self.payment_mode.payment_method_id.pain_version: + self.assertTrue(self.payment_order.sepa) + else: + self.assertFalse(self.payment_order.sepa) self.assertTrue(self.payment_order.payment_ids) agrolait_bank_line = self.payment_order.payment_ids[0] self.assertEqual(agrolait_bank_line.currency_id, self.eur_currency) diff --git a/account_banking_sepa_direct_debit/__manifest__.py b/account_banking_sepa_direct_debit/__manifest__.py index 823a4d820..829755be9 100644 --- a/account_banking_sepa_direct_debit/__manifest__.py +++ b/account_banking_sepa_direct_debit/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Account Banking SEPA Direct Debit", "summary": "Create SEPA files for Direct Debit", - "version": "14.0.2.1.1", + "version": "14.0.2.1.2", "license": "AGPL-3", "author": "Akretion, Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/bank-payment", diff --git a/account_banking_sepa_direct_debit/data/account_payment_method.xml b/account_banking_sepa_direct_debit/data/account_payment_method.xml index 16463e917..eb83d1b0b 100644 --- a/account_banking_sepa_direct_debit/data/account_payment_method.xml +++ b/account_banking_sepa_direct_debit/data/account_payment_method.xml @@ -7,5 +7,6 @@ pain.008.001.02 + diff --git a/account_banking_sepa_direct_debit/migrations/14.0.2.1.2/post-migration.py b/account_banking_sepa_direct_debit/migrations/14.0.2.1.2/post-migration.py new file mode 100644 index 000000000..292df1868 --- /dev/null +++ b/account_banking_sepa_direct_debit/migrations/14.0.2.1.2/post-migration.py @@ -0,0 +1,11 @@ +# Copyright 2023 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + sct_method = env.ref("account_banking_sepa_direct_debit.sepa_direct_debit") + sct_method.write({"warn_not_sepa": True}) diff --git a/account_payment_order/models/account_payment_line.py b/account_payment_order/models/account_payment_line.py index eac8cb933..24a3efa8d 100644 --- a/account_payment_order/models/account_payment_line.py +++ b/account_payment_order/models/account_payment_line.py @@ -66,6 +66,9 @@ class AccountPaymentLine(models.Model): ondelete="restrict", check_company=True, ) + partner_bank_acc_type = fields.Selection( + related="partner_bank_id.acc_type", string="Bank Account Type" + ) date = fields.Date(string="Payment Date") # communication field is required=False because we don't want to block # the creation of lines from move/invoices when communication is empty diff --git a/account_payment_order/views/account_payment_line.xml b/account_payment_order/views/account_payment_line.xml index 1c2c72a06..0e9ec5c61 100644 --- a/account_payment_order/views/account_payment_line.xml +++ b/account_payment_order/views/account_payment_line.xml @@ -59,6 +59,7 @@ +