Odoo : make form fields show/hide based on dropdown - odoo

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

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>

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

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 version 6, My Timesheet form crashed after inherited

In OpenERP version 6, in my custom module, I changed the Timesheet form view by inheriting as my custom view below:
<record id="oit_hr_timesheet_sheet_form" model="ir.ui.view">
<field name="name">oit.hr.timesheet.sheet.form</field>
<field name="model">hr_timesheet_sheet.sheet</field>
<field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form" />
<field name="type">form</field>
<field name="arch" type="xml">
<data>
<button name="sign_in" position="replace"/>
<button name="sign_out" position="replace"/>
<field name="state_attendance" position="after">
<field name="day_attendance"/>
</field>
<field name="total_attendance_day" position="replace"/>
<field name="total_difference_day" position="replace"/>
<field name="total_timesheet_day" position="replace"/>
<field name="timesheet_ids" position="after">
<field name="day_difference"/>
<field name="day_timesheet"/>
</field>
<page string="By Day" position="replace" />
<notebook position="inside">
<page string="Time balance">
<group colspan="4" col="2" width="600">
<field name="time_account_balance"/>
<field name="working_hour"/>
<field name="attendance_hour"/>
<separator string="Timesheet numbers until the viewed working period." colspan="4" />
<field name="total_time_account_balance"/>
<field name="total_working_hour"/>
<field name="total_attendance_hour"/>
</group>
</page>
</notebook>
</data>
</field>
</record>
Then the Human Resources / Time Tracking / My Timesheet form totaly crash. But when I go to Administration / Customization / User Interface / Menu Items, and I choose "My Timesheet" menu item to fix its action from "ir.actions.server" to "ir.actions.act_window" and select object "hr_timesheet_sheet.sheet", then choose my view "oit.hr.timesheet.sheet.form" for object's form view, choose my view "oit.hr.timesheet.sheet.tree.simplified" for object's tree view.
Then I have "My Timesheet" form shown correctly.
Why is that? I think there is somethings in my view code not work with "My Timesheet" menu and "ir.actions.server" defined in file hr_timesheet_sheet/hr_timesheet_sheet_data.xml, Here I paste the openerp6 code in hr_timesheet_sheet_data.xml:
<record id="ir_actions_server_timsheet_sheet" model="ir.actions.server">
<field eval="5" name="sequence"/>
<field eval=""""code"""" name="state"/>
<field eval=""""ir.actions.server"""" name="type"/>
<field name="model_id" ref="model_hr_timesheet_current_open"/>
<field eval="[(6,0,[])]" name="child_ids"/>
<field eval=""""action = self.pool.get('hr.timesheet.current.open').open_timesheet(cr, uid, object.id, context)"""" name="code"/>
<field eval=""""True"""" name="condition"/>
<field eval=""""My Timesheet"""" name="name"/>
</record>
<record id="menu_act_hr_timesheet_sheet_form_my_current" model="ir.ui.menu">
<field name="name">My Timesheet</field>
<field eval="1" name="sequence"/>
<field name="parent_id" ref="hr_attendance.menu_hr_time_tracking"/>
<field name="icon">STOCK_JUSTIFY_FILL</field>
<field name="action" ref="ir_actions_server_timsheet_sheet"/>
</record>
Kindly please help me to have correct view code or a solution so that I will not need to change information for menu "My Timesheet" after I upgrade my custom module! thanks a lot!