Tree child can only have one of field, button, control, groupby, widget, header tag (not feild) [closed] - odoo

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 months ago.
Improve this question
Odoo Server Error
Error while validating view near:
<tree>
<feild name="CustomerDetailIds">
</feild>
1. Tree child can only have one of field, button, control, groupby, widget, header tag (not feild)
Code XML:
<record id="view_tailor_detail_form" model="ir.ui.view">
<field name="name">tailor detail form</field>
<field name="model">tailor.data.detail</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<group>
<field name="name"/>
<field name="Phone"/>
</group>
<group>
<field name="table_no"/>
<field name="Catagory"/>
<field name="costumer_detail_id"/>
</group>
</group>
<notebook>
<page string="Customer detail">
<tree>
<feild name="CustomerDetailIds">
</feild>
<feild name="C_ids">
</feild>
<feild name="details">
</feild>
</tree>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
But when I remove the tree tag it works fine but not find any output fields on UI side.

"feild" is incorrect, change it to "field"

We can use tree tag inside a one2many or many2many field.
In your case, you declared tree tag inside page tag. So Odoo can not find a valid field.
So removing the tree tag will work or use it inside one2many or many2many field.
For example:
<field name="one2many_field">
<tree>
<field name="x">
<field name="y">
</tree>
<form>
<group>
<field name="x">
<field name="y">
</group>
</tree>
</field>

Related

odoo 9 how to add relational field to pivot view?

I'm customizing Project's pivot view to show timesheet description along with task's name.
here is my code below but when I click pivot view it shows an error
<!-- Insert Project Issue Pivot Field -->
<record id="project_task_custom_pivot" model="ir.ui.view">
<field name="name">project.task.custom.pivot</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_project_task_pivot"/>
<field name="arch" type="xml">
<field name="stage_id" position="after">
<field name="name" type="row"/>
<field name="timesheet_ids" type="row"/>
</field>
</field>
</record>
Error below
assert groupby_def and groupby_def._classic_write, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True"
Edit
I re-defined the field "timesheet_ids" as #George Daramouskas mentioned.
timesheet_ids = fields.One2many('account.analytic.line', 'task_id', string="Timesheetss", store=True)
But It didn't work.
So I took a look at the source code in Odoo Source
The function "One2many" has no such a parameter.
I guess the Store=True is for only regular field not related field.
Is there any other solution for this?
Thanks
Create your field with the attribute store=True in the constructor so that the field is stored in the database.

Odoo tree view with create_date

Do you know how to insert the column create_date on the Odoo Customers Tree View? It would let me see the most recent clients created on the system.
Thank you,
Eduardo
for insert the column create_date on the Odoo Customers Tree View follow the following steps:-
1:- inherit in .py file
from openerp import models, fields, api, _
class ResPartner(models.Model):
_inherit = 'res.partner'
create_date = fields.Datetime("Date")
2:- extend res.partner tree view.
<record id="view_inherit_res_partner_tree" model="ir.ui.view">
<field name="name">res.partner</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='function']" position="before">
<field name="create_date"/>
</xpath>
</field>
</record>
I would advise against changing the _order attribute on the model as that changes the order in the database, which may not be what you are trying to achieve. Instead, add a default_order="create_date desc" attribute to the tree element of the list view. In the arch:
<tree position="attributes">
<attribute name="default_order">create_date desc</attribute>
</tree>
Follow this step
1/ Inherit res_partner class.
In your .py file, add this code.[redefine _order attribute]
class res_partner(osv.Model):
_inherit = "res.partner"
_order = "create_date desc"
res_partner()
2/ In your view file, inherit the partner's tree-view and add create_date field.
<record id="view_partner_tree_extended" model="ir.ui.view">
<field name="name">res.partner.extended</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='display_name']" position="before">
<field name="create_date"/>
</xpath>
</field>
</record>
Note : No need to add create_date field in python file because it comes from osv.model base class.
_order atttribute is used for sort the records as your requirement.
Restart server and update your module.
Hope It will work for you !!
Let me know if you have any query.
As create_date is Automatic fields in Odoo, you can directly access it in the tree view.
Example:-
<record id="customer_list_view" model="ir.ui.view">
<field name="name">customer.tree</field>
<field name="model">bank.customer</field>
<field name="arch" type="xml">
<tree string="Customer View">
<field name="name"/>
<field name="contact"/>
<field name="create_date"/> // Directly access from database(no need to declare in model)
</tree>
</field>
</record>
I'd suggest that you'll use xpath and inherit the tree view from the customers. The following xml should work:
<record id="inherit_customer_tree_view" model="ir.ui.view">
<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">
<xpath expr="//field[#name='display_name']" position="before">
<field name="create_date" />
</xpath>
</field>
</record>
To insert create_date into the tree view
first create a field with the same name ['create_date'] in your .py file
'create_date':fields.datetime('Create Date')
then put it in your tree view. It will work.
Write code in your specific tree view
<record id="my_tree_view_id" model="ir.ui.view">
<field name="name">my.mode.view.tree</field>
<field name="model">my.model</field>
<field name="mode">primary</field>
<field name="arch" type="xml">
<tree string="My model tree view">
<field name="name" />
<field name="product_count" />
<field name="write_date" />
</tree>
</field>
</record>
Using the write_date in field tag then print date with time in specific tree view.
you can direct declare in xml. No need to define .py file. Because create_date is a odoo magic field. so, you can declare directly in tree view.
<data>
<xpath expr="//field[#name='display_name'][not(ancestor::field)]" position="after">
<field name="create_date"/>
</xpath>
<xpath expr="//field[#name='create_date'][not(ancestor::field)]" position="after">
<field name="create_uid"/>
</xpath>
</data>
Place this code in a view using the developers tool button in the partner tree
create_date = date
create_uid = the user that created the partner
In Odoo/OpenERP we can inherit or use existing modules object/class/model and views. We can also inherit single field of existing modules. The question is why we need such inheritance.
The purpose of inheritance or why we need inheritance is given below:
To change attributes of some fields which exists on existing/custom
model (e.g. making fields readonly,invisible)
To add/modify/delete old or new fields in existing/custom model
(e.g. Product, Sales, HR, Fleet Management, Attendance modules model
etc)
We can also add buttons in already existing/custom model (form and
tree) view by using inheritance

OpenERP - field not showing in a tree view

Here is my XML file. For some reason the field "product_uom" is not showing in view's tree view. Any insights why it is happening and how I can make it show?
<tree string="Components" editable="bottom">
<field name="sequence" widget="handle"/>
<field name="product_id" on_change="onchange_product_id(product_id,
product_qty)"/>
<field name="type"/>
<field name="product_qty"/>
<field name="product_uom" on_change="onchange_uom(product_id,
product_uom)" groups="product.group_uom"/>
<field name="product_rounding"/>
<field name="product_efficiency"/>
<field name="date_start"/>
<field name="date_stop"/>
<field name="attribute_value_ids" widget="many2many_tags" domain="
[('product_ids.product_tmpl_id', '=', parent.product_tmpl_id)]"/>
</tree>
The product_uom field has a groups="product.group_uom" attribute.
This makes it visible only to the users in that Group.
Either remove it from the tree definition, or make sure your user in in that group.
Probably what you need is just to activate the "Allow using different units of measures" feature on Settings / Configuration / Sales, Product Features section. Behind the scenes this activates the group_uom for all users.

How to make field readonly based on group and status?

I want to make field readonly based on group, and status. Like I have two groups:
Manager Group
User Group
If I give User Group to any user and then change Status to Done, then field will be readonly for this user.
Hope I was able to make it clear to understand. Thanks.
Create a functional field of type boolean. If the logged in user is under user group and state is done, then return true. Then in the view, specify attrs="{'readonly':[('boolean_field_name','=',True)]}"
OR
First create your form view. Then inherit the view also specify the groups. for example in sale order form view, i want to make the customer reference field readonly for group user when state is not in draft or sent.
<record id="view_order_form_cust_ref_readonly" model="ir.ui.view">
<field name="name">sale.order.form.readonly.cust</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="groups_id" eval="[(6, 0, [ref('base.group_user') ])]"/>
<field name="arch" type="xml">
<field name='client_order_ref'" position="attributes">
<attribute name="attrs">{'readonly':[('state','not in',['draft','sent'])]}</attribute>
</field>
</field>
</record>
you can apply access rule on field level in OpenERP, like in py
'name': fields.char('Name', size=128, required=True, select=True,
read=['base.group_user'] ),
And for status in xml:
<field name="name " attrs="{'readonly': [('state','=','done')]}"/>
There is another sweet way to achieve this. Create one functional field and in that check for group assigned to that user and do not store that field. In View use that field in attrs.
Let say in product you don't want to allow any user to modify Internal Reference if user does not belongs to Product Modify group.
Create one group.
<data noupdate="1" >
<record model="res.groups" id="group_product_modify">
<field name="name">Product Modify</field>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
</data>
Python file
class product_template(models.Model):
_inherit="product.template"
#api.one
def set_access_for_product(self):
self.able_to_modify_product = self.env['res.users'].has_group('product_extended_ecom_ept.group_product_modify')
able_to_modify_product = fields.Boolean(compute=set_access_for_product, string='Is user able to modify product?')
XMl file should be looking like,
<record model="ir.ui.view" id="product_template_update_internal_code_ept">
<field name="name">Product Template extension</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="model">product.template</field>
<field name="priority" eval="50" />
<field name="arch" type="xml">
<field name="default_code" position="before">
<field name="able_to_modify_product" invisible="1" />
</field>
<field name="default_code" position="attributes">
<attribute name="attrs">{'readonly' : [('able_to_modify_product','=',False)]}</attribute>
</field>
</field>
</record>
In case if you are using Odoo web client(GUI) instead of code then there is a bit unorthodox way to do it.
Just make a copy of the field which will contain same value as the original one(giving original field name in Related Field under Advanced Properties) and mark it as read-only.
Then you can hide original field from the users which cannot edit that field and hide the copy field from those who can edit by using groups attribute.

OpenERP always displays inherited view instead of original

Original views:
<record id='view_1' model='ir.ui.view'>
<field name="name">view.name</field>
<field name="model">my.object</field>
<field name="priority" eval="17"/>
<field name="type">form</field>
<field name="arch" type="xml">
...
</field>
</record>
inherited view from the original:
<record id='view_2' model='ir.ui.view'>
<field name="name">view.name</field>
<field name="model">my.object</field>
<field name="priority" eval="10"/>
<field name="inherit_id" ref="view_1"/>
<field name="type">form</field>
<field name="arch" type="xml">
...
</field>
</record>
So what happens is OpenERP always displays the inherited view ignoring the priority value. Is this expected behaviour, or there's something else I am missing?
If this is the expected behaviour, then please read further :-)
I have my.second.object with many2one field to my.object, and when I want to create my.object from this field, I want to open a bit different form view of my.object. I am trying to create a different view just for that purpose, but as you see it doesn't work so easily (or does it?).
Any help is appreciated.
Yes it is the expected behavior. The priority of a view only serves to select the main view to use when no specific view was requested. Inherited views are "patch views" that act like children of the view they inherit from, and may never be selected as "main views". They always apply on top of their parent view when that view is displayed.
If you want an alternative view for a certain model you should define a new stand-alone view that does not inherit from any other. If that view is meant to be used only in the context of the view of my.second.object, there are two common tricks to make OpenERP use it:
Define it inline in the form view of my.second.object, as a child of the <field> element. This may not work in all OpenERP clients depending on the version, and works best for declaring inline form views for o2m lines, normally.
Declare it as a stand-alone view with a low priority (e.g. 32) and put a magic context key in the many2one field of the my.second.object view that should use it. The magic key is in the form <view_type>_view_ref, and the value must be the XML ID of the desired view. This should work everywhere.
<!-- Example 1: inline form view -->
<form string="My second object">
<field name="my_object_id">
<form string="My object inline view">
<field name="name"/>
</form>
</field>
</form>
<!-- Example 2: explicitly ask for special view using magic key -->
<form string="My second object">
<field name="my_object_id" context="{'form_view_ref': 'module.my_object_form2'}"/>
</form>
For reference, have a look at this page of the OpenERP documentation that explains most of the options for making and using context-specific views.
NOTE: If you have used form_view_ref and from form view if you have
any button which is opening another form view of some other model then
it will give you error . It will try to open the same form view you
have passed in form_view_ref for another model also.
What "position" you defined in <field name="field_from_original_view">?
<record id='view_2' model='ir.ui.view'>
<field name="name">view.name</field>
<field name="model">my.object</field>
<field name="priority" eval="10"/>
<field name="inherit_id" ref="view_1"/>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="field_from_original_view" position="after" (or before)>
<field name="inherit1" />
<field name="inherit2" />
<field name="inherit3" />
</field>
</field>
</record>
There may not be a possibility to make an inherited form the standard form of your model so that it will be presented automatically.
BUT If you look at a specific task --> open an inherited form view for a one2many field e.g.; there is. Set the context variable 'form_view_ref' to 'MODULE.VIEW_ID'.
<field name="myOne2ManyField" context="{'form_view_ref': 'myModule.myInheritedView'}/>
Still works with Odoo 9.0.