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>
Related
I have two websites in Odoo.
Site 1: www.A.com
Site 2: www.B.fr
I created a module but I would like it to be visible only in website 2. But when I install it, it appears in both sites. I must then change the views manually in Odoo so that my view is visible on site 2.
I tried to put "website_id: 'B' in manifest.py but it doesn't work.
Where should I report please? I searched but I can't find a solution ...
Thank you.
You can edit your view or template and test for the website id to add your content, for example:
<template id = "test" name="test" inherit_id="test.test_view" priority="16">
<t t-if="website.id == 1">
<!-- add or edit the content that you want-->
</t>
</template>
You can specify the value of website_id field when you define the view or set its value by inheriting an existing view.
You will need the external id of website2(website.website2) and the external id of an existing view in case you need to use inheritance.
Specify the value in the view definition:
<record id="MODEL_view_TYPE" model="ir.ui.view">
<field name="name">NAME</field>
<field name="model">MODEL</field>
<field name="website_id" ref="Website_External_Id"/>
<field name="arch" type="xml">
Inherit an existing view and specify the website_id field value:
<record id="VIEW_External_ID" model="ir.ui.view">
<field name="website_id" ref="Website_External_Id"/>
</record>
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>
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?
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>
I am developing a module in Odoo. I need to change the report of invoice to add some details.
I use xpath with position attribute and check if an affair is linked to hide the default table.
<template id="my_invoice" inherit_id="account.report_invoice_document">
<xpath expr="//div[#class='page']/table[#class='table table-condensed']" position="attributes">
<attribute t-if="o.affair_id" name="class">hidden</attribute>
</xpath>
</template>
This is not working. The default table is hidden in every invoices even if the invoice is not linked to an affair.
I do not understand because the condition works in my second template.
<template id="my_invoice2" inherit_id="account.report_invoice_document">
<xpath expr="//div[#class='page']/div[#class='row mt32 mb32']" position="after">
<t t-if="o.affair_id">
<!-- table with my additional detail -->
</t>
</xpath>
</template>
Sorry for my english. I am learning it.
try this one:
<attribute name="t-att-style">'display: none;' if o.affair_id else ''</attribute>
OR even this one also:
<attribute name="t-att-class">'hidden' if o.affair_id else ''</attribute>
it may help in your case.