I have the following code in my xml view file that inherits from another view:
<xpath expr="//notebook/page[#string='Accounting']/group" position="replace"></xpath>
but it gives me the error:
Element "'<xpath expr="//notebook/page[#string='Accounting']/group">'" cannot be located in parent view
although the 'Accounting' tab is in the parent view. What I am doing wrong? Thanks for your help.
Here is the view I inherited from:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<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"/>
</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"/>
</group>
</group>
</page>
</page>
</field>
</record>
<record id="product_template_search_view" model="ir.ui.view">
<field name="name">product.template.search</field>
<field name="model">product.template</field>
<field name="mode">primary</field>
<field name="inherit_id" ref="product.product_template_search_view"/>
<field name="arch" type="xml">
<field name="product_variant_ids" position="after">
<field name="categ_id"/>
</field>
<xpath expr="//group[#string='Group by...']" position="inside">
<filter string='Category' icon="terp-stock_symbol-selection" domain="[]" context="{'group_by' : 'categ_id'}"/>
</xpath>
</field>
</record>
<record id="view_category_property_form" model="ir.ui.view">
<field name="name">product.category.property.form.inherit</field>
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_form_view"/>
<field name="arch" type="xml">
<data>
<xpath expr="//group[#name='parent']" position="inside">
<group name="account_property" string="Account Properties" colspan="2">
<field name="property_account_income_categ" domain="[('type','<>','view'),('type','<>','consolidation')]"/>
<field name="property_account_expense_categ" domain="[('type','<>','view'),('type','<>','consolidation')]"/>
</group>
</xpath>
</data>
</field>
</record>
</data>
</openerp>
and here is the view that inherited previous view and gave me the error:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="product_config_form_view" model="ir.ui.view">
<field name="name">product.config.form.view</field>
<field name="model">product.template</field>
<field name="type">form</field>
<field name="inherit_id" ref="product.product_template_only_form_view" />
<field name="arch" type="xml">
<label for="name" position="replace">
<label for="name" invisible="1"/>
</label>
<field name="name" position="replace">
<div style="font-size:10pt;">
<label for="class_id" string="Item Class" />
</div>
<div style="font-size:10pt;">
<field name="class_id" colspan="3" nolabel="1" on_change="onchange_class_id(class_id)"
/> </div>
<div style="font-size:10pt;">
<label for="name" string="Item Description"/>
</div>
<div style="font-size:10pt;" >
<field name="name" colspan="3" nolabel="1"/>
</div>
</field>
<field name="default_code" position="replace" >
<field name="default_code" string="Item Number" />
</field>
<xpath expr="//notebook/page[#string='Accounting']/group" position="replace">
</xpath>
</field>
</record>
<record id="product_config_tree_view" model="ir.ui.view">
<field name="name">product.config.tree.view</field>
<field name="model">product.class</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Product">
<field name="default_code" string="Class ID" colspan="3" nolabel="1" />
<field name="name" string="Class Description" colspan="3" nolabel="1"/>
</tree>
</field>
</record>
<record id="class_search_view" model="ir.ui.view">
<field name="name">class.search.view</field>
<field name="model">product.class</field>
<field name="arch" type="xml">
<search string="Class">
<field name="name" string="Class Description" filter_domain="['|',('default_code','ilike',self),
('name','ilike',self)]" />
</search>
</field>
</record>
</data>
</openerp>
You start your xpath expression with //notebook.
So your xpath selects all notebook elements, regardless of where they appear in the document.
But I don't see any xml tag that contains notebook.
This expression:
<xpath expr="//page[#string='Accounting']/group" position="replace"></xpath>
selects all the group elements under:
<page string="Accounting" groups="account.group_account_invoice">
Related
how to inherit correctly field
I inherited a field but did not appear as required, because it is inside a div
<group name="email_template_and_project" position="before">
<group name="sale_condition" string="Sale Conditions">
<label for="warranty" groups="stock.group_production_lot"/>
<div groups="stock.group_production_lot">
<field name="warranty" class="oe_inline"/> months
</div>
<label for="sale_delay"/>
<div>
<field name="sale_delay" attrs="{'readonly':[('sale_ok','=',False)]}" class="oe_inline" style="vertical-align:baseline"/> days
</div>
</group>
</group>
<record model="ir.ui.view" id="view_product_template_es_">
<field name="name">product.template.es.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='sale_delay']" position="after">
<div>
<field name = 'time_pose' /> hours
</div>
</xpath>
</field>
</record>
<record model="ir.ui.view" id="view_product_template_es_">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='sale_delay']/parent::div" position="after">
<label for="time_pose"/>
<div>
<field name="time_pose" class="oe_inline"/> hours
</div>
</xpath>
</field>
</record>
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>
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
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 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.