0
votes

When i want to add product_id price_total or something from WorkOrederLine class i get error ParseError: "Error while validating constraint

Field product_id does not exist

Error context: View Work Order

it works fine if i leave just field name.

The thing is that it's related models so i'm kinda confused. even if i check it in developers mode pointing over with mouse it saying

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>
1

1 Answers

1
votes

In your xml you close your workorder_line tag this is wrong.

<field name="workorder_line" nolable="1"/>
    <tree>
        <field name="name"/>
        <field name="product_id"/>
     </tree>

should be

<field name="workorder_line" nolable="1">
    <tree>
        <field name="name"/>
        <field name="product_id"/>
     </tree>
</field>