Neo*_*oVe 1 python python-2.7 odoo odoo-8
我有这个方法:
@api.multi
def create_printy(self):
copy_record = self.env['stock.picking'] # now you call the method directly
for record in self:
order_lines = []
for rec in record.order_lines:
order_lines.append(
(0,0,
{
'product_id': rec.isbn.id,
'product_qty': rec.qty,
}
))
copy_record.create({
'origin': order.name,
'picking_type_id.id': 'outgoing',
'move_lines': order_lines,
'move_type': 'direct',
'priority': '1',
'company_id': record.company_id.id,
})
Run Code Online (Sandbox Code Playgroud)
这是一个按钮,应该stock.picking从我的模型中创建一个新的。
我已经尝试过,picking_type_id.id但它似乎不起作用,在标准插件中的每个示例上,你只是看到picking_type_id,我的模型中也没有任何定义,但我虽然我可以传递一种可用的类型,它是outgoing(我需要的)。
现在,它向我抛出了这个:
Integrity Error
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set
[object with reference: picking_type_id - picking.type.id]
Run Code Online (Sandbox Code Playgroud)
那么,我如何将它传递picking_type_id到stock.picking, 我应该在我的模型中定义这个字段,即使不需要?但它是stock.picking模型所必需的。
该字段picking_type_id在stock.picking模型中是强制性的,您没有在create方法中指定它,而是为 指定一个值picking_type_id.id,该值不是一个字段(并且 Odoo 不会让您知道这个事实)。您必须找到选股类型对象的 ID,并将其传递给该create方法。如果您需要传出类型,请使用此代码查找选择类型。如果您有多个仓库,则搜索方法必然会返回多条记录,这就是我获取第一个的原因。但是如果你想要另一个,你将不得不向方法传递更多的参数以search更简洁。所以试试这个:
@api.multi
def create_printy(self):
copy_record = self.env['stock.picking'] # now you call the method directly
for record in self:
order_lines = []
for rec in record.order_lines:
order_lines.append(
(0,0,
{
'product_id': rec.isbn.id,
'product_qty': rec.qty,
}
))
sp_types = self.env['stock.picking.type'].search([
('code', '=', 'outgoing')
])
if len(sp_types) > 0:
copy_record.create({
'origin': order.name,
'picking_type_id': sp_types[0].id,
'move_lines': order_lines,
'move_type': 'direct',
'priority': '1',
'company_id': record.company_id.id,
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
649 次 |
| 最近记录: |