specifying the "editable" attribute in two different views - odoo

i have a model that defined a nomenclator, it have only one field :
'name': fields.char('Name',size = 50,required = True),
and its view is as follow:
<record model="ir.ui.view" id="view_df_t_r_m_resource_type_tree">
<field name="name">df.t.r.m.resource.type.tree</field>
<field name="model">df.t.r.m.resource.type</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Types" editable="bottom">
<field name="name" select = "1"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_df_t_r_m_resource_type_form">
<field name="res_model">df.t.r.m.resource.type</field>
<field name="view_type">form</field>
<field name="view_mode">tree</field>
</record>
I use this view to create types of product, but when i make a many2one field that reference the nomencaltor mode in other view and press the "Search" options i cant select the item because the editable property defined in the original view mess with the behavior i want
So: any ideas about how i can define the "editable" property in diferents views
PD: I tried to use this:
<field name="type_id" >
<tree>
<field name="name"/>
</tree>
</field>
but i dont know how to specify the "editable" property

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>

Odoo. How to create a view to extended model

I am very new in odoo and i really need your help.
I've extended res.partner :
class extendedPartner(models.Model):
_name = 'extended.partner'
_inherit = 'res.partner'
auto = fields.One2Many('partner.car', 'auto_name', 'Car', required=False)
class partnerCar(models.Model):
_name = 'partner.car'
auto_model = fields.Char('Model auto', size=20, required=True)
release = fields.Integer('Year of release', required=True)
auto_name = fields.Many2One('extended.partner', 'Car Name', required=True)
But I don't know how to write xml so that I could see all partner's cars and information about them
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<notebook position="inside">
<page string="Cars">
<!-- what should I write here? -->
</page>
</notebook>
</field>
</record>
Could you please help me? Thank you in advance.
UPD:
Is it right solution?
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="auto">
<tree>
<field name="auto_name"/>
<field name="auto_model"/>
<field name="release"/>
</tree>
</field>
</field>
</record>
You are almost there, since you inherit from another view and you injecting your view into the view you inherit from, you need to give your new view a "hook" in the parent view which it can use to attach its contents. So you use an xpath expression, and then you insert your field.
When you insert a relational field you can create so called embedded views. Here you have defined a tree view for your field. That means whenever your field will be rendered as a tree that is the tree that will be used, in your case the form.
You could also create a <form> after <tree> to be shown when clicked.
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="insert_x_path_xpression here" position="after, before etc"
<field name="auto">
<tree>
<field name="auto_name"/>
<field name="auto_model"/>
<field name="release"/>
</tree>
</field>
</xpath>
</field>
</record>

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>

How can I make an inline trees many2many field look okay in Odoo?

I have a tree view with a many2many field require_weekday:
<record model="ir.ui.view"
id="sale_order_email_collection_form">
<field name="name">sale.order_email.collection.form</field>
<field name="model">sale.order_email.collection</field>
<field name="arch" type="xml">
<form string="Collection">
<group>
<field name="name"/>
</group>
<field name="emails">
<tree string="Lines" editable="bottom">
<field name="required_weekday"/>
</tree>
</field>
</form>
</field>
</record>
When I click the many2many field it's basically unusable with some blue text overlaying the tree view making it impossible to tell what's going on.
Is it possible to make it work decent?
You can use widget="many2many_tags" in xml.
for example :
<field name="fields_name" widget="many2many_tags"/>
You can use widget="one2many" in xml.
This will change many2many form view to one2many as you want.
For Example:
<field name="your_many2many_field" widget="one2many">
<tree string="your string" editable="top/bottom">
<field name="your_fields"/>#Define all your fields for tree view
</tree>
</field?

How to define the action that occurs when clicking a tree view row in OpenERP?

I haven't been able to figure out how to define what action occurs when clicking a row in an OpenERP tree view. I've created a custom tree view for showing product suppliers (product.supplierinfo). Ideally I would like to open the form view for the product.product object with the Suppliers tab active and not a view of the product.supplierinfo object (as it does now). Is this possible? At a minimum I would like to open a popup window containing a view of the supplierinfo with a link to the parent product.
The supplier info view (default_code, manuf_name and manuf_code are all custom fields added to the product.supplierinfo model):
<record id="product_suppliers_tree_view" model="ir.ui.view">
<field name="name">product.suppliers.tree.view</field>
<field name="model">product.supplierinfo</field>
<field name="type">tree</field>
<field name="priority">16</field>
<field name="arch" type="xml">
<tree string="Product Suppliers">
<field name="default_code"/>
<field name="product_id"/>
<field name="name"/>
<field name="product_code"/>
<field name="manuf_name"/>
<field name="manuf_code"/>
</tree>
</field>
</record>
Supplier info action:
<record id="product_suppliers_action" model="ir.actions.act_window">
<field name="name">Product Suppliers</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.supplierinfo</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="product_suppliers_tree_view"/>
<field name="help">Here you can search for products by supplier information, including supplier and manufacturer name and part number. Each product can have one or more supplier sources.</field>
</record>