繁体   English   中英

错误字段`product_id`不存在

[英]Error Field `product_id` does not exist

当我想添加product_id price_total或WorkOrederLine类的内容时,出现错误ParseError:“验证约束时出错

字段product_id不存在

错误上下文:查看Work Order

如果我只留下字段名称,它会很好地工作。

问题是它是相关模型,所以我有点困惑。 即使我在开发人员模式下用鼠标指着它检查说

field.workorder_line object.wkf.workorder type.one2many.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>

在您的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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM