I'm trying to register a payment for an invoice that I created earlier via the API.
I posted the invoice as follows
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
models.execute_kw(db, uid, password, 'account.move', 'post', [[invoice_id]])
I want to register this payment and mark it as paid after it being posted. I'm trying to use a workflow similar to the one above like this
models.execute_kw(db, uid, password, 'account.payment', 'action_register_payment', [{"active_id":invoice_id}])
I've tried sending the required fields in the module as well . I don't get any errors but the invoice is still not being registered.
Anyone can help with this ? Thanks
The action_register_payment method will check if active_ids
is in context and if not it will return an empty string.
To pass the context you need to pass a dict just after the args list like they passed the fields
argument to the read method in the official XML-RPC documentation:
models.execute_kw(db, uid, password, 'account.payment', 'action_register_payment', [[]], {'context': {"active_ids": [invoice_id]}}
The method returns an action as a dictionary which will lead to a:
TypeError: cannot marshal <class \'odoo.tools.misc.frozendict\'>
You can use the payment register wizard to create the invoice payments, you have to create a new payment register record then call the create_payments method.
Example:
payment_register_id = models.execute_kw(db, uid, password, 'account.payment.register', 'create', [{'journal_id': bank_journal_id, 'payment_method_id': payment_method_id, 'invoice_ids': [(4, invoice_id)]}])
models.execute_kw(db, uid, password, 'account.payment.register', 'create_payments', [[payment_register_id]])