OpenERP specify multiple view references on "view_id" - odoo

I extended "hr.employee" class. (Inherited and gave the same name to the new one).
I defined two views (tree and form) and a menu:
<record model="ir.ui.view" id="my_employee_tree">
<field name="name">hr.employee.tree</field>
<field name="model">hr.employee</field>
<field name="arch" type="xml">
...
</field>
</record>
<record id="view_my_hr_employee_form" model="ir.ui.view">
<field name="name">hr.employee.form</field>
<field name="model">hr.employee</field>
<field name="arch" type="xml">
...
</field>
</record>
<record model="ir.actions.act_window" id="action_my_hr_employee_seq">
<field name="name">Angajati</field>
<field name="res_model">hr.employee</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_my_hr_employee_form"/>
</record>
<menuitem id="menu_project_hr_base" parent="menu_project_utcn_project_base_main" name="HR"/>
<menuitem action="action_my_hr_employee_seq" id="menu_action_employee_form" name ="Angajati" parent="menu_project_hr_base"/>
What I want to do is to get the original views from hr.employee view when i use the original module, and to get my defined views when i use my module.
As you can see, I have specified "view_id" reference to my form view, but how can i define a reference also to my tree view? And I want the tree view to be shown first, and form view as alternative. How can i specify this?
<field name="view_mode">tree,form</field>
seems not to work if i add reference to form view

You have to map your action with particular tree,form view.
Try this:
<record model="ir.actions.act_window" id="action_my_hr_employee_seq">
<field name="name">Angajati</field>
<field name="res_model">hr.employee</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<record model="ir.actions.act_window.view" id="act_hr_employee_tree_view">
<field eval="1" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="your_tree_view_id"/>
<field name="act_window_id" ref="action_my_hr_employee_seq"/>
</record>
<record model="ir.actions.act_window.view" id="act_hr_employee_form_view">
<field eval="2" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="your_form_view_id"/>
<field name="act_window_id" ref="action_my_hr_employee_seq"/>
</record>

Related

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>

Create two graph view for one model openerp

I want Create two graph view for one model openerp, I like to define Two menu for each one display a graph view,
exemple one content graph by country the ather by gender
You need to create two graph view in xml.
<record id="country_graph_id" model="ir.ui.view">
<field name="name">country.graph</field>
<field name="model">your.model</field>
<field name="arch" type="xml">
<graph string="By Country" type="bar">
<field name="your fields"/>
<field name="your_field2"/>
</graph>
</field>
</record>
<record id="country_gender_id" model="ir.ui.view">
<field name="name">gender.graph</field>
<field name="model">your.model</field>
<field name="arch" type="xml">
<graph string="By Gender" type="bar">
<field name="your_field3"/>
<field name="your_field4"/>
</graph>
</field>
</record>
after that, you need to create two actions and two menus like,
<record id="action_for_country_graph" model="ir.actions.act_window">
<field name="name">By Country</field>
<field name="res_model">your.model</field>
<field name="view_type">form</field>
<field name="view_mode">graph</field>
<field name="view_id" ref="country_graph_id"/>
</record>
<record id="action_for_gender_graph" model="ir.actions.act_window">
<field name="name">By gender</field>
<field name="res_model">your.model</field>
<field name="view_type">form</field>
<field name="view_mode">graph</field>
<field name="view_id" ref="gender_graph_id"/>
</record>
<menuitem action="action_for_country_graph" id="menu_country_graph_id"
sequence="1" name='Country Graph' parent='parent.menu'/>
<menuitem action="action_for_gender_graph" id="menu_gender_graph_id"
sequence="2" name='Gender Graph' parent='parent.menu'/>

OpenERP - implementing something similar to stock.picking.in

The way stock.picking.in is implemented in openERP is interesting. I am trying to do something similar with purchase orders.
Stock.picking.in inherits from stock.picking, customizes a few columns and defaults and declares the table as stock_picking. On the UI side, a form view is inherited from view_picking_form and the model used is stock.picking.in.
I am trying to do something similar by creating a special purchase order. The problem is that the form for the special PO never gets picked up. It always shows a dynamic view with all fields of the PO dumped in some default manner. The developer mode also does not show the right form view.
When I check Settings -> User Interface -> Views, it does show the view properly but doesn't display it when I create new special PO.
Here is the code:
class my_purchase_order(osv.osv):
_name = "purchase.order"
_inherit = "purchase.order"
_columns={
...
}
my_purchase_order()
class my_purchase_order_special(osv.osv):
_name = 'purchase.order.my_special'
_inherit = "purchase.order"
_table = "purchase_order"
_columns = {...
}
my_purchase_order_special()
<record id="po_my_special_form" model="ir.ui.view">
<field name="name">po_my_special_form</field>
<field name="model">purchase.order.my_special</field>
<field name="type">form</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
...
</field>
</record>
<record id="po_my_special_tree" model="ir.ui.view">
<field name="name">po_my_special_tree</field>
<field name="model">purchase.order.my_special</field>
<field name="arch" type="xml">
<tree fonts="bold:message_unread==True" colors="grey:state=='cancel';blue:state in ('wait','confirmed');red:state in ('except_invoice','except_picking')" string="Purchase Order">
<field name="message_unread" invisible="1"/>
<field name="name" string="Reference"/>
<field name="date_order" />
<field name="partner_id"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<field name="minimum_planned_date" invisible="context.get('quotation_only', False)"/>
<field name="origin"/>
<field name="amount_untaxed" sum="Total Untaxed amount" string="Untaxed"/>
<field name="amount_total" sum="Total amount"/>
<field name="state"/>
</tree>
</field>
</record>
<record id="action_po_my_special_tree" model="ir.actions.act_window">
<field name="name">Special Purchase Orders</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.order.my_special</field>
<field name="view_mode">tree,form,graph,calendar</field>
<field name="context">{}</field>
<field name="domain">[('state','=','draft')]</field>
<field name="search_view_id" ref="purchase.view_purchase_order_filter"/>
</record>
<record id="action_po_my_special_form" model="ir.actions.act_window.view">
<field eval="2" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="po_my_special_form"/>
<field name="act_window_id" ref="action_po_my_special_tree"/>
</record>
Please advise. Thanks in advance.
Turns out I was missing view records:
<record id="action_po_my_special_tree2" model="ir.actions.act_window.view">
<field eval="1" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="po_my_special_tree"/>
<field name="act_window_id" ref="action_po_my_special_tree"/>
</record>
<record id="action_po_my_special_form2" model="ir.actions.act_window.view">
<field eval="2" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="po_my_special_form"/>
<field name="act_window_id" ref="action_po_my_special_tree"/>
</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.

OpenERP 6.1 multiple views with different fields

I would like to create different 'kinds' of purchase order forms in OpenERP with different fields in each. Because of the inheritance model, I am assuming I can't inherit multiple children with disjoint fields. So I decided to create a superset child that had all the fields from all types of PO.
I then created different views, containing different fields from the inherited model.
But each of the views shows the same superset.
Please advise if I am doing this the right way or is there no other way but fields_view_get().
Thanks
Code:
class purchase_order_hash(osv.osv):
_name = 'purchase.order'
_inherit = 'purchase.order'
_columns={
'quality_code': fields....,
'rice_quality': fields....,
'packing_code': fields....,
'packing_type': fields....,
'late_payment': fields.float('Late Payment'),
'num_bags': fields.integer('Number of Bags'),
'unit_kg': fields.integer('Unit kg'),
'rate_': fields.float('Rate', digits=(16,2), help="Rate"),
'penalty_moisture': fields.float('Moisture Penalty', digits=(16,2), help="Percentage"),
'penalty_broken': fields.float('Broken Penalty', digits=(16,2), help="Percentage"),
'num_trucks': fields.integer('Number of Trucks'),
'test1': fields.integer('Test 1')
}
purchase_order_hash()
(views xml:)
<record id="purchase_order_hash_form" model="ir.ui.view">
<field name="name">purchase_order_hash_form</field>
<field name="model">purchase.order</field>
<field name="priority" eval="1" />
<field name="type">form</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<field name="origin" select="2" position="after">
<field name="quality_code"/>
<field name="rice_quality"/>
<field name="packing_code"/>
<field name="packing_type"/>
<field name="late_payment"/>
<field name="num_bags"/>
<field name="unit_kg"/>
<field name="rate_"/>
<field name="penalty_moisture"/>
<field name="penalty_broken"/>
<field name="num_trucks"/>
</field>
</field>
</record>
<record id="purchase_order_hash_form_test" model="ir.ui.view">
<field name="name">purchase_order_hash_form_test</field>
<field name="model">purchase.order</field>
<field name="priority" eval="2" />
<field name="type">form</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<field name="origin" select="2" position="after">
<field name="test1"/>
</field>
<field name="num_trucks" position="replace"/>
</field>
</record>
<record model="ir.actions.act_window" id="action_PO_hash">
<field name="name">action_PO_hash</field>
<field name="res_model">purchase.order</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="purchase_order_hash_form" />
</record>
<record model="ir.actions.act_window" id="action_PO_hash_test">
<field name="name">action_PO_hash_test</field>
<field name="res_model">purchase.order</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="purchase_order_hash_form_test" />
</record>
<menuitem id="menu_PO_hash" name="menu_PO_hash" action="action_PO_hash" parent="purchase.menu_procurement_management"/>
<menuitem id="menu_PO_hash_test" name="menu_PO_hash_test" action="action_PO_hash_test" parent="purchase.menu_procurement_management"/>
[Update Oct 16, 2012: view.xml - final working code:]
<record model="ir.actions.act_window" id="action_PO_hash">
<field name="name">action_PO_hash</field>
<field name="res_model">purchase.order</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
</record>
<record model="ir.actions.act_window" id="action_PO_hash_test">
<field name="name">action_PO_hash_test</field>
<field name="res_model">purchase.order</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
</record>
<record model="ir.actions.act_window.view" id="action_PO_hash_2">
<field name="sequence" eval="1"/>
<field name="view_mode">form</field>
<field name="view_id" ref="purchase_order_hash_form"/>
<field name="act_window_id" ref="action_PO_hash"/>
</record>
<record model="ir.actions.act_window.view" id="action_PO_hash_test_2">
<field name="sequence" eval="1"/>
<field name="view_mode">form</field>
<field name="view_id" ref="purchase_order_hash_form_test"/>
<field name="act_window_id" ref="action_PO_hash_test"/>
</record>
<menuitem id="menu_PO_hash" name="menu_PO_hash" action="action_PO_hash" parent="purchase.menu_procurement_management"/>
<menuitem id="menu_PO_hash_test" name="menu_PO_hash_test" action="action_PO_hash_test" parent="purchase.menu_procurement_management"/>
If you want to get different form for each action, then you have to create different forms without inheriting the view. Then for each form and tree view you newly create, please specify the window action. For example:
<record model="ir.actions.act_window.view" id="a_unique_name_as_id">
<field name="sequence" eval="2"/>
<field name="view_mode">form</field>
<field name="view_id" ref="your_view_ref_id"/><!--use ref="purchase_order_hash_form_test"-->
<field name="act_window_id" ref="your_action_reference_id"/><!--use ref='action_PO_hash_test'-->
</record>
To create different 'kinds' of purchase order forms you have to create different forms without inheriting them and provide reference of those forms in your action.
Write below tag in your action:
<field name="view_id" ref="id_of_your_form"/>
You can find so many examples in your addons.
To see example go to addons-6.1/account/account_view.xml: find with "view_id"