Record Rules, same object, different group, different domain - odoo-14

i have define code as
<!-- Category -->
<record model="ir.module.category" id="module_category_purchase_request">
<field name="name">Purchase Request</field>
<field name="parent_id" ref="base.module_category_purchase_management" />
<field name="sequence">5</field>
</record>
<!-- Groups -->
<record id="group_purchase_request_user" model="res.groups">
<field name="name">Purchase Request User (Own Document)</field>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]" />
<field name="category_id" ref="module_category_purchase_request" />
</record>
<record id="group_purchase_request_user_all_doc" model="res.groups">
<field name="name">Purchase Request User (All Document)</field>
<field name="implied_ids" eval="[(4, ref('group_purchase_request_user'))]" />
<field name="category_id" ref="module_category_purchase_request" />
</record>
<record id="group_purchase_request_user_assigned_to" model="res.groups">
<field name="name">Purchase Request User (Assigned To)</field>
<field name="implied_ids" eval="[(4, ref('group_purchase_request_user_all_doc'))]" />
<field name="category_id" ref="module_category_purchase_request" />
</record>
<record id="purchase_request_line_user_all_doc_rule" model="ir.rule">
<field name="name">Purchase Request Line User (All Document)</field>
<field name="model_id" ref="purchase_request.model_purchase_request_line" />
<field name="domain_force">[(1, '=', 1)]</field>
<field name="groups" eval="[(6,0, [ref('purchase_request.group_purchase_request_user_all_doc')])]" />
<field name="perm_read" eval="True" />
<field name="perm_write" eval="True" />
<field name="perm_create" eval="True" />
<field name="perm_unlink" eval="False" />
</record>
<record id="purchase_request_line_user_assigned_rule" model="ir.rule">
<field name="name">Purchase Request User (Assigned To)</field>
<field name="model_id" ref="purchase_request.model_purchase_request_line"/>
<field name="domain_force">[('assigned_to','=',user.id)]</field>
<field name="groups" eval="[(4, ref('purchase_request.group_purchase_request_user_assigned_to'))]"/>
<field name="perm_unlink" eval="0"/>
<field name="perm_write" eval="0"/>
<field name="perm_read" eval="1"/>
<field name="perm_create" eval="1"/>
</record>
But only first rules works. When group_purchase_request_user_assigned_to assign to user, its not working.
When i comment out first rule then purchase_request_line_user_assigned_rule is work perfectly.
I have to define four rules for four groups on a model with different domains. Please guide where is mistake.

Related

Group by field name

I want to do Group by by City but this possibility doesn't shows up. where is my mistake? there is field city in python file and it's showing up in tree view but not really in Group by
<openerp>
<data>
<record id="vpicktree" model="ir.ui.view">
<field name="name">Picking tree city</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.vpicktree"/>
<field name="arch" type="xml">
<field name="location_dest_id" position="after">
<field name="city"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="stock_picking_filter_city_search">
<field name="name">stock.picking.tree.filter_search</field>
<field name="model">stock.picking</field>
<field name="arch" type="xml">
<search string="City">
<filter name="city" string="City" context="{'group_by':'city'}"/>
</search>
</field>
</record>
<record id="action_picking_tree_city" model="ir.actions.act_window">
<field name="name">City</field>
<field name="res_model">stock.picking</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,kanban,calendar</field>
<field name="domain"></field>
<field name="context">{ 'group_by':'city' }</field>
<field name="search_view_id" ref="stock.view_picking_internal_search"/>
</record>
</data>
</openerp>
The group by must be in search view not on the action setion as you did, so you have to edit your search view:
<record model="ir.ui.view" id="stock_picking_filter_city_search">
<field name="name">stock.picking.tree.filter_search</field>
<field name="model">stock.picking</field>
<field name="arch" type="xml">
<search string="City">
<filter name="city" string="City" context="{'group_by':'city'}"/>
<group expand="0" string="Grouper par">
<filter string="City" icon="terp-personal" domain="[]" context="{'group_by':'city'}"/>
</group>
</search>
</field>
</record>

How to change default form of many2one field in odoo

Hi I have a mode Unit which inherits product.product.
I have defined the custom views for Unit and they work fine from the menu.
Property which inherits account.asset.assets has multiple units.
How do I call my custom unit views from the Property view?
When I click on Add an item I get the standard product form.
<record id="unit_form" model="ir.ui.view">
<field name="name">All Units</field>
<field name="model">product.product</field>
<field name="sequence">0</field>
<field name="arch" type="xml">
<form string="Unit">
<group>
<field name="property_id" widget="many2one" attrs="{'required': [('is_unit', '=', True)]}" />
<field name="is_unit" invisible="1" />
<field name="features_amenities_ids" placeholder="Features and Amenities" widget="many2many_tags" />
<field name="appliences_ids" placeholder="Apliences" widget="many2many_tags" />
<field name="lst_price" string="Rent" />
</group>
</form>
</field>
</record>
<record id="unit_tree" model="ir.ui.view">
<field name="name">All Units</field>
<field name="model">product.product</field>
<field name="arch" type="xml">
<tree string="Units" default_order='property_id,name'>
<field name="property_id" />
<field name="name" string="Unit#" />
</tree>
</field>
</record>
<record id="action_unit" model="ir.actions.act_window">
<field name="name">Units</field>
<field name="res_model">product.product</field>
<field name="view_mode">search, kanban,tree,form</field>
<field name="domain">[('is_unit', '=', True)]</field>
<field name="context">{'default_is_unit':1 }</field>
<field name="search_view_id" ref="unit_search"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a Unit.
</p>
<p>
Here you will find the all units.
</p>
</field>
</record>
<record id="action_unit_form" model="ir.actions.act_window.view">
<field name="act_window_id" ref="action_unit" />
<field name="view_id" ref="unit_form" />
<field name="view_mode">form</field>
<field name="sequence">10</field>
</record>
<record id="action_unit_tree" model="ir.actions.act_window.view">
<field name="act_window_id" ref="action_unit" />
<field name="view_id" ref="unit_tree" />
<field name="view_mode">tree</field>
<field name="sequence">9</field>
</record>
<record id="action_unit_kanban" model="ir.actions.act_window.view">
<field name="act_window_id" ref="action_unit" />
<field name="view_id" ref="product.product_kanban_view" />
<field name="view_mode">kanban</field>
<field name="sequence">8</field>
</record>
<menuitem action="action_unit" sequence="2"
id="menu_units_list" name="Units" parent="menu_property_sub"/>
This is from Property
<notebook colspan="4">
<page string="Units">
<field name="unit_ids" nolabel="1" widget="one2many" >
<tree string="Units">
<field name="name" string="Unit#"/>
</tree>
</field>
</page>
</notebook>
If you want to specify a view for many2one or one2many field:
<field name="m2o_id" context="{'form_view_ref': 'module_name.form_id'}"/>
hope this helps. there are other key word like tree_view_ref for tree views

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>

OpenERP 7: Set Default Value of Group By

I'm grouping POLine by Order Reference by Manual , it filtering the data as shown in below image.
<record id="view_purchase_line_search" model="ir.ui.view">
<field name="name">purchase.order.line.search</field>
<field name="model">purchase.order.line</field>
<field name="arch" type="xml">
<search string="Search Purchase Order">
<field name="order_id"/>
<field name="partner_id" string="Supplier" filter_domain="[('partner_id', 'child_of', self)]"/>
<group expand="1" string="Group By...">
<filter icon="terp-gtk-jump-to-rtl" string="Order Reference" domain="[]" context="{'group_by' :'order_id'}"/>
<filter string="Supplier" icon="terp-partner" domain="[]" context="{'group_by' : 'partner_id'}" />
</group>
</search>
</field>
</record>
<record id="view_purchase_line_list" model="ir.ui.view">
<field name="name">purchase.order.line.tree</field>
<field name="model">purchase.order.line</field>
<field name="arch" type="xml">
<tree string="Purchase Order Lines" create="false">
<field name="order_id"/>
<field name="partner_id" string="Supplier" />
<field name="product_id"/>
<field name="price_unit"/>
<field name="product_qty"/>
<field name="product_uom" groups="product.group_uom"/>
<field name="price_subtotal"/>
<field name="date_planned" widget="date" width="135"/>
<field name="state" invisible="1"/>
<field name="invoiced" invisible="1"/>
</tree>
</field>
</record>
<record id="action_purchase_line_list" model="ir.actions.act_window">
<field name="name">PO Tree Structure</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.order.line</field>
<field name="view_id" ref="view_purchase_line_list"/>
<field name="context">{'search_default_order_id':1 }</field>
<field name="search_view_id" ref="view_purchase_line_search"/>
</record>
<menuitem action="action_purchase_line_list" id="menu_purchase_list"
parent="menu_procurement_management"
sequence="0"/>
But i need this filter by default (i.e) when openning this window at first time it should groupped the data
Tried Below Code:
<field name="context">{'search_default_order_id':1 }</field>
I need "Order Reference" instead of Order Reference POOOO1 in search field.
Any Advice will be helpful.
update your code with this.
<filter name="groupby_order" icon="terp-gtk-jump-to-rtl" string="Order Reference"
domain="[]" context="{'group_by' :'order_id'}"/>
and pass <field name="context">{'search_default_groupby_order': 1}</field> in
act_window. Hope this will be useful to you.
try this, In your purchase_view.xml file search this id view_purchase_order_filter and than add below filter in Group By...
<filter icon="terp-gtk-jump-to-rtl" name="order_id" string="Order Reference" domain="[]" context="{'group_by' :'name'}"/>
Than find this id purchase_form_action and paste below context
<field name="context">{'search_default_order_id': 1}</field>
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"