I've added a new boolean field(with default False) to the sale_order and added a button to set it as True in the quotation form.
<button name="action_confirm" position="before">
<field name="boolean_field" invisible="1"/>
<button name="set_boolean_field" string="Boolean Field" type="object"
attrs="{'invisible': ['|',('boolean_field', '=', True), ('state','in',('sale','confirm'))]}"/>
</button>
Now, I need to hide the "Confirm Sale" button, when the above boolean field is False, in the quotation form.
There are two such buttons in the form header.
<button name="action_confirm" states="sent" string="Confirm Sale" class="btn-primary o_sale_confirm" type="object"/>
<button name="action_confirm" states="draft" string="Confirm Sale" class="o_sale_confirm" type="object"/>
How do I hide the above two buttons when based on the value of boolean_field?
Thanks.
I can't test it but I think it should be something like that.
It needs the boolean_field first.
It replaces first and second buttons attrs field. If the original buttons already have something in the attrs field then it should be added to here aswell.
<xpath expr="//button[#name='action_confirm'][1]" position="attributes">
<attribute name="attrs">{'invisible': [('boolean_field', '=', False)]}</attribute>
</xpath>
<xpath expr="//button[#name='action_confirm'][2]" position="attributes">
<attribute name="attrs">{'invisible': [('boolean_field', '=', False)]}</attribute>
</xpath>
Related
I'm using Odoo V12 CE and my issue is I try to edit a PageA view.
Have some PageA, PageB and more, inherit ParentPage.
I want to inherit ParentPage into PageA to add some content and, PageB must be: PageB = ParentPage(without modifications from PageA) + PageB.
Helps please and thanks for all!!
<template id="tpml_id" inherit_id="parent.tpml_parent_id" name="Posts">
<xpath expr="//ul[#id='post-list']" position="after">
<span>This is my posts list for all page (MyPage and all page inherits ParentPage). It's so bad. </span>
</xpath>
</template>
<!-- I want this -->
<template id="tpml_id" copy_inherit_id="parent.tpml_parent_id" name="Posts">
<xpath expr="//ul[#id='post-list']" position="after">
<span>This is my post list for this page only. </span>
</xpath>
</template>
If you want to inherit view but do not want to add anything in parent.tpml_parent_id then you can write as following :
<template id="tpml_id" inherit_id="parent.tpml_parent_id" name="Posts" primary="True">
<xpath expr="//ul[#id='post-list']" position="after">
<span>This is my post list for this page only. </span>
</xpath>
</template>
I'm setting up redux form in react application, in the form i have dual list box, i cannot shift values from one box to another, vise versa.
other thing im doing checkbox switches it doesn't post value when pages loads when ever i touch/click on it then it does, in both cased true/false but not default false.
for Dual list box
<Field
name="list"
type="select"
onChange={this.handleOnMove}
component={this.renderReactSelectWrapper}
/>
renderReactSelectWrapper = props => (
<DualListBox
value={props.input.value}
onChange={props.input.onChange}
onBlur={props.input.onBlur(props.input.value)}
options={available}
selected={selected}
placeholder="Select"
simpleValue
icons={{
moveLeft: <span key={0}><</span>,
moveAllLeft: [<span key={1}><<</span>],
moveRight: <span key={2}>></span>,
moveAllRight: [<span key={4}>>></span>],
moveDown: <span key={5}>↓</span>,
moveUp: <span key={6}>↑</span>
}}
/>
);
For Checkbox/Switch
<Field
name="available"
id="available"
component={this.renderToggleInput}
/>
renderToggleInput = field => ( <Switch checked={field.input.value} onChange={field.input.onChange} /> );
I need to have value shift from one box to another, in the case of checkbox/switch i need to post when page loads.
I was tackling the same problem. I think the issue is you aren't updating the selected array correctly. The follow code worked for me on the selected option.
<DualListBox
options={options}
value={this.props.input.value}
onChange={this.props.input.onChange}
selected={[...this.props.input.value]}
/>
I'm working on Employee Directory module in odoo11 and I want to set a notebook page invisible to the current user (Logged user) if he is different to the related user.
I tried to use user.id in XML but it does not work.
Here is my code :
<page name="hr_settings" string="HR Settings" attrs="{'invisible':[('user_id', '!=', user.id)]}">
<group>
<group string='Status' name="active_group">
<field name="company_id"/>
<field name="user_id" string="Related User"/>
</group>
</group>
</page>
The error message :
<class 'NameError'>: "name 'user' is not defined" while evaluating
"{'invisible': [('user_id', '!=', user.id)]}"
None" while parsing /opt/odoo/odoo/my_addons/hr_dz/views/employee_views.xml:5, near
<record id="view_employee_form" model="ir.ui.view">
<field name="name">hr.employee.form</field>
Any idea about that, please ?
One of the thing i know to use a field in attrs the field must be Mentionsed in the form. i don't know how to get the value of the user id in the form. but if there is not a short way like uid or user you can work arround this, just create a m2o field to res.users make this field compute field with store = False.
Please try this it useful to you.:
# by default store = False this means the value of this field
# is always computed.
current_user = fields.Many2one('res.users', compute='_get_current_user')
#api.depends()
def _get_current_user(self):
for rec in self:
rec.current_user = self.env.user
# i think this work too so you don't have to loop
self.update({'current_user' : self.env.user.id})
and you can use this field in your form.
<page name="hr_settings" string="HR Settings" attrs="{'invisible':[('user_id', '=', current_user)]}">
<group>
<group string='Status' name="active_group">
<field name="company_id"/>
<field name="user_id" string="Related User"/>
</group>
</group>
</page>
In your case basically, we can achieve directly with uid global expression variable on view level.
uid is also used into the expression evaluation in odoo xml view file
<page name="hr_settings" string="HR Settings" attrs="{'invisible':[('user_id', '!=', uid)]}">
<group>
<group string='Status' name="active_group">
<field name="company_id"/>
<field name="user_id" string="Related User"/>
</group>
</group>
</page>
No need to add and create any compute field for the code.
Please see the following view under the addons of Odoo V11
addons/project/project_view.xml.
I need add tag <sheet> inside <form> using xpath. I have tried below code:
<xpath expr="//form[#string='Bank account']" position="inside">
<sheet></sheet>
</xpath>
The sheet added but after the form tag.
How can i do it?
please try
<xpath expr="//form" position="inside">
<sheet></sheet>
</xpath>
or
<xpath expr="//form/group[1]" position="before">
<sheet></sheet>
</xpath>
if you gave any group tags inside form
When you use position="inside" what happens is that the sheet you are inserting is appended as the last item inside of your form. You do not need that, what you need is for the form //form[#string='Bank account'] to contain a sheet and that sheet to contain all the children of the form.
See if the xpaths below work for you:
<xpath expr="//form[#string='Bank account']" position="inside">
<sheet>
<xpath expr="//form[#string='Bank account']/[not(name()='sheet')]"/>
<xpath expr="//form[#string='Bank account']/[not(name()='sheet')]" position="replace"/>
</sheet>
</xpath>
What I do here is:
1) Add the sheet inside the form
2) Select all the items in the form(besides the sheet I just added and put them inside the sheet.
3) To avoid having items both in the sheet and outside, I remove the outside.
I have a one2many field like:
pricelist_details = fields.One2many('price.list.details', 'price_list_id', string='Price List Details', copy=True)
and xml like:
<notebook>
<page>
<field name="pricelist_details" nolabel="1" widget="one2many_list">
<tree string="Price List Details" editable="bottom" create="false">
<field name="state" invisible="1"></field>
<field name="date_time" attrs="{'required': True, 'readonly': True}"></field>
<field name="company_id" attrs="{'required': True, 'readonly': True}"></field>
<field name="category_id" attrs="{'required': True, 'readonly': True}"></field>
<field name="grade" attrs="{'required': True, 'readonly': True}"></field>
<field name="ex_mill" attrs="{'required': True, 'readonly': True}"></field>
<field name="sale_price_per_lb" attrs="{'required': True, 'readonly': [('state', '!=', 'draft')]}"></field>
<field name="price_per_bag" attrs="{'required': True, 'readonly': True}"></field>
</tree>
</field>
</page>
</notebook>
On a button click all the records are created and show up on GUI for this field.
Now i have added some filter fields beside this field like:
minor = fields.Many2one('product.minor',string='Minor')
sub_category = fields.Many2one('product.subcategory', string='Sub Category')
What i want is to filter my one2many field records on the basis of these filters. I dont want any records to be deleted. Just have
to filter the records.
Please help me regarding this.
Write the onchange method of the field "sub_category" and populate the response as you want it to be. return statement should looks like below:
return {'values': {'pricelist_details': [record_set]}}
record_set contains the objects that are filtered as per the field sub_category
record_set will be populated as below:
records_set = self.env['product.category'].search([('sub_category', '=', ID)])
NOTE: ID is the id of the changed field whose onchange method you are writing.