diff options
| author | Damien Bouvy <dbo@odoo.com> | 2020-05-18 07:50:33 +0000 |
|---|---|---|
| committer | Damien Bouvy <dbo@odoo.com> | 2020-05-18 12:07:34 +0000 |
| commit | 34867df7286e188f589c15cef44d758ea5c95a5a (patch) | |
| tree | 7fb7d951e113cc6365faebe8eea6f783695aadcf /addons/payment | |
| parent | 59c075b46156c91778f8660c0241b798dc4e3765 (diff) | |
[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>
Diffstat (limited to 'addons/payment')
| -rw-r--r-- | addons/payment/controllers/portal.py | 15 | ||||
| -rw-r--r-- | addons/payment/wizards/payment_link_wizard.py | 20 |
2 files changed, 32 insertions, 3 deletions
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): |
