[IMP] payment, sale: add an acquirer dropdown when generating payment link
Actually, salesmen have to add manually the acquirer_id to the link, and it isn't user-friendly. The dropdown will show the possibility to add the acquirer_id. Task #2504225 closes odoo/odoo#69334 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com> Co-authored-by: Valentin Chevalier <vcr@odoo.com>
This commit is contained in:
committed by
Demesmaeker
co-authored by
Valentin Chevalier
parent
69976584d8
commit
41b13d530f
@@ -42,6 +42,22 @@ class PaymentLinkWizard(models.TransientModel):
|
||||
description = fields.Char('Payment Ref')
|
||||
access_token = fields.Char(compute='_compute_values')
|
||||
company_id = fields.Many2one('res.company', compute='_compute_company')
|
||||
available_acquirer_ids = fields.Many2many(
|
||||
comodel_name='payment.acquirer',
|
||||
string="Payment Acquirers Available",
|
||||
compute='_compute_available_acquirer_ids',
|
||||
compute_sudo=True,
|
||||
)
|
||||
acquirer_id = fields.Many2one(
|
||||
comodel_name='payment.acquirer',
|
||||
string="Specific Payment Acquirer",
|
||||
domain="[('id', 'in', available_acquirer_ids)]",
|
||||
help="Leave blank to select all acquirers"
|
||||
)
|
||||
has_multiple_acquirers = fields.Boolean(
|
||||
string="Has Multiple Acquirers",
|
||||
compute='_compute_has_multiple_acquirers',
|
||||
)
|
||||
|
||||
@api.onchange('amount', 'description')
|
||||
def _onchange_amount(self):
|
||||
@@ -50,7 +66,7 @@ class PaymentLinkWizard(models.TransientModel):
|
||||
if self.amount <= 0:
|
||||
raise ValidationError(_("The value of the payment amount must be positive."))
|
||||
|
||||
@api.depends('amount', 'description', 'partner_id', 'currency_id')
|
||||
@api.depends('amount', 'description', 'partner_id', 'currency_id', 'acquirer_id')
|
||||
def _compute_values(self):
|
||||
for payment_link in self:
|
||||
payment_link.access_token = payment_utils.generate_access_token(
|
||||
@@ -65,6 +81,20 @@ class PaymentLinkWizard(models.TransientModel):
|
||||
record = self.env[link.res_model].browse(link.res_id)
|
||||
link.company_id = record.company_id if 'company_id' in record else False
|
||||
|
||||
@api.depends('company_id', 'partner_id', 'currency_id')
|
||||
def _compute_available_acquirer_ids(self):
|
||||
for link in self:
|
||||
link.available_acquirer_ids = link.env['payment.acquirer']._get_compatible_acquirers(
|
||||
company_id=link.company_id.id,
|
||||
partner_id=link.partner_id.id,
|
||||
currency_id=link.currency_id.id
|
||||
)
|
||||
|
||||
@api.depends('available_acquirer_ids')
|
||||
def _compute_has_multiple_acquirers(self):
|
||||
for link in self:
|
||||
link.has_multiple_acquirers = len(link.available_acquirer_ids) > 1
|
||||
|
||||
def _generate_link(self):
|
||||
for payment_link in self:
|
||||
related_document = self.env[payment_link.res_model].browse(payment_link.res_id)
|
||||
@@ -75,4 +105,5 @@ class PaymentLinkWizard(models.TransientModel):
|
||||
f'¤cy_id={payment_link.currency_id.id}' \
|
||||
f'&partner_id={payment_link.partner_id.id}' \
|
||||
f'&company_id={payment_link.company_id.id}' \
|
||||
f'{"&acquirer_id=" + str(payment_link.acquirer_id.id) if payment_link.acquirer_id else "" }' \
|
||||
f'&access_token={payment_link.access_token}'
|
||||
|
||||
@@ -13,8 +13,14 @@
|
||||
<field name="partner_id" invisible="1"/>
|
||||
<field name="partner_email" invisible="1"/>
|
||||
<field name="amount_max" invisible="1"/>
|
||||
<field name="available_acquirer_ids" invisible="1"/>
|
||||
<field name="has_multiple_acquirers" invisible="1"/>
|
||||
<field name="description"/>
|
||||
<field name="amount"/>
|
||||
<field name="acquirer_id"
|
||||
placeholder="Leave blank to select all acquirers"
|
||||
options="{'no_open': True, 'no_create': True}"
|
||||
attrs="{'invisible':[('has_multiple_acquirers', '=', False)]}"/>
|
||||
<field name="currency_id" invisible="1"/>
|
||||
<field name="access_token" invisible="1"/>
|
||||
</group>
|
||||
|
||||
@@ -24,6 +24,17 @@ class PaymentLinkWizard(models.TransientModel):
|
||||
})
|
||||
return res
|
||||
|
||||
@api.depends('company_id', 'partner_id', 'currency_id')
|
||||
def _compute_available_acquirer_ids(self):
|
||||
sale_links = self.filtered(lambda link: link.res_model == 'sale.order')
|
||||
super(PaymentLinkWizard, self-sale_links)._compute_available_acquirer_ids()
|
||||
for link in sale_links:
|
||||
link.available_acquirer_ids = link.env['payment.acquirer']._get_compatible_acquirers(
|
||||
company_id=link.company_id.id,
|
||||
partner_id=link.partner_id.id,
|
||||
currency_id=link.currency_id.id,
|
||||
sale_order_id=link.res_id)
|
||||
|
||||
def _generate_link(self):
|
||||
""" Override of payment to add the sale_order_id in the link. """
|
||||
for payment_link in self:
|
||||
@@ -35,6 +46,7 @@ class PaymentLinkWizard(models.TransientModel):
|
||||
f'?reference={urls.url_quote(payment_link.description)}' \
|
||||
f'&amount={payment_link.amount}' \
|
||||
f'&sale_order_id={payment_link.res_id}' \
|
||||
f'{"&acquirer_id=" + str(payment_link.acquirer_id.id) if payment_link.acquirer_id else "" }' \
|
||||
f'&access_token={payment_link.access_token}'
|
||||
# Order-related fields are retrieved in the controller
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user