[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) <anv@odoo.com>
This commit is contained in:
@@ -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'<div>' \
|
||||
f'<h3>{_("Please use the following transfer details")}</h3>' \
|
||||
f'<h4>{_("Bank Account")}</h4>' \
|
||||
f'<h4>{_("Communication")}</h4>' \
|
||||
f'<p>{_("Please use the order name as communication reference.")}</p>' \
|
||||
f'</div>'
|
||||
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'<div>' \
|
||||
f'<h3>{_("Please use the following transfer details")}</h3>' \
|
||||
f'<h4>{_("Bank Account") if len(accounts) == 1 else _("Bank Accounts")}</h4>' \
|
||||
f'<ul>{"".join(f"<li>{account.display_name}</li>" for account in accounts)}</ul>' \
|
||||
f'<h4>{_("Communication")}</h4>' \
|
||||
f'<p>{_("Please use the order name as communication reference.")}</p>' \
|
||||
f'</div>'
|
||||
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"<li>{account.display_name}</li>" for account in accounts)
|
||||
provider.pending_msg = f'<div>' \
|
||||
f'<h3>{_("Please use the following transfer details")}</h3>' \
|
||||
f'<h4>{_("Bank Account") if len(accounts) == 1 else _("Bank Accounts")}</h4>' \
|
||||
f'<ul>{account_names}</ul>' \
|
||||
f'<h4>{_("Communication")}</h4>' \
|
||||
f'<p>{_("Please use the order name as communication reference.")}</p>' \
|
||||
f'</div>'
|
||||
|
||||
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()
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
<field name="model">payment.provider</field>
|
||||
<field name="inherit_id" ref="payment.payment_provider_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="code" invisible="1" position="after">
|
||||
<field name="custom_mode" invisible="1"/>
|
||||
</field>
|
||||
<field name="capture_manually" position="after">
|
||||
<field name="qr_code" attrs="{'invisible': [('code', '!=', 'custom')]}" />
|
||||
</field>
|
||||
@@ -14,6 +17,17 @@
|
||||
{'invisible': [('code', '=', 'custom')]}
|
||||
</attribute>
|
||||
</group>
|
||||
<field name="pending_msg" position="after">
|
||||
<div class="o_row" colspan="2"
|
||||
attrs="{'invisible': [('custom_mode', '!=', 'wire_transfer')]}">
|
||||
<button string=" Reload Pending Message"
|
||||
type="object"
|
||||
name="action_recompute_pending_msg"
|
||||
class="oe_link ms-0 ps-0"
|
||||
icon="fa-refresh"
|
||||
/>
|
||||
</div>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user