Skip to Content
Menu
This question has been flagged
3 Replies
3784 Views

Hi, 

I'm trying to solve this problem without succes. 

I'm trying to create a custom wiev form that only shows name and category in the form view of a new module.

Here the classes:


from osv import osv, fields


class product_product2(osv.osv):

    _name = 'product.product2'

    _inherit = 'product.product'

    _columns = {

        'melody_ids': fields.many2many('vr.melody','product_vr_melody_rel','product_id','melody_id','Melodies'),

        

    }

product_product2()


class vr_melody (osv.osv):

    _name = 'vr.melody'

    _columns = {

        'name': fields.char('Melody',size=30,required=True),

        'author': fields.char('Melodist',size=30,required=True),

        'year': fields.char('Year',size=30,required=True),

        'product_id':fields.many2many('product.product2','product_vr_melody_rel','melody_id','product_id','Products'),

        

        

    }

vr_melody()


And here the views:

<?xml version="1.0"?>

<openerp>

<data>

</record>

<record model="ir.ui.view" id="view_vr_melody_tree">

        <field name="name">Video Rental Melodies Tree</field>

        <field name="model">vr.melody</field>

        <field name="type">tree</field>

        <field name="arch" type="xml">

            <tree string="Melodies Tree">

                <field name="name" select="1"/>

<field name="year" select="1"/>

<field name="author"/>

            </tree>

        </field>

    </record>

<record model="ir.ui.view" id="view_vr_melody_form">

        <field name="name">Video Rental Melodies Form</field>

        <field name="model">vr.melody</field>

        <field name="type">form</field>

        <field name="arch" type="xml">

    <form string="Melodies Form">

                <field name="name"/>

                <field name="year"/>

<field name="author"/>

<field name="product_id"/>

            </form>

        </field>

    </record>

  

<record model="ir.actions.act_window" id="action_vr_melodies">

        <field name="name">Melodies</field>

        <field name="res_model">vr.melody</field>

        <field name="view_type">form</field>

        <field name="view_mode">tree,form</field>

    </record>

<menuitem name="Melodies" id="menu_vr_melodies" action="action_vr_melodies" parent="video_rental_GonzalezLozano.menu_vr_configuration"/>

</data>

</openerp>

Now product_id doesn't show any data.  If I delete _name = 'product.product2' and name the class like product.product, then product_id shows all the same data that are showed on product view form. 

I need that my product view form shows only name and category.

Any help?

Thank you,





Avatar
Discard
Best Answer

You can define a new form view for product.product and add that form view id in product_id field.

eg:

Product new form view:--

<record model="ir.ui.view" id="view_product_form">

        <field name="name">Product Form</field>

        <field name="model">product.product</field>

        <field name="type">form</field>

        <field name="arch" type="xml">

    <form string="Melodies Form">

                <field name="name"/>

                <field name="category"/>

</form>
</field>
</record>


Change in your vr melody form:--


<record model="ir.ui.view" id="view_vr_melody_form">

        <field name="name">Video Rental Melodies Form</field>

        <field name="model">vr.melody</field>

        <field name="type">form</field>

        <field name="arch" type="xml">

    <form string="Melodies Form">

                <field name="name"/>

                <field name="year"/>

<field name="author"/>

<field name="product_id" context="{'form_view_ref': 'view_product_form'}"/>

</form>

        </field>

    </record>

Avatar
Discard
Author Best Answer

Hi, 

Thank you so much.

Is working!!

Avatar
Discard

Please accept the answer if you found its working.

Related Posts Replies Views Activity
3
Aug 22
10495
2
Feb 19
2675
2
Jun 16
4991
2
Nov 23
1540
3
Dec 22
5884