Error while showing button for specific user (Admin) odoo 8 - xpath

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>

Related

Can I set default view mode of a field inside Notebook/Page

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">
....
....

Make a delete button invisible using attrs. I am using Odoo 10

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"/>

conditionally hide a button openerp/odoo

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>

Odoo use both inherited Tree View and Parent Tree View

I created a special tree view for res.partner that help me modify records on the fly.
I put this view in a special Menu: test Configuration / Modification Rapide / Modification Contacts.
Everything is working fine expect that whenever there's a res.partner tree it's my tree view that is used.
Is there a way to use my custom tree view only from my Custom menu.
and every place else is the default tree view that is used ?
<record model="ir.ui.view" id="view_test_contact_tree">
<field name="name">res.partner.tree.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<field name="email" position="replace" />
<field name="phone" position="replace" />
<xpath expr="//tree[#string='Contacts']" position="attributes">
<attribute name="editable">bottom</attribute>
</xpath>
<xpath expr="/tree/field[#name='display_name']" position="before">
<field name="isBuyer" string="A"/>
<field name="isSeller" string="V"/>
<field name="isSupplier" string="F"/>
<field name="isMiddle" string="I"/>
<field name="isBackOffice" string="B"/>
</xpath>
<xpath expr="/tree/field[#name='display_name']" position="after">
<field name="mobile"/>
<field name="phone"/>
<field name="email"/>
</xpath>
</field>
</record>
<record model="ir.actions.act_window" id="action_res_partner_rel10">
<field name="name">Menu</field>
<field name="res_model">res.partner</field>
<field name="view_mode">tree</field>
</record>
<menuitem name="test Configuration" id="test_config_id" sequence="450"/>
<menuitem name="Modification Rapide" id="modif_id" parent="test_contact.test_config_id" sequence="20" />
<menuitem name="Modification Contacts" id="sub_gestion_modif_id" parent="modif_id" sequence="11" action="action_res_partner_rel10"/>
As I understand you want to show your own created tree view in this menu.
So for this you have to pass your create tree view in ref of action to open your tree view
Like:
<record id="action_quotations" model="ir.actions.act_window">
<field name="name">Quotations</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.order</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_quotation_tree"/> <======= your tree view id
<field name="view_mode">tree,form,calendar,graph</field>
<field name="context">{'search_default_my_sale_orders_filter': 1}</field>
<field name="domain">[('state','in',('draft','sent','cancel'))]</field>
</record>
you have not have to inherit exits view and change in this, instead of create new tree view and pass in actions
Hope this help

How add new field on tree view (inherit on inherited)

I'm trying to replace a field in a tree view. Help me please.
This is script on base odoo enteprice
<record model="ir.ui.view" id="view_task_form2_inherited">
<field name="name">project.task.form.inherited</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2" />
<field name="arch" type="xml">
<field name="project_id" position="attributes">
<attribute name="on_change">onchange_project(project_id)</attribute>
</field>
<field name="tag_ids" position="after">
<field name="analytic_account_id" invisible="1"/>
<field name="progress" widget="progressbar"
groups="project.group_time_work_estimation_tasks"/>
</field>
<xpath expr="//notebook/page[#name='description_page']" position="after">
<page string="Timesheets" groups="project.group_tasks_work_on_tasks,project.group_time_work_estimation_tasks">
<field name="timesheet_ids" groups="project.group_tasks_work_on_tasks" context="{'default_account_id' : analytic_account_id, 'default_is_timesheet' : 1}">
<tree editable="top" string="Timesheet Activities">
<field name="date"/>
<field name="user_id" required="1"/>
<field name="name"/>
<field name="account_id"/>
<field name="unit_amount" string="Duration" sum="Total time" widget="float_time"/>
<field name="is_timesheet" invisible="1"/>
</tree>
</field>
<group>
<group class="oe_subtotal_footer oe_right" name="project_hours" groups="project.group_time_work_estimation_tasks">
<field name="effective_hours" widget="float_time" groups="project.group_time_work_estimation_tasks"/>
<field name="remaining_hours" widget="float_time" class="oe_subtotal_footer_separator" groups="project.group_time_work_estimation_tasks"/>
</group>
</group>
</page>
</xpath>
</field>
</record>
This is my custom script on _view.xml:
<record id="project_task_view_form" model="ir.ui.view">
<field name="name">project.task.view.form</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field name="arch" type="xml">
<xpath expr="/notebook/page[#name='description_page']" position="replace">
<page string="Timesheets" groups="project.group_tasks_work_on_tasks,project.group_time_work_estimation_tasks">
<field name="timesheet_ids" groups="project.group_tasks_work_on_tasks" context="{'default_account_id' : analytic_account_id, 'default_is_timesheet' : 1}">
<tree editable="top" string="Timesheet Activities">
<field name="date"/>
<field name="user_id" required="1"/>
<field name="name"/>
<field name="unit_amount" string="Duration" sum="Total time" widget="float_time"/>
<field name="is_timesheet" invisible="1"/>
<field name="invoiceable_analytic_line"/>
</tree>
</field>
</page>
</xpath>
</field>
</record>
I want add new field "invoiceable_analytic_line" inside "timesheet_ids", but it doesn't work.
anybody help me?
Thanks.
View
The procedure is correct but just that there is an error with the expr attribute inside xpath.
Instead:
<xpath expr="/notebook/page[#name='description_page']" position="replace">,you have to write:
<xpath expr="//sheet/notebook/page[1]" position="replace"> when on odoo 10<xpath expr="/sheet/notebook/page[#string='Description']" position="replace">Because description_page doesn't existSo copy whole <page string="Description">..</page> tag from /project/project_view.xml and paste it inside your xpath tag by modify the string. After that insert your field where you want
Model
class Add_in_timesheet(models.Model)
_inherit = 'project.task
invoiceable_analytic_line = fields.Char(string=u"Invoiceable")

Resources