diff --git a/addons/payment_custom/models/payment_provider.py b/addons/payment_custom/models/payment_provider.py
index f83213708cd..ab13256569f 100644
--- a/addons/payment_custom/models/payment_provider.py
+++ b/addons/payment_custom/models/payment_provider.py
@@ -1,7 +1,6 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import _, api, fields, models
-from odoo.tools import is_html_empty
class PaymentProvider(models.Model):
@@ -24,6 +23,12 @@ class PaymentProvider(models.Model):
qr_code = fields.Boolean(
string="Enable QR Codes", help="Enable the use of QR-codes when paying by wire transfer.")
+ @api.model_create_multi
+ def create(self, values_list):
+ providers = super().create(values_list)
+ providers.filtered(lambda p: p.custom_mode == 'wire_transfer').pending_msg = None
+ return providers
+
@api.depends('code')
def _compute_view_configuration_fields(self):
""" Override of payment to hide the credentials page.
@@ -39,41 +44,33 @@ class PaymentProvider(models.Model):
'show_cancel_msg': False,
})
- def _transfer_ensure_pending_msg_is_set(self):
- transfer_providers_without_msg = self.filtered(
- lambda p: p.code == 'custom'
- and p.custom_mode == 'wire_transfer'
- and is_html_empty(p.pending_msg)
- )
-
- if not transfer_providers_without_msg:
- return # Don't bother translating the messages.
-
+ def action_recompute_pending_msg(self):
+ """ Recompute the pending message to include the existing bank accounts. """
account_payment_module = self.env['ir.module.module']._get('account_payment')
- if account_payment_module.state != 'installed':
- transfer_providers_without_msg.pending_msg = f'
' \
- f'
{_("Please use the following transfer details")}
' \
- f'
{_("Bank Account")}
' \
- f'
{_("Communication")}
' \
- f'
{_("Please use the order name as communication reference.")}
' \
- f'
'
- return
-
- for provider in transfer_providers_without_msg:
- company_id = provider.company_id.id
- accounts = self.env['account.journal'].search([
- ('type', '=', 'bank'), ('company_id', '=', company_id)
- ]).bank_account_id
- provider.pending_msg = f'' \
- f'
{_("Please use the following transfer details")}
' \
- f'
{_("Bank Account") if len(accounts) == 1 else _("Bank Accounts")}
' \
- f'
{"".join(f"- {account.display_name}
" for account in accounts)}
' \
- f'
{_("Communication")}
' \
- f'
{_("Please use the order name as communication reference.")}
' \
- f'
'
+ if account_payment_module.state == 'installed':
+ for provider in self.filtered(lambda p: p.custom_mode == 'wire_transfer'):
+ company_id = provider.company_id.id
+ accounts = self.env['account.journal'].search([
+ ('type', '=', 'bank'), ('company_id', '=', company_id)
+ ]).bank_account_id
+ account_names = "".join(f"{account.display_name}" for account in accounts)
+ provider.pending_msg = f'' \
+ f'
{_("Please use the following transfer details")}
' \
+ f'
{_("Bank Account") if len(accounts) == 1 else _("Bank Accounts")}
' \
+ f'
' \
+ f'
{_("Communication")}
' \
+ f'
{_("Please use the order name as communication reference.")}
' \
+ f'
'
def _get_removal_values(self):
""" Override of `payment` to nullify the `custom_mode` field. """
res = super()._get_removal_values()
res['custom_mode'] = None
return res
+
+ def _transfer_ensure_pending_msg_is_set(self):
+ transfer_providers_without_msg = self.filtered(
+ lambda p: p.custom_mode == 'wire_transfer' and not p.pending_msg
+ )
+ if transfer_providers_without_msg:
+ transfer_providers_without_msg.action_recompute_pending_msg()
diff --git a/addons/payment_custom/views/payment_provider_views.xml b/addons/payment_custom/views/payment_provider_views.xml
index 4718cb13c13..413e64ee5c9 100644
--- a/addons/payment_custom/views/payment_provider_views.xml
+++ b/addons/payment_custom/views/payment_provider_views.xml
@@ -6,6 +6,9 @@
payment.provider
+
+
+
@@ -14,6 +17,17 @@
{'invisible': [('code', '=', 'custom')]}
+
+
+
+
+