I am working for Odoo project of my company.
An engineer before me (now he resigned) made a Go script that launches periodically to create invoices from sales orders. This Go script works fine.
Now, we realize that creating invoice can be done through Odoo's Automated/Scheduled Actions as well.
My current task is to translate his Go script into Odoo's Automated Action.
But, I have a problem....
In his Go script there are codes like this:
param := []interface{}{
c.cred.Db,
c.uid,
c.cred.Password,
"sale.advance.payment.inv",
"create_invoices",
[]int{
paymentID,
},
map[string]interface{}{
"context": map[string]interface{}{
"active_id": salesOrderID,
"active_ids": []int{salesOrderID},
"active_model": "sales.order",
},
},
}
The codes are basically meant to work from model "sale.advance.payment.inv"
and then call the method create_invoices
.
With the first parameter is the payment object. With the second parameter is a JSON/Python Dict of something exactly like this:
{
'context':
{
'active_id' : so['id'],
'active_ids' : [so['id']],
'active_model': 'sales.order'
}
}
My Automated Action is like this:
paymentInAdvModel = env["sale.advance.payment.inv"]
paymentInAdv = paymentInAdvModel.create(
{
'advance_payment_method': 'delivered',
'amount': 0,
}
)
paymentInAdv.create_invoices(
[paymentInAdv],
{
'context':
{
'active_id' : so['id'],
'active_ids' : [so['id']],
'active_model': 'sales.order'
}
}
)
There is this error for Automated Action:
ValueError: : "create_invoices() takes 1 positional argument but 3 were given" while evaluating
Things to notice:
"create_invoices"
need only one parameter. I supplied two parameters, but the error said that I have three parameters inputted. I assume the other parameter is a Python's self
.create_invoices
and it only takes one parameter.Anyone have solutions hence, I can use create_invoices()
with the same parameter as the Go script?
You don't need to pass list when you call create_invoice method and also you need to pass the context using with_context() method.
Try following code:
ctx = {
'active_id' : so['id'],
'active_ids' : [so['id']],
'active_model': 'sales.order'
}
paymentInAdv.with_context(ctx).create_invoices()
Hope this will help you.