从另一个模型将 move_lines 传递到 stock.picking - Odoo v8
Pass move_lines into stock.picking from another model - Odoo v8
我有这个方法:
@api.multi
def create_printy(self):
copy_record = self.env['stock.picking']
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': record.name,
'picking_type_id': sp_types[0].id,
'move_lines': order_lines,
'move_type': 'direct',
'priority': '1',
'company_id': record.company_id.id,
})
我正在尝试从另一个模型创建 stock.picking
。
但是,使用这种方法,我遇到了 move_lines
的问题,它在 stock.picking
上与 stock.move
有关。
现在,它抛给我这个:
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: Product Unit of Measure - product.uom]
我知道我的 order_lines
字段中没有一些 stock.move
必填字段。
所以,我的问题是,我如何传递模型所需的 product.uom
或 date_expected
?
是否有一些与我的示例中 picking_type_id
类似的方法。对于 One2many
字段?
您可以看看当您不在界面中填写这些字段时会发生什么(并查看它们默认得到的内容)。例如,在 stock.move
中,Odoo 从 product_id
字段中获取 product_uom
(通过 onchange
方法)。 date_expected
默认填写当前日期。所以:
@api.multi
def create_printy(self):
copy_record = self.env['stock.picking']
for record in self:
order_lines = []
for rec in record.order_lines:
order_lines.append(
(0,0,
{
'product_id': rec.isbn.id,
'product_uom': rec.isbn.uom_id.id,
'date_expected': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
'product_qty': rec.qty,
}
))
sp_types = self.env['stock.picking.type'].search([
('code', '=', 'outgoing')
])
if len(sp_types) > 0:
copy_record.create({
'origin': record.name,
'picking_type_id': sp_types[0].id,
'move_lines': order_lines,
'move_type': 'direct',
'priority': '1',
'company_id': record.company_id.id,
})
对于 date_expected
,您必须在 .py 文件中(从 类 中)导入以下内容:
import time
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
我有这个方法:
@api.multi
def create_printy(self):
copy_record = self.env['stock.picking']
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': record.name,
'picking_type_id': sp_types[0].id,
'move_lines': order_lines,
'move_type': 'direct',
'priority': '1',
'company_id': record.company_id.id,
})
我正在尝试从另一个模型创建 stock.picking
。
但是,使用这种方法,我遇到了 move_lines
的问题,它在 stock.picking
上与 stock.move
有关。
现在,它抛给我这个:
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: Product Unit of Measure - product.uom]
我知道我的 order_lines
字段中没有一些 stock.move
必填字段。
所以,我的问题是,我如何传递模型所需的 product.uom
或 date_expected
?
是否有一些与我的示例中 picking_type_id
类似的方法。对于 One2many
字段?
您可以看看当您不在界面中填写这些字段时会发生什么(并查看它们默认得到的内容)。例如,在 stock.move
中,Odoo 从 product_id
字段中获取 product_uom
(通过 onchange
方法)。 date_expected
默认填写当前日期。所以:
@api.multi
def create_printy(self):
copy_record = self.env['stock.picking']
for record in self:
order_lines = []
for rec in record.order_lines:
order_lines.append(
(0,0,
{
'product_id': rec.isbn.id,
'product_uom': rec.isbn.uom_id.id,
'date_expected': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
'product_qty': rec.qty,
}
))
sp_types = self.env['stock.picking.type'].search([
('code', '=', 'outgoing')
])
if len(sp_types) > 0:
copy_record.create({
'origin': record.name,
'picking_type_id': sp_types[0].id,
'move_lines': order_lines,
'move_type': 'direct',
'priority': '1',
'company_id': record.company_id.id,
})
对于 date_expected
,您必须在 .py 文件中(从 类 中)导入以下内容:
import time
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT