Odoo hide "Create" and "Edit" buttons depend on state and role - python-2.7

I would like to hide "Create" and "Edit" buttons on state and group role in form view .For example hide Create and Edit buttons when the state is not draft and user belongs to request user group.
As I understand hide buttons I can on editing views. And on group role rules I can disable create or edit.
I tried to write a rule for request user group but then user can't use the button but see it.
From view I found only way to hide default Create and Edit buttons:
<form string="Request" create="false" edit="false">
But in that way I hide them for all users for all states. Is there another way how can I hide Create and Edit buttons depend on state and group role?
I tried to expand the base.xml template on conditions state is "approved" or "done" and the group role is purchase_request_user and view id is view_purchase_request_form "Create" and "Edit" button:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space='preserve'>
<t t-extend="FormView.buttons">
<t t-if="widget.fields_view.state !== 'done' or widget.fields_view.state !== 'approved'">
<div class="o_form_buttons_view">
<button t-if="widget.is_action_enabled('edit')"
type="button"
class="oe_form_button_edit btn btn-default btn-sm" accesskey="E">
Edit
</button>
<button t-if="widget.is_action_enabled('create')"
type="button" class="oe_form_button_create btn btn-default btn-sm"
accesskey="C">
Create
</button>
</div>
</t>
</t>
</templates>
added 'base' to dependences.
UPDATED base.xml Now I can change "Create" button name depend on my view name but nothing that depends on my module states.
<templates>
<t t-extend="FormView.buttons">
<t t-jquery="button.oe_form_button_create" t-operation="replace">
<t t-if="widget.fields_view.name == 'purchase.request.form'">
<button t-if="widget.is_action_enabled('create')"
type="button" class="oe_form_button_create btn btn-default btn-sm"
accesskey="C">
New button name
</button>
</t>
</t>
</t>
</templates>
My form view xml peace:
<openerp>
<data>
<record model="ir.ui.view" id="view_purchase_request_form">
<field name="name">purchase.request.form</field>
<field name="model">purchase.request</field>
<field name="arch" type="xml">
<form string="Purchase Request" create="false" edit="false">
<header>
<button name="%(action_sale_order_reset)d" attrs="{'invisible': [('state','not in', ('to_approve_first'))]}" string="Reset" type="action" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_to_approve_first" states="draft" string="Request approval" type="object" class="oe_highlight"/>
<button name="button_approved" states="to_approve_first" string="Approve" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_approvedd" states="approved" string="Return Request" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_create_order" states="approvedd" string="Create Order" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_user"/>
<button name="button_to_approve_second" states="create_order" string="Approve" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_approved2" states="to_approve_second" string="Done" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_rejected" states="draft,approvedd" string="Reject" type="object" groups="purchase_request.group_purchase_request_user"/>
<field name="state" widget="statusbar" statusbar_visible="draft,to_approve_first,approved,rejected" statusbar_colors="{"approved":"green"}"/>
</header>
<sheet>
<group>
<group>
<field name="date_start" readonly="1"/>
<field name="participate_process"/>
</group>
<group>
<field name="requested_by" readonly="1"/>
<field name="assigned_to" attrs="{'readonly': [('state','not in', ('draft'))]}" />
</group>
<notebook>
<page string="Order" attrs="{'invisible': [('state','in', ('draft', 'to_approve_first', 'approved', 'approvedd'))]}">
<field name="supply_ids" attrs="{'readonly': [('state','not in', ('to_approve_second'))]}"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

You have to write a template inheriting the 'FormView.buttons' one, check the context fields, like groups and state, and put a condition based on the wanted fields.
Something like this:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space='preserve'>
<t t-extend="FormView.buttons">
<t t-if="widget.fields_view.state == <wanted_state>">
<your operations>
</t>
</t>
</templates>

Using this you can inspect all the FormView widget fields, you can find it in /odoo/addons/web/static/src/js/views/form_view.js.
I also found datarecord inside it, which should contain your state info and value.
Then, if you want to do the same with the buttons in edit mode, replace '.o_form_buttons_view' with '.o_form_buttons_edit'.
Tell me if you have problems. And again sorry for the delay, I was a little busy.
<t t-extend="FormView.buttons">
<t t-jquery=".o_form_buttons_view" t-operation="before">
<t t-log="widget"/>
</t>
</t>

Thank you! #Michele Zaccheddu using your answer I can get many types of the widget using
<t t-extend="FormView.buttons">
<t t-jquery=".o_form_buttons_view" t-operation="before">
<t t-log="widget"/>
</t>
</t>
Just put the code as a test and after update apps - go to form view, check using browser Developer Tools, In the console you will get the list from "Class", I'm using odoo 11 and can target
<t t-if="widget.initialState.data.state === 'draft'">
For other versions, please check the t-log yourself it can be different, but I haven't check for user group it may or may not be there...

Related

Insert grid template row (within grid) under condition

In a facebook-esque fasion, I'm working in a post with comments. The comments have a int which indicates the id of the parent post. So Comment 1 and 2 both have assigned as parent Post 1.
What im working on is on displaying them as a grid within a grid. Here is that part in .zul:
<grid id="postGrid" height="550px" model="#load(vm.pcdata.posts)" emptyMessage="No Posts.">
<template name="model">
<row>
<window border="normal">
<!-- .................. -->
<!-- PARENT POST -->
<!-- .................. -->
<caption id="userPost" label="#load(each.user)"/>
<textbox id="infoPost" readonly="true" value="#load(each.info)" multiline="true" rows="4" width="100%" mold="rounded"/>
<separator bar="true"/>
<hlayout>
<div>
<button label="Like" onClick="#command('addPLike', postid=each.postid)"/>
</div>
<div hflex="true">
<textbox id="likeTB" disabled="true" width="40px" style="text-align:center" value="#load(each.plikes)"/>
</div>
</hlayout>
<separator bar="false"/>
<window border="normal">
<!-- .................. -->
<!-- THE SECOND GRID-->
<!-- .................. -->
<grid id="commentGrid" height="150px" model="#load(vm.pcdata.comments)" emptyMessage="No Comments.">
<template name="model">
<row>
<window border="normal">
<caption id="userComment" label="#load(each.user)"/>
<textbox id="infoComment" readonly="true" value="#load(each.info)" multiline="true" rows="4" width="100%" mold="rounded"/>
<separator bar="true"/>
<hlayout>
<div>
<button label="Like" onClick="#command('addCLike', commentid=each.commentid)"/>
</div>
<div hflex="true">
<textbox id="likeTB" disabled="true" width="40px" style="text-align:center" value="#load(each.clikes)"/>
</div>
</hlayout></window></row></template></grid></window></window></row></template></grid>
In the second grid, I imagine there could be some sort of if function in which if both the postid in the father Post and the postsrc in the child Comment are the same, the comment will be displayed. Is there any way to make this work?
You can use shadow element <if>, e.g.
<if test="#load(vm.yourFlag)">
<grid id="commentGrid">
....
</if>
please see http://books.zkoss.org/zk-mvvm-book/8.0/shadow_elements/flow_control.html
Do you mean commentGrid is created but inner window is hidden, so there is space inside commentGrid, right?
Since you specify emptyMessage on commentGrid, it should show no comments. Or there are still comments but all hidden? If so, you can consider hide both commentGrid with inner window.

Template Inheritance odoo

I am developing in odoo 8, and my task is to create menu links on left side of the page and when you click the link, the template having html should be shown. below are the codes applied so far:
my template is : external id ( menu_item.test )
<template id="receivePO">
<div >
<div align="center" >
<h2>Login</h2>
</div>
<form role="form" t-attf-action="" method="POST">
<div align="center">
<table >
<tr>
<td>Enter Name :</td>
<td><input type="text" name="username" id="po"/></td>
</tr>
<tr>
<td>Enter Password :</td>
<td><input type="text" name="passwd" id="po"/></td>
</tr>
<tr>
<td></td>
<td><button name="submit" type="submit" >Submit</button></td>
</tr>
</table>
</div>
</form>
</div>
</template>
The above template is in Module A.
I have created a new module ( Module B) to create menu item in warehouse menu and if clicked on the menu item login it should display the above template.
in Module B, the menu items are:
<record id="action_view_menu" model="ir.actions.act_window">
<field name="name">MenuItem</field>
<field name="res_model">Module B Model Name</field>
<field name="inherit_id" ref="menu_item.test" />
</record>
<menuitem id="menu_sub_sales_menuitem" parent="stock.menu_stock_root" name="Warehouse Management" sequence="1"/>
<menuitem id="menu__sub_menuitem" parent="menu_sub_sales_menuitem" name="Processes" sequence="1" groups="base.group_no_one" />
<menuitem id="menu__menuitem" parent="menu__sub_menuitem" name="Login" sequence="1" action="action_view_menu" />
I have tried using using ir.ui.view in model also, but got errors.
Can someone help me regarding this. Also, Login template in other Module will be processing login and going into other templates. I have to show those templates on click of the submit button.
Thanks,

Joomla Template Paramenter Type Menu Assignment

I use Joomla 3.2.1.
I create a new template and add some configuration parameter.
Now I need in my advanced configuration a selection, where I can set the menu assignment for a slideshow in my template. The Slideshow is html / javascript (jquery). I can enable/disable it in configuration.
But I want to assign it to menu item. Is there a configuration parameter type for this? I couldnt find.
my configuration looks like:
<config>
<fields name="params" >
<fieldset name="advanced">
<field type="spacer" label="Slideshow" />
<field name="isSlideshow" type="radio"
class="btn-group btn-group-yesno"
default="1"
label="Slideshow">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<!-- add menu assingment-->
<field type="menut assignment???"....>
<field name="slide1" type="media" default=""
label="Slide 1"/>
<field name="slide2" type="media" default=""
label="Slide 2"/>
<field name="slide3" type="media" default=""
label="Slide 3"/>
</fieldset>
</fields>
</config>
You should create a module with the slideshow code.
Then assign the module to a position in your template, where you will include the position:
<jdoc:include type="modules" name="slideshow" />
Install the module in the slideshow position, then in the module settings, tab "Menu Assignment", choose "Only on the pages selected";
below you can tick the menu items you want it to show on.
There are a few cases where this is not sufficient, i.e. in the blog view the articles will share the same menu item, but you might want to treat them differently. You have many options here, the best is to create a different - named position in the template, and assign the modules to the appropriate one, i.e.:
<jdoc:include type="modules" name="slideshow-all" />
<jdoc:include type="modules" name="slideshow-articles" />

Joomla ACL custom actions

I'm creating a custom (1.6) component wherein users can book a camp site. Users will be required to log in if they want to use funds/credits that they already have stored. Only certain groups can use these funds/credits.
I have created an access.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<access component="com_propbooker">
<section name="booking">
<action name="booking.create" title="Book Site" description="Allows users of this group to book sites." />
</section>
</access>
and my config.xml file:
<config>
<fieldset name="API Configuration" label="API Configuration">
<field name="google_api_key" label="Google API Key" type="text" size="50" default="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
</fieldset>
<fieldset name="Booking Permissions" label="Booking Permissions" description="Set Groups that can book sites">
<field name="booking_permission" label="Booking Permission" type="rules" class="inputbox" validate="rules" filter="rules" component="com_propbooker" section="booking" />
</fieldset>
</config>
It all shows up fine when I click the options button, but no changes are ever saved. It always flips back to "Inherited" when i click the "Save" button.
Thanks in advance for any insight.
Try using permissions as the fieldset name and rules as the fieldname in your config.xml.
Like this:
<fieldset name="permissions"
label="JCONFIG_PERMISSIONS_LABEL"
description="JCONFIG_PERMISSIONS_DESC" >
<field name="rules"
type="rules"
label="JCONFIG_PERMISSIONS_LABEL"
class="inputbox"
validate="rules"
filter="rules"
component="com_propbooker"
section="booking"
/>
</fieldset>
I would also consider using the section name component as it is the default naming. But your needs may be different.

How to programmatically disable buttons or add/remove items from dropDown with Office Ribbon UI

I have written a simple C++ COM Office add-in that loads a ribbon XML definition and displays a simple ribbon tab. It features some buttons and a dropDown (combobox/droplist). I can handle button click events and combo selection change events like a charm.
Now I want to update ribbon UI according to changes in the active document so that some buttons are disabled and some items added/removed from combobox.
I have searched up and down and could not find a way to control this. Am I missing something very obvious? How can I change button enabled state from anywhere in my code?
The way I've seen it done, using the Windows Ribbon control: the extra buttons must be specified in the XML markup, at design time. At runtime, you call SetModes() to specify which sets of widgets gets displayed in the ribbon.
Like this:
<Application.Views>
<Ribbon>
<Ribbon.Tabs>
<Tab CommandName="cmdTabMain" ApplicationModes="0,1">
<Group CommandName="cmdGroupCommon"
SizeDefinition="ThreeButtons"
ApplicationModes="0,1">
<Button CommandName="cmdButtonNew" />
<Button CommandName="cmdButtonOpen" />
<Button CommandName="cmdButtonSave" />
</Group>
<Group CommandName="cmdGroupSimple"
SizeDefinition="TwoButtons"
ApplicationModes="0">
<Button CommandName="cmdButtonSwitchToAdvanced" />
<Button CommandName="cmdButtonDropA" />
</Group>
<Group CommandName="cmdGroupAdvanced"
SizeDefinition="FourButtons"
ApplicationModes="1">
<Button CommandName="cmdButtonSwitchToSimple" />
<Button CommandName="cmdButtonDropA" />
<Button CommandName="cmdButtonDropB" />
<Button CommandName="cmdButtonDropC" />
</Group>
</Tab>
</Ribbon.Tabs>
</Ribbon>
</Application.Views>
Then (in C# anyway) in the click handler, you do _ribbon.SetModes(1) or _ribbon.SetModes(0).