2017-03-05 65 views
0

當我要添加從WorkOrederLine類的product_id price_total或東西我得到錯誤ParseError:在驗證約束錯誤域`product_id`不存在

「錯誤

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

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