This question has been flagged
3641 Views

i made a new object called cmms.piece it has one2many fields called piece_line. It contains 2 fields (product_id, product_qty). I want to insert that line to cmms.intervention But it shows error Uncaught TypeError: Type is not a constructor odoo. My code shown below:

piece_defectueuse.py

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>
Avatar
Discard

Why are you adding the widget=one2many on a field that is already a one2many though?

Author

I tried everything to make it works. Just i found some example of code use that widget so i said maybe it the reason of the problem