Skip to content
Permalink
Browse files

[WIP] improvements

  • Loading branch information...
sza-odoo committed Mar 25, 2019
1 parent cd21547 commit bb4f6550ea34ea34c0e65c9e821e5faec3584ce4
@@ -15,23 +15,25 @@ def default_get(self, fields):
active_id = self._context.get('active_id')
active_model = self._context.get('active_model')
record = self.env[active_model].browse(active_id)
amount_total = sum(record.invoice_ids.mapped('amount_total'))
res['order_id'] = active_id
res['amount'] = record.amount_total
res['amount'] = record.amount_total - amount_total if amount_total else record.amount_total
return res

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


@api.multi
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:
if self.order_id.amount_total >= self.amount > 0:
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 must be equal or less than %s and positive value") % (self.order_id.amount_total))
raise UserError(_("Please set an amount smaller than %s. Please set a positive amount") % (self.order_id.amount_total))
return {
'name': _('Payment Link'),
'type': 'ir.actions.act_window',
@@ -6,15 +6,16 @@
<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="order_id" widget="selection"/>
<field name="amount"/>
<field name="description"/>
</group>
<group>
<field name="link" readonly="1" widget="CopyClipboardChar" attrs="{'invisible': [('link', '=', False)]}" options="{'string': 'Copy Link'}"/>
</group>
<footer>
<button string="Create Payment Link" name="generate_payment_link" type="object" attrs="{'invisible': [('link','!=', False)]}" class="btn-primary"/>
<button string="Close" special="cancel" attrs="{'invisible': [('link','!=', False)]}"/>
<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>

0 comments on commit bb4f655

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