Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
3348 Vues

Hi,

After creating an invoice through XML-RPC, I cannot get its "access_token". The default value is false. When I visit that invoice in Odoo, I see access_token is generated.

Can anyone help me to generate invoice access_token through XML-RPC?

It is a hard time for me when I have to visit invoices manually before sending them to customers.

Thank you so much.


Avatar
Ignorer
Meilleure réponse
# -*- 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.


Avatar
Ignorer