I try to make a page tab in a view dynamicly visible based on the value of a field of the model. A field that is availble on the screen.
I need to change this is an inherited view
I tried:
<xpath expr="//page[#string='Functions']" position="attributes">
<attribute name="invisible">[('org_type_id','!=',0)]</attribute>
</xpath>
But now the page tab function is always hidden. even for the org_type_id that are 0.
Is it not possible to use xpath to add a dynamic invisible attritbute?
You are totally going on wrong way to do that job.
Just you can do with the the following way to do your job
some thing like this.
<xpath expr="//page[#string='Functions']" position="attributes">
<attribute name="attrs">{'invisible':[('org_type_id','!=',0)]}</attribute>
I hope this should helpful for you :)
You should also try this,
<page string="Functions" position="attributes">
<attribute name="attrs">{'invisible':[('org_type_id','!=',0)]}</attribute>
</page>
Related
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>
I need to change a field name in Odoo 11 installed on Windows.
In the customer credit notes field name (Taxes), I need to change that to (Pat).
How can I change it? Is it possible to change in XML through overriding and is it the correct way?
Yes you can do this through the xml using either one of below method.
<xpath expr="//field[#name='your_field_name']" position="attributes">
<attribute name="string">Pat</attribute>
</xpath>
OR
<field name="your_field_name" position="attributes">
<attribute name="string">Pat</attribute>
</field>
I hope it will help you.
You can do in XML if you want to do it only in that view. If you want to do it for all views, add string option in your Python code:
tax_ids = fields.Many2many('taxes.taxes',string = 'Pat' )
So in your dB and code references it will be called tax_ids but the user will see 'Pat'
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?
I have one field which i want to hide when specific journal selected.
<field name="any_field" attrs="{'invisible':[('journal_id','=',10])]}"/>
And For that above code is working fine.
I sure it is not a way to check condition.So, i tried this way.
<field name="any_field" attrs="{'invisible':[('journal_id','=',ref('my_module.account_journal_10'))]}"/>
It's working then i tried by using the static field on the journal eg. code.
<field name="any_field" attrs="{'invisible':[('journal_id.code','=','CARD')]}"/>
But still not working and getting error from view.
I am thinking if i can return the attrs from .py like i do for domain.
eg.
return {'domain':
{
'any_field':[('journal_id','=',self.env.ref('my_module.account_journal_10').id)]
}
}
Can anybody help me in this?
Thank you.
As far as i know these attrs domains/filters are client-side so you can't use something like journal_id.code or partner_id.customer, because the client doesn't know about such data.
A possible workaround is to define a related field on the model you're trying to do this. Let's assume the model is my.model and already has this Many2one field journal_id:
journal_code = fields.Char(string="Journal Code", related="journal_id.code")
Now you need to extend the view of my.model:
<field name="journal_code" invisible="1" />
<field name="any_field" attrs="{'invisible':[('journal_code','=','CARD')]}"/>
The partner_id has a context
{'show_address': 1}
Which I thought made the address show inline, but setting the context doesn't seem to accomplish the same thing on partner_shipping_id
<field name="partner_shipping_id" position="attributes">
<attribute name="context">{'show_address':1,'default_type':'delivery'}</attribute>
</field>
What am I missing?
Seems like I also need to make it always reload as the address is pulled in dynamically.
<field name="partner_shipping_id" position="attributes">
<attribute name="context">{'show_address':1,'default_type':'delivery'}</attribute>
<attribute name="options">{"always_reload": True}</attribute>
</field>
Yes you are right you missed
always_reload
Since the web client has already sent the record with a value it will not call name_get method. so the always_reload option in Many2one field forces to call name_get method explicitly