OpenERP - implementing something similar to stock.picking.in - openerp-7

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>

Related

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 make scheduled action

In openerp there's a standard module named account_followup_print, in here there's a method called do_process which sends out all the payment followup emails.
I want it to automatically do this every day without having to click the button. So I have made the following:
<openerp>
<data>
<record forcecreate="True" id="ir_cron_project_task" model="ir.cron">
<field name="name">Run Payment Follow-up scheduler</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'account_followup.print'" name="model"/>
<field eval="'do_process'" name="function"/>
</record>
</data>
Yet this does not work, what am I doing wrong here? Thanks in advance!
Try following,
<record id = "ir_cron_project_task" model = "ir.cron">
<field name="name">Run Payment Follow-up scheduler</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'account_followup.print'" name="model"/>
<field eval="'do_process'" name="function"/>
<field eval="'()'" name="args"/>
</record>

OpenERP specify multiple view references on "view_id"

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>

Openerp 6.1 put product category in sale order line

I want to show the product category in the sale.order.line.tree view of a sales order with the following code which I wrote. It shows the category button under the group by button but on clicking it, I get the following error and I have don't know how to solve the bug: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"
AssertionError: Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True
Here is my code:
from osv import fields, osv<code>
class sales_order_line_category(osv.osv):
_name='sale.order.line'
_inherit='sale.order.line'
_columns={'categ_id': fields.related('product_id', 'categ_id', type='many2one', relation='product.categ_id'),
}
sales_order_line_category()
My view:
`<?xml version="1.0" encoding="utf-8"?>
<record id="view_sale_orderlinecategory" model="ir.ui.view">
<field name="name">sale.order.line.categoryinherit</field>
<field name="model">sale.order.line</field>
<field name="type">tree</field>
<field name="inherit_id" ref="sale.view_order_line_tree"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="categ_id" string="Category"/>
</field>
</field>
</record>
<record id="view_sale_orderlinecategory2" model="ir.ui.view">
<field name="name">sale.order.line.categoryinherit2</field>
<field name="model">sale.order.line</field>
<field name="type">search</field>
<field name="inherit_id" ref="sale.view_sales_order_uninvoiced_line_filter"/>
<field name="arch" type="xml">
<group expand="0" string="Group By..." >
<filter string="Category of Product" icon="terp-stock_symbol-selection" name="Category" context="{'group_by':'categ_id'}"/>
</group>
</field>
</record>
<record id="view_sale_orderlinecategory3" model="ir.ui.view">
<field name="name">sale.order.line.categoryinherit3</field>
<field name="model">sale.order,line</field>
<field name="type">search</field>
<field name="inherit_id" ref="sale.view_sales_order_uninvoiced_line_filter"/>
<field name="arch" type="xml">
<field name="name" position="before">
<field name="categ_id" string="Category"/>
</field>
</field>
</record>
</data>
`
WOuld you please try with following code replace?
'categ_id': fields.related('product_id', 'categ_id', type='many2one', relation='product.category', store=True),
Check that your field categ_id must be appear in tree view of sale.order.line where you try to do group by categ_id
Hope this help

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"