From c3f865e1dd0fb85c15cc06cb8363b0d7ae462bb4 Mon Sep 17 00:00:00 2001 From: Horacio Tellez Date: Thu, 6 Oct 2022 14:09:16 +0000 Subject: [PATCH] [IMP] payment_custom: allow for recomputing of pending message Before this commit (in the case the `custom_mode` is set to `wire_transfer`) the model tries to find existing bank accounts to compute a pending message with the necessary information. When bank accounts are not already setup we end with an incomplete message. After this commit we can at any point recompute the pending message and it will be updated with the current bank information. Task - 2511080 closes odoo/odoo#103903 Signed-off-by: Antoine Vandevenne (anv) --- .../payment_custom/models/payment_provider.py | 61 +++++++++---------- .../views/payment_provider_views.xml | 14 +++++ 2 files changed, 43 insertions(+), 32 deletions(-) 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'
      {account_names}
    ' \ + 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')]} + +
    +
    +