Home > OS >  how to change pages in notebook by a selection field in odoo14
how to change pages in notebook by a selection field in odoo14

Time:12-06

i have a selection field declared in the form view, and i want, whenever i change the selection field my pages should be changed. my selection field is:

    package_name = fields.Selection([
        ('labour', 'Labour Cost'),
        ('material', 'Material Cost'),
        ('subcontract', 'Subcontract Cost'),
        ('package', 'Work Package Cost'),
        ('others', 'Others')], string="Package Name", default="labour", required=True)

i have declared 4 pages in xml part each for one selection field. xml for the pages in notebook are given below:

<notebook>
    <page string="Labour Cost" name="labour_cost" attrs="{'invisible': [('package_name', 'not in', 'labour')]}">
        <field name="header_id" attrs="{'invisible': [('package_name', '!=', 'labour')]}">
            <tree string="Labour Cost Tree" editable="bottom">
                <field name="cost_header_id"/>
                <field name="description"/>
                <field name="header_cost"/>
            </tree>
        </field>
    </page>
    <page string="Material Cost" name="material_cost" attrs="{'invisible': [('package_name', '!=', 'material')]}">
        <field name="header_id" attrs="{'invisible': [('package_name', '!=', 'material')]}">
            <tree string="Material Cost Tree" editable="bottom">
                <field name="product_id"/>
                <field name="qty"/>
                <field name="unit_price"/>
                <field name="uom"/>
                <field name="subtotal"/>
            </tree>
        </field>
    </page>
</notebook>

currently there are 2 pages when i comment "a page from the notebook" in xml then only the field of the other "page of the notebook" is getting reflected in frontend otherwise if it reflects the same view in 2 of the pages reguardless what field i declare in the pages of other notebook.

can anyone please help me here.

CodePudding user response:

Can you check the attrs of the first page:

... attrs="{'invisible': [('package_name', 'not in', 'labour')]}">

It should be:

... attrs="{'invisible': [('package_name', '!=', 'labour')]}"

And you are defining more than one tree views of the field header_id , but unfortunately Odoo only pick the last definition to generate view. To fix this, you can try defining tree views separately for each page and then add context="{'tree_view_ref' : model.view_id'}" on field. For example:

<record model="ir.ui.view" id="labour_cost_tree">
    <field name="name">Model</field>
    <field name="model">model.name</field>
    <field name="arch" type="xml">
        <tree string="Labour Cost Tree" editable="bottom">
            <field name="cost_header_id"/>
            <field name="description"/>
            <field name="header_cost"/>
        </tree>
    </field>
</record>

Inside page:

<field name="header_id" attrs="{'invisible': [('package_name', '!=', 'labour')]}" context="{'tree_view_ref' : module.labour_cost_tree'}">

CodePudding user response:

@Randi Tran you are right. i was defining more than one tree views of the field header_id, Odoo only pick the last definition to generate view. to solve this issue i had to declare one2many field for each notebook page.

<notebook>
    <page string="Labour Cost" name="labour_cost" attrs="{'invisible': [('package_name', '!=', 'labour')]}">
        <field name="header_id">
            <tree string="Labour Cost Tree" editable="bottom">
                <field name="cost_header_id"/>
                <field name="description"/>
                <field name="header_cost"/>
            </tree>
        </field>
    </page>
    <page string="Material Cost" name="material_cost" attrs="{'invisible': [('package_name', '!=', 'material')]}">
        <field name="material_id">
            <tree string="Material Cost Tree" editable="bottom">
                <field name="product_id"/>
                <field name="qty"/>
                <field name="unit_price"/>
                <field name="uom"/>
                <field name="subtotal"/>
            </tree>
        </field>
    </page>
</notebook>
  • Related