我在我公司的Odoo项目工作。
我之前的一位工程师(现在他辞职了)制作了一个Go脚本,定期发布,从销售订单中创建发票。这个围棋剧本很好用。
现在,我们意识到创建发票也可以通过Odoo的自动/计划操作来完成。
我目前的任务是将他的Go脚本转换成Odoo的自动操作。
但是我有个问题..。
在他的Go脚本中有这样的代码:
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",
},
},
}代码基本上是从模型"sale.advance.payment.inv"中工作,然后调用方法create_invoices。
第一个参数是支付对象。第二个参数是一个JSON/Python,其内容如下所示:
{
'context':
{
'active_id' : so['id'],
'active_ids' : [so['id']],
'active_model': 'sales.order'
}
}我的自动行动是这样的:
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'
}
}
)自动操作有以下错误:
ValueError::"create_invoices()采用一个位置参数,但在计算时给出了3个位置参数“
要注意的事情:
"create_invoices"方法只需一个参数即可。我提供了两个参数,但是错误说我输入了三个参数。我假设另一个参数是Python的self。create_invoices的函数,并且只接受一个参数。
任何人都有解决方案,因此,我可以使用与Go脚本具有相同参数的create_invoices()吗?
发布于 2018-11-03 10:21:03
调用create_invoice方法时不需要传递列表,也不需要使用with_context()方法传递上下文。
尝试使用以下代码:
ctx = {
'active_id' : so['id'],
'active_ids' : [so['id']],
'active_model': 'sales.order'
}
paymentInAdv.with_context(ctx).create_invoices()希望这能帮到你。
https://stackoverflow.com/questions/53129616
复制相似问题