Create button only for certain group - odoo

I want to make the create button only show for certain group. Here is my xml code
<record model="ir.ui.view" id="sales_forecast_view_tree">
<field name="name">sales.forecast.tree</field>
<field name="model">sales.forecast</field>
<field name="priority" eval="16"/>
<field name="groups_id" eval="[(4,ref('ts_addons_tbk.group_tbk_exim'))]"/>
<field name="arch" type="xml">
<tree string="Sales Forecast" version="7.0" >
<field name="name" />
</tree>
</field>
</record>
What shoukd I do?

In order di hide create button, it more easy to set the group in setting menu > Database Structure > Models
So no need to edit the script

Related

Hide field from tree view base on the condition, Odoo

I want to hide field from tree view depends on the condition. I tried some techniques, but didn't work for me. Currently I can hide just value not all column. I want to hide whole column.
This is my tree view. And this code just hide the value not column.
<record id="view_tai_approval_tree" model="ir.ui.view">
<field name="name">tai.approval.tree</field>
<field name="model">tai.approval</field>
<field name="arch" type="xml">
<tree create="false">
<field name="tai_reference"/>
<field name="tai_project_name"/>
<field name="responsible_name"/>
<field name="tai_purchase_date"/>
<field name="tai_supplier_name"/>
<field name="state" class="bg-danger" attrs="{'invisible': [('state', '!=', 'unapproved')]}"/>
<field name="state" class="bg-success" attrs="{'invisible': [('state', '!=', 'approved')]}"/>
<field name="state" class="bg-warning" attrs="{'invisible': [('state', '!=', 'pending')]}"/>
</tree>
</field>
</record>
Actually, as you can see in the code, I just want to change the colors depends on the states. So is there any simple solution for this?
Odoo allows you to change the behavior of the text based on the attributes of the corresponding record.
This documentation is for tree views, but what they describe also works for fields.
<record id="view_tai_approval_tree" model="ir.ui.view">
<field name="name">tai.approval.tree</field>
<field name="model">tai.approval</field>
<field name="arch" type="xml">
<tree create="false">
<field name="tai_reference"/>
<field name="tai_project_name"/>
<field name="responsible_name"/>
<field name="tai_purchase_date"/>
<field name="tai_supplier_name"/>
<field name="state"
decoration-danger=="state != 'unapproved'"
decoration-success="state != approved'"
decoration-warning="state != 'pending'"/>
</tree>
</field>
</record>

hide button Edit , Create on odoo xml

I want to hide the edit and create button on the form view for a specific user I use this code but the button not showing at all
i just want to hide buttons just for only group
<record model="ir.ui.view" id="edit_button_message_">
<field name="name">edit.button.message.1</field>
<field name="model">person.message</field>
<field name="inherit_id" ref="view_parent_message_form"/>
<field name="groups_id" eval="[(6,0,[ref('person_access')])]"/>
<field name="arch" type="xml">
<xpath expr="/form[#string='form_view_string']" position="attributes">
<attribute name="create">false</attribute>
<attribute name="edit">false</attribute>
</xpath>
</field>
</record>
and i use this
<form string="form_view_string" edit="false" create="false" >
nothing happened , I use odoo v8
You better create a security access for that group to allow just read to that model, preventing the create, write and unlink actions and those buttons should disappear.
You could create it in xml as it will be only one, like:
<record id="person_message_access" model="ir.model.access">
<field name="name">edit.button.message.access</field>
<field name="model_id" ref="person.message"/>
<field name="group_id" ref="person_access"/>
<field name="perm_read" eval="1"/>
<field name="perm_create" eval="0"/>
<field name="perm_write" eval="0"/>
<field name="perm_unlink" eval="0"/>
</record>
or you could set it into a field ir.model.access.csv with content like:
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
person_message_access,edit.button.message.access,model_person_message,person_access,1,0,0,0

Unknown field 'state' in domain when editing attribute

Using Odoo 10 (fetched from GitHub commit 7413b26, branch 10.0), installing a module which I'm porting over from Odoo 8.
This module forces the purchase.order.line form to show up upon clicking a line in purchase.order by removing the editable attribute from the tree, but when saving changes done in that form Odoo raises:
Error: Unknown field state in domain [["state","in",["purchase","to approve","done","cancel"]]]
purchase_order_error.xml:
<record id="purchase_order_line_tree" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="priority" eval="33"/>
<field name="type">form</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page/field[#name='order_line']/tree" position="attributes">
<attribute name="editable"/>
</xpath>
</field>
</record>
The __manifest__.py is:
{'name': "purchase_order_error",'depends': ['base', 'product', 'purchase'],'data': ['purchase_order_error.xml',],'installable':True}
and __init__.py is just the usual from . import purchase_order_error.
Here are some more observations:
The field state can have the following Selection values: [draft], [sent], [to approve], [purchase], [done], [cancel]; [draft] and [sent] do not appear in the error.
An Odoo user reported same problem on the Odoo GitHub bug tracker, without any solution as the time of writing.
Is there a workaround ?
You should add
<record id="purchase_order_line_tree" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="priority" eval="33"/>
<field name="type">form</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page/field[#name='order_line']/tree" position="attributes">
<attribute name="editable">top</attribute>
</xpath>
</field>
</record>
In your case it's going to open form view to allow you to create
records, because you have not given the value of editable attribute.
So in form view of purchase order line there might be no field defined "state". According to rule if fields are used anywhere in attrs, domains then it must be defined on view, it doesn't matter you can define it invisible.
So just add this field in Purchase order line form view or follow the first solution for editable="top"
<field name="state" invisible="1" />
The problem is when saving the record from the form view
the state field is not defined. you don't get this error
in the tree view because the field is there:
<page string="Products">
<field name="order_line" attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}">
<tree string="Purchase Order Lines" editable="bottom">
<field name="currency_id" invisible="1"/>
<field name="state" invisible="1"/>
.....
....
..
so you need to add it to the embedded form too:
<record id="xxx_purchase_order_form_list_details" model="ir.ui.view">
<field name="name">xxx_purchase_order_form_list_details</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='order_line']/tree" position="attributes">
<attribute name="editable"/>
</xpath>
<xpath expr="//field[#name='order_line']//form//field[#name='product_id']" position="before">
<field name="state" invisible="1"/>
</xpath>
</field>
</record>

Odoo: Where to edit the overview of customer invoices?

I'm new to Odoo and I'm looking for a way to add/edit columns in the overview of customer invoices.
Does anyone know which files to edit? Or how this "overview screen" is called so I can look it up better?
Link to screenshot of overview screen: http://oi58.tinypic.com/2prtyk0.jpg
Thanks in advance!
The VIEW of this "TREE" is defined in
addons/account/views/account_invoice_view.xml
Which has the code like this:
<record id="invoice_tree" model="ir.ui.view">
<field name="name">account.invoice.tree</field>
<field name="model">account.invoice</field>
<field name="arch" type="xml">
<tree decoration-info="state == 'draft'" decoration-muted="state == 'cancel'" string="Invoice">
<field name="partner_id" groups="base.group_user" string="Customer"/>
<field name="date_invoice"/>
<field name="number"/>
<field name="commercial_partner_id" invisible="1"/>
<field name="reference" invisible="1"/>
<field name="name" invisible="1"/>
<field name="journal_id" invisible="1"/>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
<field name="user_id"/>
<field name="date_due"/>
<field name="origin"/>
<field name="amount_total_signed" sum="Total Amount"/>
<field name="residual_signed" sum="Residual Amount"/>
<field name="currency_id" invisible="1"/>
<field name="company_currency_id" invisible="1"/>
<field name="state"/>
<field name="type" invisible="context.get('type',True)"/>
</tree>
</field>
</record>
I recommend you use developer mode to know the name of the view what you want change/edit/inherit/..etc,
Go to Administrator => About Odoo => Activate Developer Mode then return to the view and you will see near to the name of the current view a Drop-down list with name Debug View#xx click there and choice Edit TreeView/FormView/...etc after that you are going to see the definition of the current view, in this way you will know what view you need to inherit/edit/..etc
I hope this will help you!

How to add a field into an inherited view's tab/page?

How can I inherited a view to add a field into the "Sessions" tab ?
e.g :
<record model="ir.ui.view" id="partner_sessions_form_view">
<field name="name">partner.sessions.name</field>
<field name="model">res.partner</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<xpath expr="/form/notebook/page[#string='Notes']" position="after">
<page string="Sessions">
<field name="session_ids" nolabel="1" colspan="4"/>
</page>
</xpath>
</field>
</record>
This adds a page, but how would I add a field in the page Sessions ?
If you want to add a field to page 'Sessions' that you have created above, then you should provide
<record model="ir.ui.view" id="partner_sessions_form_view_again_inherited">
<field name="name">partner.sessions.name.inherited</field>
<field name="model">res.partner</field>
<field name="type">form</field>
<field name="inherit_id" ref="partner_sessions_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[#name='session_ids']" position="before">
<field name="new_field1" nolabel="1" colspan="4"/>
</xpath>
</field>
</record>
if you want to add add a field to the session_ids tree or form view, then
<xpath expr="//field[#name='session_ids']/tree/field[#name='already_existing_field']" position="after">
<field name="new_field1" />
</xpath>
You need to find that field in side you page Session
like this (but that page has to be their in view):
<xpath expr="//page[#string='Sessions']/field[#name='some_field'] position="after">
<field name="session_ids" nolabel="1" colspan="4"/>
</xpath>
Thanks
This is covered pretty well in the documentation. The simplest case is to just add your new field after an existing one. In this example, you're placing the relation_ids field after the lang field.
<record model="ir.ui.view" id="view_partner_form4">
<field name="name">res.partner.form.inherit4</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="lang" position="after">
<field name="relation_ids"/>
</field>
</field>
</record>
If that field appears in more than one place, you'll have to use an XPath element. For example, if the lang field appears in a subview's tree view and its form view.