diff --git a/addons/payment/controllers/portal.py b/addons/payment/controllers/portal.py index 23a6fe3b69e..ece7f11dcd6 100644 --- a/addons/payment/controllers/portal.py +++ b/addons/payment/controllers/portal.py @@ -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(): diff --git a/addons/payment/wizards/payment_link_wizard.py b/addons/payment/wizards/payment_link_wizard.py index 7dd543d997b..dd75560dd57 100644 --- a/addons/payment/wizards/payment_link_wizard.py +++ b/addons/payment/wizards/payment_link_wizard.py @@ -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): diff --git a/addons/sale/wizard/sale_payment_link.py b/addons/sale/wizard/sale_payment_link.py index c86072b2187..c3733af7ae7 100644 --- a/addons/sale/wizard/sale_payment_link.py +++ b/addons/sale/wizard/sale_payment_link.py @@ -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() \ No newline at end of file