Using Odoo 15 and python xmlrpc for API
here is my problem: I have a created payment for which I store the id. Then, when i create the invoice that corresponds, I want to be able to add this specific outstanding credit of the customer through API just like this "Ajouter" (Add) button does. ("crédits en circulation" is outstanding credits):
How would I do with python and xml-rpc tu simulate the use of this button for a specific payment (with its id)?
Note: For our sales workflow we have to create payments straight away and invoices later so I can't create the payment when creating the invoice
When you click on Add
button, Odoo will call the js_assign_outstanding_line function.
def js_assign_outstanding_line(self, line_id):
''' Called by the 'payment' widget to reconcile a suggested journal item to the present
invoice.
:param line_id: The id of the line to reconcile with the current invoice.
'''
self.ensure_one()
lines = self.env['account.move.line'].browse(line_id)
lines += self.line_ids.filtered(lambda line: line.account_id == lines[0].account_id and not line.reconciled)
return lines.reconcile()
The Add
button depends on the value of the computed invoice_outstanding_credits_debits_widget field. To reproduce the same logic using XML-RPC, you need to get the payment credit line id and call the js_assign_outstanding_line
function like following:
models.execute_kw(db, uid, password, 'account.move', 'js_assign_outstanding_line', [move_id, line_id])
It will add the payment and return the result of reconcile
function which will raise the following error (XML-RPC code):
TypeError: cannot marshal <class \'odoo.api.account.partial.reconcile\'> objects\n'>