[FIX] payment,sale: company information in payment wizard link
When generating a payment link through the payment link wizard, the company was previously not included. This could cause accounting issues if the acquirer displayed to the customer were not part of the same company as the underlying document that generated the link. This commit add a new computed field 'company_id' on the wizard model that gets computed based on the underlying model; this field will be included in links generated by the wizard to limit the acquirers displayed to those of the that company, preventing extra acocunting steps (interco reconciliation). opw-2254011 closes odoo/odoo#51441 X-original-commit: a6fcd7e0cfec8d4c62620a53b5fa806561e239af Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
This commit is contained in:
@@ -198,12 +198,23 @@ class WebsitePayment(http.Controller):
|
||||
|
||||
# Check acquirer
|
||||
acquirers = None
|
||||
if order_id and order:
|
||||
cid = order.company_id.id
|
||||
elif kw.get('company_id'):
|
||||
try:
|
||||
cid = int(kw.get('company_id'))
|
||||
except:
|
||||
cid = user.company_id.id
|
||||
else:
|
||||
cid = user.company_id.id
|
||||
acquirer_domain = [('state', 'in', ['enabled', 'test']), ('company_id', '=', cid)]
|
||||
|
||||
if acquirer_id:
|
||||
acquirers = env['payment.acquirer'].browse(int(acquirer_id))
|
||||
if order_id:
|
||||
acquirers = env['payment.acquirer'].search([('state', 'in', ['enabled', 'test']), ('company_id', '=', order.company_id.id)])
|
||||
acquirers = env['payment.acquirer'].search(acquirer_domain)
|
||||
if not acquirers:
|
||||
acquirers = env['payment.acquirer'].search([('state', 'in', ['enabled', 'test']), ('company_id', '=', user.company_id.id)])
|
||||
acquirers = env['payment.acquirer'].search(acquirer_domain)
|
||||
|
||||
# Check partner
|
||||
if not user._is_public():
|
||||
|
||||
@@ -41,6 +41,7 @@ class PaymentLinkWizard(models.TransientModel):
|
||||
link = fields.Char(string='Payment Link', compute='_compute_values')
|
||||
description = fields.Char('Payment Ref')
|
||||
access_token = fields.Char(compute='_compute_values')
|
||||
company_id = fields.Many2one('res.company', compute='_compute_company')
|
||||
|
||||
@api.onchange('amount', 'description')
|
||||
def _onchange_amount(self):
|
||||
@@ -58,10 +59,27 @@ class PaymentLinkWizard(models.TransientModel):
|
||||
# must be called after token generation, obvsly - the link needs an up-to-date token
|
||||
self._generate_link()
|
||||
|
||||
@api.depends('res_model', 'res_id')
|
||||
def _compute_company(self):
|
||||
for link in self:
|
||||
record = self.env[link.res_model].browse(link.res_id)
|
||||
link.company_id = record.company_id if 'company_id' in record else False
|
||||
|
||||
def _generate_link(self):
|
||||
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
for payment_link in self:
|
||||
payment_link.link = '%s/website_payment/pay?reference=%s&amount=%s¤cy_id=%s&partner_id=%s&access_token=%s' % (base_url, urls.url_quote(payment_link.description), payment_link.amount, payment_link.currency_id.id, payment_link.partner_id.id, payment_link.access_token)
|
||||
link = ('%s/website_payment/pay?reference=%s&amount=%s¤cy_id=%s'
|
||||
'&partner_id=%s&access_token=%s') % (
|
||||
base_url,
|
||||
urls.url_quote(payment_link.description),
|
||||
payment_link.amount,
|
||||
payment_link.currency_id.id,
|
||||
payment_link.partner_id.id,
|
||||
payment_link.access_token
|
||||
)
|
||||
if payment_link.company_id:
|
||||
link += '&company_id=%s' % payment_link.company_id.id
|
||||
payment_link.link = link
|
||||
|
||||
@api.model
|
||||
def check_token(self, access_token, partner_id, amount, currency_id):
|
||||
|
||||
@@ -30,7 +30,20 @@ class SalePaymentLink(models.TransientModel):
|
||||
for payment_link in self:
|
||||
# only add order_id for SOs,
|
||||
# otherwise the controller might try to link it with an unrelated record
|
||||
# NOTE: company_id is not necessary here, we have it in order_id
|
||||
# however, should parsing of the id fail in the controller, let's include
|
||||
# it anyway
|
||||
if payment_link.res_model == 'sale.order':
|
||||
payment_link.link = '%s/website_payment/pay?reference=%s&amount=%s¤cy_id=%s&partner_id=%s&order_id=%s&access_token=%s' % (base_url, urls.url_quote(payment_link.description), payment_link.amount, payment_link.currency_id.id, payment_link.partner_id.id, payment_link.res_id, payment_link.access_token)
|
||||
payment_link.link = ('%s/website_payment/pay?reference=%s&amount=%s¤cy_id=%s'
|
||||
'&partner_id=%s&order_id=%s&company_id=%s&access_token=%s') % (
|
||||
base_url,
|
||||
urls.url_quote(payment_link.description),
|
||||
payment_link.amount,
|
||||
payment_link.currency_id.id,
|
||||
payment_link.partner_id.id,
|
||||
payment_link.res_id,
|
||||
payment_link.company_id.id,
|
||||
payment_link.access_token
|
||||
)
|
||||
else:
|
||||
super(SalePaymentLink, payment_link)._generate_link()
|
||||
Reference in New Issue
Block a user