我创建了一个名为 cmms.piece 的新对象,它有一个名为 piece_line 的许多字段。它包含2个字段(product_id,product_qty)。我想将该行插入 cmms.intervention ,但它显示错误 Uncaught TypeError:Type不是构造函数odoo 。我的代码如下所示:
class Piece_defectueuse(osv.osv):
_name = "cmms.piece"
_columns = {
'product_id': fields.many2one('product.product', 'Product',required=True),
'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'),
required=True),
'intervention_id':fields.many2one('cmms.intervention','Demande d intervention'),}
cmms_intervention.py
class cmms_intervention(osv.osv):
_name = "cmms.intervention"
_columns = {
'piece_line': fields.one2many('cmms.piece','intervention_id', 'Piéces de rechange défectueuse'),
'product_id': fields.many2one('product.product','Piéces de rechange', required=True),
'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'),}
cmms_intervention.xml
<record id="view_intervention_form" model="ir.ui.view">
<field name="name">cmms.intervention.form</field>
<field name="model">cmms.intervention</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Intervention request" version="7.0">
<header>
<button name="action_broadcast" type="object" string="Déffuser mail" icon="STOCK_REDO"/>
<button name="action_done" states="draft" string="Valider" type="object" icon="gtk-apply"/>
<button name="action_cancel" states="done," string="Annuler" type="object" icon="gtk-cancel"/>
<button name="action_draft" states="cancel" string="Remettre en brouillon" type="object" icon="terp-stock_effects-object-colorize"/>
<field name="state" widget="statusbar" />
</header>
<sheet>
<group>
<group>
<field name="name" select="1" />
<field name="user_id" select="1" colspan="1" />
<field name="user2_id" />
<field name="priority" />
<field name="state_machine" />
<field name="product_id"/>
</group>
<group>
<field name="type" select="1" colspan="1" />
<field name="equipment_id" select="1" colspan="1" />
<field name="date_inter" />
<field name="date_end" />
</group>
</group>
<separator colspan="4" string="Piéce défectueuse" name="piece_def"/>
<field name="piece_line" widget="one2many">
<tree string="Piéces de rechange" editable="bottom">
<filed name="product_id" />
<field name="product_name"/>
<field name="product_qty"/>
</tree>
</field>
<newline />
<notebook colspan="1">
<page string="Motif d'intervention">
<field name="motif" />
</page>
<page string="Observation">
<field name="observation" />
</page>
</notebook>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
</field>
</record>