How to change default form of many2one field in odoo - 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

Related

Odoo 10 - ParseError:

Odoo 10 -
I am trying to create an attendance module for partners rather than employees. I am copying code from the Attendance Module included in Odoo but am stuck and getting ParseError. The problem seems to be the action="base.res_partner_kanban_view"/>
The error is below
ParseError: "ir.actions.view" while parsing
/opt/odoo/odoo10/odoo-10.0/customaddons/gym_attendance/views/gym_attendance_view.xml:93,
near
<menuitem id="menu_gym_attendance_view_members_kanban" name="Members" parent="menu_gym_attendance_manage_attendances" sequence="15" action="base.res_partner_kanban_view
Below is my XML
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- views -->
<record id="view_attendance_tree" model="ir.ui.view">
<field name="name">gym.attendance.tree</field>
<field name="model">gym.attendance</field>
<field name="arch" type="xml">
<tree string="Member attendances">
<field name="partner_id"/>
<field name="check_in"/>
<field name="check_out"/>
</tree>
</field>
</record>
<record id="gym_attendance_view_form" model="ir.ui.view">
<field name="name">gym.attendance.form</field>
<field name="model">gym.attendance</field>
<field name="arch" type="xml">
<form string="Member attendances">
<sheet>
<group>
<field name="partner_id"/>
<field name="check_in"/>
<field name="check_out"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="gym_attendance_view_filter" model="ir.ui.view">
<field name="name">gym_attendance_view_filter</field>
<field name="model">gym.attendance</field>
<field name="arch" type="xml">
<search string="Gym Attendance Search">
<field name="partner_id"/>
<!-- <field name="department_id"/> -->
<filter name="today" string="Today" domain="[('check_in', '>=', datetime.datetime.now().replace(hour=0, minute=0, second=0)),('check_in', '<=', datetime.datetime.now().replace(hour=23, minute=59, second=59))]" />
<filter string="Current Month" domain="[('check_in', '>=', datetime.datetime.now().strftime('%Y-%m-01'))]" />
<separator/>
<filter string="No Check Out" domain="[('check_out', '=', False)]" />
<separator/>
<filter string="My Attendances" domain="[('employee_id.user_id.id', '=', uid)]" />
<group expand="0" string="Group By">
<filter name="member" string="Member" context="{'group_by':'partner_id'}"/>
<separator/>
<filter name="groupby_name" string="Month" context="{'group_by':'check_in'}"/>
</group>
</search>
</field>
</record>
<record id="gym_attendance_action_my_attendances" model="ir.actions.client">
<field name="name">Attendance</field>
<field name="tag">gym_attendance_my_attendances</field>
<field name="target">main</field>
</record>
<!-- actions -->
<record id="gym_attendance_action" model="ir.actions.act_window">
<field name="name">Attendances</field>
<field name="res_model">gym.attendance</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{"search_default_today":1}</field>
<field name="search_view_id" ref="gym_attendance_view_filter" />
<field name="help" type="html">
<p>The attendance records of your members will be displayed here.</p>
<p>Please make sure you're using the correct filter if you expected to see any.</p>
</field>
</record>
<record id="gym_attendance_action_my_attendances" model="ir.actions.client">
<field name="name">Gym Attendance</field>
<field name="tag">gym_attendance_my_attendances</field>
<field name="target">main</field>
</record>
<menuitem id="menu_gym_attendance_root" name="Attendances" sequence="90" web_icon="gym_attendance,static/description/icon.png"/>
<menuitem id="menu_gym_attendance_my_attendances" name="Gym Attendances" parent="menu_gym_attendance_root" sequence="10" action="gym_attendance_action_my_attendances"/>
<menuitem id="menu_gym_attendance_manage_attendances" name="Manage Attendances" parent="menu_gym_attendance_root" sequence="20"/>
<menuitem id="menu_gym_attendance_view_attendances" name="Attendances" parent="menu_gym_attendance_manage_attendances" sequence="10" action="gym_attendance_action"/>
<menuitem id="menu_gym_attendance_view_members_kanban" name="Members" parent="menu_gym_attendance_manage_attendances" sequence="15" action="base.res_partner_kanban_view"/>
</odoo>
I think you trying to call id of kanban view of res.partner instead of the id of action. Either you have to find out the correct id for the action or create a new one and use.
Here is the example id for Customer base.action_partner_form which available in base/res/res_partner.xml
I hope it will help you.
Try with : gym_attendance_action,
you need to specify the action to your menu-item and this action will call your view.
Your action:
<field name="search_view_id" ref="gym_attendance_view_filter" />
Your menu-item:
<menuitem id="id_menu_item" name="NameOfYourView" parent="model.model"
action="turnover_filtered_view_action..." />

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 : make form fields show/hide based on dropdown

My custom module view looks like this
<odoo>
<data>
<record model="ir.ui.view" id="session_form_view">
<field name="name">item.form</field>
<field name="model">inventory.item</field>
<field name="arch" type="xml">
<form string="Items Form">
<sheet>
<group>
<field name="name"/>
<field name="code"/>
<field name="department"/>
<field name="state"/>
</group>
<group>
<field name="measurement" position="attributes">
<attribute name="attrs">{'invisible': [('state', '=', True)]}</attribute>
</field>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="items_tree">
<field name="name">Item</field>
<field name="res_model">inventory.item</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<!-- <field name="context" eval="{'state':True}" /> -->
</record>
<menuitem id="main_openacademy_menu" name="Inventory"></menuitem>
<menuitem id="openacademy_menu" name="Store" parent="main_openacademy_menu"></menuitem>
<menuitem id="store_items_menu" name="Store items" parent="openacademy_menu" action="items_tree"/>
</data>
</odoo>
I have a simple model
I want to hide/show based on the department drop down. But some how for a lot of cases attrs is not working. I am begginer and using odoo 10.
Thanks

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 do I make a new tree view for res.partner without inheriting the default tree?

I need to make an alternate tree view for res.partner.
This is my code
<record id="custom_res_partner_tree_view" model="ir.ui.view">
<field name="name">CUSTOM</field>
<field name="model">res.partner</field>
<field eval="1" name="priority"/>
<field name="arch" type="xml">
<tree string="Contacts">
<field string="1" name="custom_field1"/>
<field string="2" name="custom_field2"/>
<field string="3" name="name"/>
<field string="4" name="street"/>
<field string="5" name="phone"/>
<field string="6" name="email"/>
</tree>
</field>
</record>
.......
<record model="ir.actions.act_window.view" id="custom_res_partner_tree_view_action">
<field eval="2" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="custom_res_partner_tree_view"/>
<field name="act_window_id" ref="custom_res_partner_action"/>
</record>
The code above works, but it behaves like it inherits the original tree view. It shows the columns which I don't specify. How do I make a completely new tree?
Additional details:
custom_res_partner.py
from osv import osv,fields
class custom_res_partner(osv.osv):
def _account_default(self, cr ,uid, context=None):
obj= self.pool.get('account.account')
ids = obj.search(cr, uid, [])
if(len(ids)>0):
return ids[0]
else:
return None
_name = "res.partner"
_inherit = "res.partner"
_columns = {
}
_defaults = {
'property_account_receivable' : _account_default,
'property_account_payable' : _account_default,
}
_sql_constraints = [
]
def init(self, cr):
pass
custom_res_partner()
custom_res_partner_view.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="custom_res_partner_tree_view" model="ir.ui.view">
<field name="name">Customer</field>
<field name="model">res.partner</field>
<field eval="10" name="priority"/>
<field name="arch" type="xml">
<tree string="Contacts">
<field string="KTP" name="ktp"/>
<field string="NPWP" name="npwp"/>
<field string="Name" name="name"/>
<field string="Address" name="street"/>
<field string="Telephone" name="phone"/>
<field string="Email" name="email"/>
</tree>
</field>
</record>
<record id="custom_res_partner_kanban_view" model="ir.ui.view">
<field name="name">res.partner.kanban.custom</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.res_partner_kanban_view" />
<field name="arch" type="xml">
<xpath expr="/kanban/field[#name='color']" position="after">
<field name="npwp" />
</xpath>
</field>
</record>
<record id="custom_res_partner_form_view" model="ir.ui.view">
<field name="name">res.partner.form</field>
<field name="model">res.partner</field>
<field eval="1" name="priority" />
<field name="arch" type="xml">
<form string="Customer" version="7.0">
<header></header>
<sheet>
<field name="image" widget='image' class="oe_left oe_avatar" options='{"preview_image": "image_medium", "size": [90, 90]}'/>
<div class="oe_title">
<div class="oe_edit_only">
<label for="name" string="Name"/>
</div>
<h1>
<field name="name" default_focus="1" placeholder="Nama" />
</h1>
<div class="oe_edit_only">
<label for="ktp" string="KTP"/>
</div>
<h1>
<field name="ktp" placeholder="KTP" />
</h1>
<div class="oe_edit_only">
<label for="npwp" string="NPWP"/>
</div>
<h1>
<field name="npwp" placeholder="NPWP" />
</h1>
</div>
<group>
<group>
<label for="street" string="Address"/>
<div>
<field name="street" placeholder="Address 1"/>
<field name="street2" placeholder="Address 2"/>
<div class="address_format">
<field name="city" placeholder="City" style="width: 40%%"/>
<field name="state_id" class="oe_no_button" placeholder="State" style="width: 37%%" options='{"no_open": True}' on_change="onchange_state(state_id)"/>
<field name="zip" placeholder="Zip" style="width: 20%%"/>
</div>
<field name="country_id" placeholder="Country" class="oe_no_button" options='{"no_open": True}'/>
</div>
</group>
<group>
<field name="phone" placeholder="misal +62224281110"/>
<field name="mobile"/>
<field name="fax"/>
<field name="email" widget="email"/>
</group>
</group>
</sheet>
<div class="oe_chatter"></div>
</form>
</field>
</record>
<record id="custom_res_partner_action" model="ir.actions.act_window">
<field name="name">Customer</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form</field>
<field name="context">{"search_default_customer":1}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
bla bla bla
</p>
</field>
</record>
<record model="ir.actions.act_window.view" id="custom_res_partner_kanban_view_action">
<field eval="1" name="sequence"/>
<field name="view_mode">kanban</field>
<field name="view_id" ref="custom_res_partner_kanban_view"/>
<field name="act_window_id" ref="custom_res_partner_action"/>
</record>
<record model="ir.actions.act_window.view" id="custom_res_partner_tree_view_action">
<field eval="2" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="custom_res_partner_tree_view"/>
<field name="act_window_id" ref="custom_res_partner_action"/>
</record>
<record model="ir.actions.act_window.view" id="custom_res_partner_form_view_action">
<field eval="3" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="custom_res_partner_form_view"/>
<field name="act_window_id" ref="custom_res_partner_action"/>
</record>
<menuitem id="menu_partner_form" parent="base.menu_sales" action="custom_res_partner_action" sequence="1"/>
</data>
</openerp>
Turns out the cause was because of this <field name="name">CUSTOM</field>. Coincidentally I changed content here to CUSTOM while in my original code it was still Customer. It somehow indicates that I inherited the original view. I don't know what's the purpose of the inherit_id then. But after I changed the name it works fine.