Odoo How to add a editable tree view inside a new page? - odoo

I want to display the fields as editable in tree view inside a new tab in the sale.order? My code does not make any errors, but shows the fields in form view rather than tree view. How to correct it?
.xml
<record model="ir.ui.view" id="contract_custom">
<field name="name">sale.order.custom.form.inherited</field>
<field name="model">sale.order</field>
<field name="type">tree</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//page[#string='Other Information']" position="after">
<page string="Salesman Commission">
<tree editable="bottom">
<group>
<field name="user_select"/>
<field name="sales_value" on_change="on_change_commission(sales_value,sale_percent)"/>
<field name="sale_percent" on_change="on_change_commission(sales_value,sale_percent)"/>
<field name="sale_commission"/>
</group>
</tree>
</page>
</xpath>
</field>
</record>

Here is a possible solution
<record model="ir.ui.view" id="contract_custom">
<field name="name">sale.order.custom.form.inherited</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//page[#string='Other Information']" position="after">
<page string="Salesman Commission">
<field name="field_name"> <!-- field you want to show as tree -->
<tree editable="bottom">
<field name="user_select"/>
<field name="sales_value" on_change="on_change_commission(sales_value,sale_percent)"/>
<field name="sale_percent" on_change="on_change_commission(sales_value,sale_percent)"/>
<field name="sale_commission"/>
</tree>
</field>
</page>
</xpath>
</field>
</record>

Related

inheriting the inherit view in xml

In 'product.template' I need to add two fields for that I written one view in xml file but the problem is 'inherit_id' of 'accounts' is inheriting from 'product.product_template_form_view'.so how should I use inherit_id in my file.
I tried with below code but it was showing error please help me
account.product_view.xml code:
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">product.template.form.inherit</field>
<field name="model">product.template</field>
<field name="priority">5</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<page string="Sales" position="after">
<page string="Accounting" groups="account.group_account_invoice">
<group>
<label for="categ_id" string="Internal Category"/>
<div><field name="categ_id" colspan="3" nolabel="1"/></div>
</group>
<group name="properties">
<group>
<field name="property_account_income" domain="[('type','=','other')]" groups="account.group_account_user"/>
<field name="taxes_id" colspan="2" widget="many2many_tags" required="1"/>
</group>
<group>
<field name="property_account_expense" domain="[('type','=','other')]" groups="account.group_account_user"/>
<field name="supplier_taxes_id" colspan="2" widget="many2many_tags" required="1"/>
</group>
</group>
</page>
</page>
</field>
</record>
mycode:
<record model="ir.ui.view" id="gst_account_view_inherit">
<field name="name">gst_account_view_add_form_inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="account.product_template_form_view"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field/page/page/group/group/field[#name='taxes_id']" position="after">
<field name="cgst_id"/>
</xpath>
</data>
</field>
</record>
I need to add my 'cgst_id' field under 'taxes_id' field.
You don't need to give full path.
Try with these code:
<field name="taxes_id" position="after">
<field name="cgst_id"/>
</field>

Odoo not displayed field

I get a problem with displaying custom field in sale order view.
sale_order.py
...
'typeship' : fields.many2one('vips_shop.delivery', string="Type delivery", readonly=False),
'usersess' : fields.many2one('vips_vc.session', string="Session customer", readonly=False),
...
sale_order.xml
<record model="ir.ui.view" id="sale_order_usersess_form_view">
<field name="name">order.usersess</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<field name="client_order_ref" position="after">
<field name="usersess" string="User Session ID"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="sale_order_typeship_form_view">
<field name="name">order.typeship</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<field name="client_order_ref" position="after">
<field name="typeship" string="Type shipping"/>
</field>
</field>
</record>
As result i received this: field usersess displayed fine, typeship - not displayed.
Why is it happening? All fields for usersess and typeship is equal.
Thanks for Hardik Patadia
why are you having two separate views for showing two fields? Why are
you not showing both of them in single inherited view? I think view
priority may help you
When I'm showing in single view all displayed fine:
<record model="ir.ui.view" id="sale_order_usersess_form_view">
<field name="name">order.usersess</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<field name="client_order_ref" position="after">
<field name="usersess" string="User Session ID"/>
<field name="typeship" string="Type shipping"/>
</field>
</field>
</record>

how can I merge two tree views?

I have two tree views, how can I merge it in one but still have the same number of lines because my problem is that I wanna separate a line into two as i didn't find a solution I created the two tree views, so if there is another way to separate the line without creating the two views is better.
<record model="ir.ui.view" id="medical_lab_cash_tree_id">
<field name="name">cash</field>
<field name="model">medical.lab.patient</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field name="patient_id"/>
<field name="Amount_in_date"/>
<field name="Amount_In"/>
<field name="type_In"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="medical_lab_cash_tree_id2">
<field name="name">cash2</field>
<field name="model">medical.lab.patient</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field name="patient_id"/>
<field name="Amount_in_date1"/>
<field name="Amount_In1"/>
<field name="type_In1"/>
</tree>
</field>
</record>
We can inherit original view and add as needed fields in tree view.
For example:
<record id="medical_lab_cash_tree_id_extend" model="ir.ui.view">
<field name="name">medical.lab.cash.tree</field>
<field name="model">medical.lab.patient</field>
<field name="inherit_id" ref="module_name.medical_lab_cash_tree_id"/>
<field name="arch" type="xml">
<field name="type_In" position="after">
<field name="Amount_in_date1"/>
<field name="Amount_In1"/>
<field name="type_In1"/>
</field>
</field>
</record>
EDIT: You can replace your whole tree with following style.
<record id="medical_lab_cash_tree_id_extend" model="ir.ui.view">
<field name="name">medical.lab.cash.tree</field>
<field name="model">medical.lab.patient</field>
<field name="inherit_id" ref="module_name.medical_lab_cash_tree_id"/>
<field name="arch" type="xml">
<xpath expr="/tree" position="replace">
<tree>
<!-- Place your new field list -->
</tree>
</xpath>
</field>
</record>

I need to show Tree view instead of Form view after i inherit CRM Module to my Custom Module in Openerp

I had successfully inherited the CRM module into my custom module.I'm able to view the Form view but i need to show Tree view first.When i click Lead button in the main menu i'm able to show the form view (like in img1), but i need to show the tree view(like in img 2)
img 1
img 2
lead_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_lead_tree" model="ir.ui.view">
<field name="name">bala.lead</field>
<field name="model">bala.lead</field>
<field name="arch" type="xml">
<tree string="Leads">
<field name="contact_name"/>
<field name="lead_source"/>
<field name="lead_status"/>
</tree>
</field>
</record>
<!-- ========================This is Form layout===============================-->
<record id="crm_case_form_view_leads_extended" model="ir.ui.view">
<field name="name">CRM - Leads Form</field>
<field name="model">bala.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads" />
<field name="arch" type="xml">
<field name="email_from" postion="replace"/>
<field name="contact_name" position="replace"/>
<label for="contact_name" position="replace">
<br/>
</label>
<xpath expr="//label[#for='street']" position="before">
<field name="contact_name"/>
</xpath>
<xpath expr="//label[#for='section_id']" position="before">
<field name="lead_source"/>
<field name="lead_status"/>
</xpath>
<field name="function" position="replace"/>
<field name="partner_name" position="replace"/>
<field name="priority" position="replace"/>
<field name="categ_ids" position="replace"/>
<field name="partner_id" position="replace"/>
</field>
</record>
<!-- ===========================Action layout=========================== -->
<record id="new_lead" model="ir.actions.act_window">
<field name="name">Leads</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">bala.lead</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_lead_tree"/>
</record>
<!-- ===========================Menu Settings=========================== -->
<menuitem name ="Lead" id = "menu_lis_lab" />
<menuitem name="Leads" id="sub_lead" parent="menu_lis_lab" />
<menuitem name="Create Lead" id="create_lead" parent="sub_lead" action="new_lead"/>
</data>
</openerp>
then on click of any lead i'm getting img 3 (invalid view)and on click on Create button img 4 is being displyed , but i need to get img1
img 3
img 4
Add tree view to your xml file, and you can add more fields in this according to requirement,
<record id="view_lead_tree" model="ir.ui.view">
<field name="name">bala.lead</field>
<field name="model">bala.lead</field>
<field name="arch" type="xml">
<tree string="Leads">
<field name="contact_name"/>
<field name="lead_source"/>
<field name="lead_status"/>
</tree>
</field>
</record>
update your act_window
<record id="new_lead" model="ir.actions.act_window">
<field name="name">Lead</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">bala.lead</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_lead_tree"/>
</record>
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.