Search code examples
pythonxmlodoo

making sale_line_id field invisible


I'm working on customizing Odoo and have encountered an issue with the sale_line_id field.

I'm inheriting the project.task model in my custom module (wsl_available_drivers). In view, I need to make the sale_line_id field invisible.

<record id="view_task_form2" model="ir.ui.view">
    <field name="name">Project.task.view.form.inherit.available.drivers</field>
    <field name="model">project.task</field>
    <field name="inherit_id" ref="project.view_task_form2"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='user_ids']" position="before">
            <field name="first_user" invisible="1"/>
            <field name="Journey_start_date"/>
            <field name="recurring_task" invisible="1"/>
        </xpath>
        <xpath expr="//field[@name='sale_line_id']" position="attribute">
           <attribute name="invisible">1</attribute>
        </xpath>

    </field>
</record>

When attempting to hide sale_line_id using XPath, I receive an error stating that the field does not exist in the project.task model.

Upon further investigation: I found that sale_line_id is related to the Task model, with relatedmodel pointing to sale.order.line.

However, I cannot locate the sale_line_id field within the sale.order.line model or its related modules.


Solution

  • The sale_project module adds two sale_line_id fields and the visibility of the field depends on the group to which the user belongs, the second field has an additional invisible attribute

    The XPath expression will match the first node it finds. If you need to hide the two fields, add another XPath to target the second field

    Example:

    <record id="view_task_form_inherit" model="ir.ui.view">
        <field name="name">project.task.form.inherit</field>
        <field name="model">project.task</field>
        <field name="inherit_id" ref="sale_project.view_sale_project_inherit_form"/>
        <field name="arch" type="xml">
    
            <xpath expr="//field[@name='sale_line_id']" position="attributes">
                <attribute name="invisible">1</attribute>
            </xpath>
    
            <xpath expr="//field[@name='sale_line_id'][2]" position="attributes">
                <attribute name="invisible">1</attribute>
            </xpath>
            
        </field>
    </record>
    

    For more details check the View resolution and Inheritance specs documentation sections