I am trying to create a refund credit note via the API in odoo 11. The call I make is:
create account.invoice.refund {
"kwargs": {
"context": {
"uid": 9,
"tz": false,
"lang": "en_US",
"type": "out_invoice",
"journal_type": "sale",
"active_model": "account.invoice",
"active_id": 145,
"active_ids": [
145
],
"search_disable_custom_filters": true,
"params": {
"action": 198
}
}
},
"model": "account.invoice.refund",
"method": "create",
"args": [
{
"filter_refund": "cancel",
"description": "Refund after cancellation",
"date_invoice": "2018-11-09",
"date": false
}
]
}
This is a copy of the call that is made by the odoo web frontend in my browser:
{
"jsonrpc":"2.0",
"method":"call",
"params":{
"args":[
{
"filter_refund":"cancel",
"description":"cancelation",
"date_invoice":"2018-11-09",
"date":false
}
],
"model":"account.invoice.refund",
"method":"create",
"kwargs":{
"context":{
"uid":9,
"tz":false,
"lang":"en_US",
"type":"out_invoice",
"journal_type":"sale",
"params":{
"action":198
},
"active_model":"account.invoice",
"active_id":145,
"active_ids":[
145
],
"search_disable_custom_filters":true
}
}
},
"id":318670720
}
In both cases an identical record is created in table account.invoice.refund of type 'cancel'.
However, only when the web frontend makes the call, a new invoice is created of type 'out_refund' and the original invoice is put in paid state. When I make the call via my backend, no out_refund invoice is created.
My suspicion is that setting the context of the active model ( account.invoice ) does not work when making the call from my backend. In the worst case, I will try updating the original invoice and creating the out_refund invoice manually, but it would be much nicer of course, if it happened automatically like in the case when the call is made by the odoo web frontend.
I hope somebody knows why the behaviour is different when the call is made from the backend?