I have a button which I need to show only if the user is a superuser (admin). My problem is that when I'm using xpath to include the attrs, nothing is working as expected. My code is:
<record id="wms_stock_view_move_form" model="ir.ui.view">
<field name="name">wms.stock.view.move.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_form" />
<field name="arch" type="xml">
<field name="location_id" position="attributes">
<attribute name="domain">[('name','!=', 'Scrapped')]</attribute>
</field>
<field name="location_id" position="after">
<field name="is_superuser"/>
</field>
<field name="location_dest_id" position="attributes">
<attribute name="domain">[('name','!=', 'Scrapped')]</attribute>
</field>
<xpath expr='//form[#string="Stock Moves"]' position='attributes'>
<attribute name="create">false</attribute>
<attribute name="edit">false</attribute>
<attribute name="delete">false</attribute>
</xpath>
<xpath expr="//button[#name='action_cancel']" position="attributes">
<attribute name="attrs">{'invisible':[('is_superuser','=', True)]}</attribute>
</xpath>
</field>
</record>
here, is_superuser is a computed field, its code is:
is_superuser = fields.Boolean(compute='_is_super_user')
def _is_super_user(self):
if self._uid == SUPERUSER_ID:
self.is_superuser = True
else:
self.is_superuser = False
The original code for the button, in its original view is:
<button name="action_cancel" states="draft,assigned,confirmed" string="Cancel Move" type="object"/>
any idea, what I'm doing wrong ? Thanks in advance.
I would prefer to use Odoo's group access system for such behaviour. Just extend the button with the attribute groups and ofcourse the correct group (for example base.group_system or base.group_no_one for admins):
<field name="action_cancel" states="draft,assigned,confirmed" position="attributes">
<attribute name="groups">base.group_system</attribute>
</field>
The code that you are using should work :
first you need to put #api.depends() on the method definition, without putting any field so it will be computed every time the record is called.
second check the result of the compute field doe's it work like it should because the xml code is correct use print in console to see if the code i working is the method gets called.
I really appreciate all your help, but the above responses does not helped me. However, I found the answer for this question. Since, it has states included, we need to take that into account as well. We need to override the behavior of 'states' tag as well. so the code needs to be:
<xpath expr="//button[#name='action_cancel']" position="attributes">
<attribute name="states"></attribute>
<attribute name="attrs">{'invisible':['|', ('is_superuser','=', False), ('state', 'not in', ('draft','assigned','confirmed'))]}</attribute>
</xpath>
Related
I have overriden account.invoice_supplier_form and I have added kanban view
<record id="invoice_supplier_form_inherit" model="ir.ui.view">
<field name="name">account.invoice.supplier.form.inherit</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page/field[#name='invoice_line_ids']" position="attributes">
<attribute name="mode">tree,kanban</attribute>
</xpath>
<xpath expr="//notebook/page/field[#name='invoice_line_ids']" position="inside">
<kanban class="o_kanban_mobile">
...
So now page inside notebook supports two views - tree and kanban for invoice_line_ids. I want to set kanban as default view. How do I do that?
...
Did you try this:
<xpath expr="//notebook/page/field[#name='invoice_line_ids']" position="attributes">
<!-- reverse the order here -->
<attribute name="mode">kanban,tree</attribute>
</xpath>
<!-- and here make sure the kanban is the first tag inside the field tag -->
<xpath expr="//notebook/page/field[#name='invoice_line_ids']/tree" position="before">
<kanban class="o_kanban_mobile">
....
....
I am new in odoo.
I have a tree view , i want to show it by default with grouped by according to my stage_id.
Any one help me.
Thanks
<field name="name">dmr.search.view</field>
<field name="model">model.name</field>
<field name="arch" type="xml">
<search string="DMR">
<filter name="group_customer_id" string="Customer" icon="terp-partner" context="{'group_by':'field_name'}"/>
</search>
</field>
After adding search record, you need to add search_view_id in action.
For Ex :-
In action
<field name="search_view_id" ref="dmr_search_view"/>
I hope it works for you
I need to make a delete button invisible using attrs.
my code here.
in this code i want to put invisible delete button.
<record id="calender_event_form_id1" model="ir.ui.view">
<field name="name">calender_event</field>
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_form_popup"/>
<field name="arch" type="xml" delete="false">
<xpath expr="//field[#name='partner_ids']" position="after">
<field name="c_is_meeting_done" string="Is Meeting Done?" readonly="1"/>
<field name="description"/>
</xpath>
<xpath expr="//field[#name='alarm_ids']" position="after">
<div name="buttons">
<button name="%(ouc_meeting_wizard_action)d" string="Close Meeting" attrs="{'invisible':[('c_is_meeting_done', '=', True)]}" type="action" class="oe_highlight" />
</div>
</xpath>
</field>
</record>
You can give "delete=1" to your particular view from xml. Like this:
<form string="Custom" delete="1"/>
I've inherited a form view and made some modifications using xpath. I need a button in the header of form view to show only to admin user. But when I'm putting the groups, its giving following error :
Error details:
error_details
My code is:
<record id="wms_stock_view_move_form" model="ir.ui.view">
<field name="name">wms.stock.view.move.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_form" />
<field name="arch" type="xml">
<field name="location_id" position="attributes">
<attribute name="domain">[('name','!=', 'Scrapped')]</attribute>
</field>
<field name="location_dest_id" position="attributes">
<attribute name="domain">[('name','!=', 'Scrapped')]</attribute>
</field>
<xpath expr='//form[#string="Stock Moves"]' position='attributes'>
<attribute name="create">false</attribute>
<attribute name="edit">false</attribute>
<attribute name="delete">false</attribute>
</xpath>
<xpath expr='//button[#name="action_cancel"]' position='attributes'>
<attribute name="invisible">True</attribute>
</xpath>
<button name="action_done" states="draft,assigned,confirmed" string="Process Entirely" type="object" class="oe_highlight" position="replace" groups="base.group_no_one"/>
</field>
</record>
I have to guess which button you want to set new groups to, because your error relates to action_done but your own answer to action_cancel. So let me do this abstractly. You already have the answer in your question. Use XPath to "find" the button and use position="attributes":
<xpath expr="//button[#name='button_name']" position="attributes">
<attribute name="groups">module_name.group_id</attribute>
</xpath>
I eventually solved my own question, the solution is:
<xpath expr='//button[#name="action_done"]' position='replace'>
<button name="action_done" states="draft,assigned,confirmed" string="Process Entirely" type="object" class="oe_highlight" position="replace" groups="base.group_no_one"/>
</xpath>
I want to display my Many2one field.
I inherited from the hr_timesheet_sheet.sheet model like this:
class list_activity_sheet(models.Model):
_inherit = 'hr_timesheet_sheet.sheet'
activity_id = fields.Many2one('list_activity_sheet.activity')
class List_activity(models.Model):
_name='list_activity_sheet.activity'
name= fields.Char('Description',required=True)
And for the View:
<openerp>
<data>
<record id="List_activity_form" model="ir.ui.view">
<field name="name">hr_timesheet_sheet.sheet.form.inherit</field>
<field name="model">hr_timesheet_sheet.sheet</field>
<field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet/notebook/page[#string='Details']/field/tree/field[#name='name']" position="after">
<field name="activity_id"></field>
</xpath>
</field>
</record>
</data>
When i install my addon , i got that message:
field activity_id doesn't exist in the view.
Does anyone know how to solve that?
You're working on the wrong model. If i understand your view definition correctly, you want to choose an activity on the sheet lines.
You have to inherit hr.analytic.timesheet for that instead of hr_timesheet_sheet.sheet. In Odoo 9+ you have to inherit account.analytic.line, because hr.analytic.timesheet was kicked out.