Change the Position of field - Odoo - odoo

I am using Odoo 10 and I am trying to move the position of the mobile field. The below code works but the new mobile field does not have any data. Mobile number is missing. I remove that code and the mobile number comes back.
<xpath expr="//field[#name='mobile']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//field[#name='category_id']" position="after">
<field name="mobile" />
</xpath>

You cannot have same field twice in the view. You need to completely remove the field first and add it to another place after that. Your templates work if you change the first xpath to remove the field, not just hide it. This can be done like this
<xpath expr="//field[#name='mobile']" position="replace">
</xpath>
<xpath expr="//field[#name='category_id']" position="after">
<field name="mobile" />
</xpath>

Veikko`s answer is universal for all versions of Odoo but requires to rewrite full dom structure in new place
For Odoo starting version 12.0 best for move field and other is (described here):
<xpath expr="//field[#name='category_id']" position="after">
<xpath expr="//field[#name='mobile']" position="move"/>
</xpath>

Related

Odoo List view: set column to be always visible

I'm working with Odoo 14 and would like to know if there is an option in XML template to suppress optional="show"/"hide" setting inherited from parent template. For example I have following code in parent template:
<field name="code" optional="show" readonly="1"/>
On a child template I would like to do something like this:
<xpath expr="//field[#name='code']" position="attributes">
<attribute name="optional">Always on</attribute>
</xpath>
to set the code field to be always on, without option to hide or show the column. Is there any option to do so?
You can inherit that field's attribute and remove it.
<xpath expr="//field[#name='code']" position="attributes">
<attribute name="optional"></attribute>
</xpath>
Solution is in fact easy, just to replace the inherited element with newly defined - without optional attribute. This rewrites all attribute settings.
<!-- In child template: -->
<xpath expr="//field[#name='code']" position="replace">
<field name="code"/>
</xpath>

Inheriting a model and adding new field to the model odoo 12

I'm trying to add a new field in the res.users model near the field named partned_id in that model.But im not getting the field in the view and i dont understand why.
I have tried below code:
*.py
class Users(models.Model):
_inherit = "res.users"
reporting_to = fields.Many2one('res.users',string="Reporting To")
*.xml
<record id="view_users_form_inherit" model="ir.ui.view">
<field name="name">res.users.form.inherit</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='partner_id']" position="after">
<field name="reporting_to"/>
</xpath>
</field>
</record>
Assuming you have registered your XML in the manifest file.
The partner_id field exists many times on the base view. It may find the wrong one. Use a more exact xpath.
There are two partner_id field tags inside view_users_form, To show the reporting_to field after the related partner field, trigger the partner field which is inside a group tag:
<xpath expr="//group/field[#name='partner_id']" position="after">
<field name="reporting_to"/>
</xpath>

Issue when Invisible Sale Order line Description Field

Currently, I'm working on odoo version 12.0.
I'm facing the issue, When I invisible sale order line Description field from Tree view at that time it also invisible the section text & Note Text.
Code for invisible sale order line Description field:
<xpath expr="//page[#name='order_lines']//tree/field[#name='name']" position="attributes">
<attribute name="invisible">1</attribute> ​
​</xpath>
Can anyone help me to resolve this issue?
Thanks in advance.
Technically Description, section text and note text is same field='name' in sale.order.line at client-side UI tweak based on field display_type
you should try attrs invisible based on display_type instead of invisible=1
ref:
https://github.com/odoo/odoo/blob/12.0/addons/sale/models/sale.py#L1223
Please use the below code
<record id="view_order_form_inherit_custom" model="ir.ui.view">
<field name="name">sale.order.form.custom</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='order_line']/tree/field[#name='name']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</field>
</record>

Invisible two buttons using xpath in Odoo 10

In sale.order form view, there are two buttons Send by Email. One for draft state and another for sent, sale. I need to hide both buttons. I tried below code:
<xpath expr="//button[#name='action_quotation_send']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
The result is: The button in draft state become invisible, another button is still visible.
How can I hide that button too?
Use below code how it is, to hide both buttons by replacing with nothing.
<xpath expr="//button[#name='action_quotation_send']" position="replace"/>
<xpath expr="//button[#name='action_quotation_send']" position="replace"/>
I know it looks weird cause its exactly the same code twice but it worked for me.
We have to set attribute for both buttons.
Try with following code:
<xpath expr="//button[#name='action_quotation_send' and #states='sent']" position="attributes">
<attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
<attribute name="invisible">1</attribute>
</xpath
<xpath expr="//button[#name='action_quotation_send' and #states='draft']" position="attributes">
<attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
<attribute name="invisible">1</attribute>
</xpath>
I know it's late, but might help someone in future.
<xpath expr="(//button[#name='action_quotation_send'])[1]" position="attributes">
...
</xpath>
<xpath expr="(//button[#name='action_quotation_send'])[2]" position="attributes">
...
</xpath>
Refer How can you identify multiple elements with the same name in XPath?

Hide group in odoo 9

How with xpath expr replace (hide) group Configuration in project managment module in tabs settings?
<group string="Configuration" groups="base.group_no_one">
<field name="sequence" groups="base.group_no_one"/>
</group>
I'm try with below code but get error:
<xpath expr="//group[#string='Configuration']" position="replace">
</xpath>
I guess the error you are getting is a ParseError, because you are using the string attribute as a selector inside your XPath expression, which is not allowed since Odoo v9.0.
Instead, you might try to find the sequence field and the select the parent:
<xpath expr="//field[#name='sequence']/.." position="replace">
</xpath>
However, replacing the whole element might not be the best solution, because other modules might use the group or the sequence field inside an inherited view, which would cause an error. A better solution would be to hide the group using the invisible attribute. The full record could look something like this:
<record id="edit_project_inherit" model="ir.ui.view">
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='sequence']/.." position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</field>
</record>