Skip to content
Permalink
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 @@
'views/payment_views.xml',
'views/product_attribute_views.xml',
'wizard/sale_product_configurator_views.xml',
'wizard/sale_generate_payment_link_views.xml',
],
'demo': [
'data/sale_demo.xml',
@@ -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 = "sale.payment.link"
_description = "Generate Sales Payment Link"

@api.model
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):
self.ensure_one()
self.order_id._portal_ensure_token()
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:
self.link = '%s/website_payment/pay?reference=%s&model=%s&amount=%s&access_token=%s' % (base_url, self.order_id.id, self._context.get('active_model'), self.amount, self.order_id.access_token)
else:
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': 'sale.payment.link',
'res_id': self.id,
'target': 'new',
}
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="sale_generate_payment_link_view_form" model="ir.ui.view">
<field name="name">sale.payment.link.form</field>
<field name="model">sale.payment.link</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"/>
</group>
<group>
<field name="link" readonly="1" widget="CopyClipboardChar" attrs="{'invisible': [('link', '=', False)]}" options="{'string': 'Copy Link'}"/>
</group>
<footer>
<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)]}"/>
</footer>
</form>
</field>
</record>

<act_window name="Generate a Payment Link"
res_model="sale.payment.link"
src_model="sale.order"
view_mode="form"
target="new"
view_type="form"
view_id="sale_generate_payment_link_view_form"
id="action_sale_order_generate_link"
/>
</odoo>

0 comments on commit cfdc3c1

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