# -*- coding: utf-8 -*-
from werkzeug import urls
from odoo.addons.payment import utils as payment_utils
from odoo import models
class Invoice(models.Model):
_inherit = 'account.move'
def get_payment_link(self):
if self.amount_residual <= 0:
return''
base_url = self.get_base_url()
partner_id = record.partner_id.id
currency_id = record.currency_id.id
token_str = '|'.join(str(val) for val in [partner_id, record.amount_residual, currency_id])
secret = self.env['ir.config_parameter'].sudo().get_param('database.secret')
message = repr(('generate_access_token', token_str))
access_token = hmac_lib.new(
secret.encode(),
message.encode(),
hashlib.sha256,
).hexdigest()
url_params = {
'reference': urls.url_quote(self.name),
'amount': self.amount_residual,
'currency_id': self.currency_id.id,
'partner_id': self.partner_id.id,
'company_id': self.company_id.id,
'access_token': access_token,
}
return f'{base_url}/payment/pay?{urls.url_encode(url_params)}'
I was trying to do this through a scheduled action and I ended up adding the above function to the invoice model in my customization module.