diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/sale/wizard/sale_payment_link.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/sale/wizard/sale_payment_link.py')
| -rw-r--r-- | addons/sale/wizard/sale_payment_link.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/addons/sale/wizard/sale_payment_link.py b/addons/sale/wizard/sale_payment_link.py new file mode 100644 index 00000000..823a2e11 --- /dev/null +++ b/addons/sale/wizard/sale_payment_link.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from werkzeug import urls + +from odoo import api, models + + +class SalePaymentLink(models.TransientModel): + _inherit = "payment.link.wizard" + _description = "Generate Sales Payment Link" + + @api.model + def default_get(self, fields): + res = super(SalePaymentLink, self).default_get(fields) + if res['res_id'] and res['res_model'] == 'sale.order': + record = self.env[res['res_model']].browse(res['res_id']) + res.update({ + 'description': record.name, + 'amount': record.amount_total - sum(record.invoice_ids.filtered(lambda x: x.state != 'cancel').mapped('amount_total')), + 'currency_id': record.currency_id.id, + 'partner_id': record.partner_id.id, + 'amount_max': record.amount_total + }) + return res + + def _generate_link(self): + """ Override of the base method to add the order_id in the link. """ + 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': + record = self.env[payment_link.res_model].browse(payment_link.res_id) + 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') % ( + record.get_base_url(), + urls.url_quote_plus(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() |
