Skip to content
Browse files

[IMP] sale: Generate custom payment link

Purpose of the task is,
there is no easy way to request custom online payments on sales orders or invoices,
The only way is to create an URL manually: /website_payment/pay?reference=inv-008&amount=123&currency_id=1.

So Added Menu 'Generate payment link' in action in sales order.

Task ID : 1938635
Closes : #31575
  • Loading branch information...
sza-odoo authored and mba-odoo committed Mar 5, 2019
1 parent 2f932e3 commit cfdc3c185f8876aedc11d293a0fb4504da1a019e
@@ -34,6 +34,7 @@
'demo': [
@@ -3,4 +3,5 @@

from . import payment_acquirer_onboarding_wizard
from . import sale_make_invoice_advance
from . import sale_product_configurator
from . import sale_product_configurator
from . import sale_generate_payment_link
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models, fields, api, _
from odoo.exceptions import UserError

class SalePaymentLink(models.TransientModel):
_name = ""
_description = "Generate Sales Payment Link"

def default_get(self, fields):
res = super(SalePaymentLink, self).default_get(fields)
active_id = self._context.get('active_id')
active_model = self._context.get('active_model')
record = self.env[active_model].browse(active_id)
res['order_id'] = active_id
res['amount'] = record.amount_total
return res

order_id = fields.Many2one("sale.order", string="Reference ID", require=True)
amount = fields.Float(required=True)
link = fields.Char(string="Payment link")

def generate_payment_link(self):
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
if self.amount > 0 and self.order_id.amount_total >= self.amount: = '%s/website_payment/pay?reference=%s&model=%s&amount=%s&access_token=%s' % (base_url,, self._context.get('active_model'), self.amount, self.order_id.access_token)
raise UserError(_("The amount should be less than %s and positive value") % (self.order_id.amount_total))
return {
'name': _('Payment Link'),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': '',
'target': 'new',
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<record id="sale_generate_payment_link_view_form" model="ir.ui.view">
<field name="name"></field>
<field name="model"></field>
<field name="arch" type="xml">
<form string="Generate Payment Link">
<group name="details" attrs="{'invisible': [('link', '!=', False)]}">
<field name="order_id" readonly="1"/>
<field name="amount"/>
<field name="link" readonly="1" widget="CopyClipboardChar" attrs="{'invisible': [('link', '=', False)]}" options="{'string': 'Copy Link'}"/>
<button string="Generate Link" name="generate_payment_link" type="object" attrs="{'invisible': [('link','!=', False)]}" class="btn-primary"/>
<button string="Cancel" special="cancel" attrs="{'invisible': [('link','!=', False)]}"/>
<button string="Ok" class="btn-primary" special="cancel" attrs="{'invisible': [('link','==', False)]}"/>

<act_window name="Generate a Payment Link"

0 comments on commit cfdc3c1

Please sign in to comment.
You can’t perform that action at this time.