Search code examples
odooopenerp-6

OpenERP 6.1 multiple views with different fields


I would like to create different 'kinds' of purchase order forms in OpenERP with different fields in each. Because of the inheritance model, I am assuming I can't inherit multiple children with disjoint fields. So I decided to create a superset child that had all the fields from all types of PO.

I then created different views, containing different fields from the inherited model.

But each of the views shows the same superset.

Please advise if I am doing this the right way or is there no other way but fields_view_get(). Thanks

Code:

class purchase_order_hash(osv.osv):
_name = 'purchase.order'
_inherit = 'purchase.order'
_columns={
            'quality_code': fields....,
            'rice_quality': fields....,
            'packing_code': fields....,
            'packing_type': fields....,
            'late_payment': fields.float('Late Payment'),
            'num_bags': fields.integer('Number of Bags'),
            'unit_kg': fields.integer('Unit kg'),
            'rate_': fields.float('Rate', digits=(16,2), help="Rate"),
            'penalty_moisture': fields.float('Moisture Penalty', digits=(16,2), help="Percentage"),
            'penalty_broken': fields.float('Broken Penalty', digits=(16,2), help="Percentage"),
            'num_trucks': fields.integer('Number of Trucks'),
    'test1': fields.integer('Test 1')
          }
purchase_order_hash()  

(views xml:)

        <record id="purchase_order_hash_form" model="ir.ui.view">
                    <field name="name">purchase_order_hash_form</field>
                    <field name="model">purchase.order</field>
        <field name="priority" eval="1" />
                    <field name="type">form</field>
                    <field name="inherit_id" ref="purchase.purchase_order_form" />
                    <field name="arch" type="xml">
            <field name="origin" select="2" position="after">
                <field name="quality_code"/>
                <field name="rice_quality"/>
                <field name="packing_code"/>
                <field name="packing_type"/>
                <field name="late_payment"/>
                <field name="num_bags"/>
                <field name="unit_kg"/>
                <field name="rate_"/>
                <field name="penalty_moisture"/>
                <field name="penalty_broken"/>
                <field name="num_trucks"/>
            </field>
        </field>
    </record>

    <record id="purchase_order_hash_form_test" model="ir.ui.view">
        <field name="name">purchase_order_hash_form_test</field>
        <field name="model">purchase.order</field>
        <field name="priority" eval="2" />
        <field name="type">form</field>
        <field name="inherit_id" ref="purchase.purchase_order_form" />
        <field name="arch" type="xml">
            <field name="origin" select="2" position="after">
                <field name="test1"/>
            </field>
            <field name="num_trucks" position="replace"/>
        </field>
    </record>

    <record model="ir.actions.act_window" id="action_PO_hash">
        <field name="name">action_PO_hash</field>
        <field name="res_model">purchase.order</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="purchase_order_hash_form" />
    </record>

    <record model="ir.actions.act_window" id="action_PO_hash_test">
        <field name="name">action_PO_hash_test</field>
        <field name="res_model">purchase.order</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="purchase_order_hash_form_test" />
    </record>

    <menuitem id="menu_PO_hash" name="menu_PO_hash" action="action_PO_hash" parent="purchase.menu_procurement_management"/>
    <menuitem id="menu_PO_hash_test" name="menu_PO_hash_test" action="action_PO_hash_test" parent="purchase.menu_procurement_management"/>

[Update Oct 16, 2012: view.xml - final working code:]

    <record model="ir.actions.act_window" id="action_PO_hash">
        <field name="name">action_PO_hash</field>
        <field name="res_model">purchase.order</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
    </record>

    <record model="ir.actions.act_window" id="action_PO_hash_test">
        <field name="name">action_PO_hash_test</field>
        <field name="res_model">purchase.order</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
    </record>

    <record model="ir.actions.act_window.view" id="action_PO_hash_2">
        <field name="sequence" eval="1"/>
        <field name="view_mode">form</field>
        <field name="view_id" ref="purchase_order_hash_form"/>
        <field name="act_window_id" ref="action_PO_hash"/>
    </record>

    <record model="ir.actions.act_window.view" id="action_PO_hash_test_2">
        <field name="sequence" eval="1"/>
        <field name="view_mode">form</field>
        <field name="view_id" ref="purchase_order_hash_form_test"/>
        <field name="act_window_id" ref="action_PO_hash_test"/>
    </record>

    <menuitem id="menu_PO_hash" name="menu_PO_hash" action="action_PO_hash" parent="purchase.menu_procurement_management"/>
    <menuitem id="menu_PO_hash_test" name="menu_PO_hash_test" action="action_PO_hash_test" parent="purchase.menu_procurement_management"/>

Solution

  • If you want to get different form for each action, then you have to create different forms without inheriting the view. Then for each form and tree view you newly create, please specify the window action. For example:

    <record model="ir.actions.act_window.view" id="a_unique_name_as_id">
                <field name="sequence" eval="2"/>
                <field name="view_mode">form</field>
                <field name="view_id" ref="your_view_ref_id"/><!--use ref="purchase_order_hash_form_test"-->
                <field name="act_window_id" ref="your_action_reference_id"/><!--use ref='action_PO_hash_test'-->
            </record>