当我想在WorkOrederLine类中添加product_id price_total或者其他内容时,我得到错误ParseError:"验证约束时出错
字段product_id
不存在
错误上下文:
查看Work Order
如果我只留下字段名称,它可以正常工作。
问题在于它的相关模型,所以我有点困惑。 即使我在开发者模式中检查它,用鼠标指向它
field.workorder_line object.wkf.workorder type.one2many relation.wkf.workorder.line
class WorkOrderLine(models.Model):
_name = 'wkf.workorder.line'
_description = 'Work Order Line'
@api.depends('product_uom_qty', 'price_unit',)
def _compute_amount(self):
"""
Compute the amounts of the WO line.
"""
for line in self:
line.update({
'price_total': line.price_unit * line.product_uom_qty
})
workorder_id = fields.Many2one('wkf.workorder', string='WorkOrder Reference', required=True,
ondelete='cascade', index=True, copy=False)
name = fields.Text(string='Description', required=True)
sequence = fields.Integer(string='Sequence', default=10)
product_id = fields.Many2one('product.product', string='Product', domain=[('sale_ok', '=', True)],
change_default=True, ondelete='restrict', required=True)
product_uom_qty = fields.Float(string='Quantity', digits=dp.get_precision('Product Unit of Measure'), required=True,
default=1.0)
product_uom = fields.Many2one('product.uom', string='Unit of Measure', required=True)
price_unit = fields.Float('Unit Price', required=True, digits=dp.get_precision('Product Price'), default=0.0)
price_total = fields.Float(compute='_compute_amount', string='Total', readonly=True, store=True)
class WorkOrder(models.Model):
_name = 'wkf.workorder'
_description = 'Work Order'
name = fields.Char(string="Code", required=True, index=True, default=lambda self: ('New'), readonly=True)
color = fields.Integer(string="Color Index", required=False, )
workorder_line = fields.One2many('wkf.workorder.line', 'workorder_id', string='WorkOrder Lines', copy=True)
<record id="wkf_workorder_form" model="ir.ui.view">
<field name="name">Work Order</field>
<field name="model">wkf.workorder</field>
<field name="arch" type="xml">
<form string="Work Order">
<group>
<field name="name"/>
</group>
<notebook>
<page string="Workorder Lines">
<field name="workorder_line" nolable="1"/>
<tree>
<field name="name"/>
<field name="product_id"/>
</tree>
</page>
</notebook>
</form>
</field>
</record>
答案 0 :(得分:0)
在您的xml中,您关闭了workorder_line标记,这是错误的。
<field name="workorder_line" nolable="1"/>
<tree>
<field name="name"/>
<field name="product_id"/>
</tree>
应该是
<field name="workorder_line" nolable="1">
<tree>
<field name="name"/>
<field name="product_id"/>
</tree>
</field>