First I Inherit hr.employee model in my custom module and add a field unique_id. Than in my custom module I inherit hr.employee search view for this unique_id field. But throw this error, Field "unique_id " does not exist in model "hr.employee"
Here is python file:
class HrUniqueId(models.Model):
_inherit = "hr.employee"
unique_id = fields.Char(string='ID', required=True, copy=False, readonly=True,
default=lambda self: _('New'))
Here is XMLfile:
<record model="ir.ui.view" id="hr_employee_search_inherit">
<field name="name">hr.employee.search.inherit</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_filter"/>
<field name="arch" type="xml">
<xpath expr="//search" position="inside">
<field name="unique_id" string="Employee Id"/>
</xpath>
</field>
</record>
Error massage is:
<search string="Employees">
<field name="name" string="Employee" filter_domain="['|', ('work_email', 'ilike', self), ('name', 'ilike', self)]"/>
<field name="category_ids" groups="hr.group_hr_user"/>
<field name="job_id"/>
<separator/>
Field "unique_id" does not exist in model "hr.employee"
View error context:
{'file': 'c:\\odoo\\fornew\\fornew\\odoo\\custom\\employee_details\\views\\employee_details.xml',
'line': 3,
'name': 'hr.employee.search.inherit',
'view': ir.ui.view(2023,),
'view.model': 'hr.employee',
'view.parent': ir.ui.view(366,),
'xmlid': 'hr_employee_search_inherit'}
Related
i suppose I've not fully undrestood the prototype inheritance in Odoo.
I try to inherit crm.lead
The Model :
` class learn_odoo(models.Model):
_name = 'learn_odoo.learn_odoo'
_inherit = ['crm.lead']
_description = 'learn_odoo.learn_odoo'
tag_ids = fields.Many2many('mail.channel','mail_channel_profile_crm', 'partner_id', 'tag_id')
job = fields.Char()`
The View :
`<record id="view_inherit_list_crm" model="ir.ui.view">
<field name="name">Learn Odoo</field>
<field name="model">learn_odoo.learn_odoo</field>
<field eval="1" name="priority"/>
<field name="inherit_id" ref="crm.crm_case_tree_view_oppor"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='name']" position="after">
<field name="job"/>
</xpath>
</field>
</record>
<record id="learn_odoo.action_window" model="ir.actions.act_window">
<field name="name">Learn Odoo</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">learn_odoo.learn_odoo</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
</p>
<p>
</p>
</field>
</record>`
The problem I encountered :
From your question, what i understood is you are trying to inherit crm.lead if i am right then please remove the _name = 'learn_odoo.learn_odoo'
you have to do as i am doing below:
class learn_odoo(models.Model):
_inherit = 'crm.lead'
tag_ids = fields.Many2many('mail.channel','mail_channel_profile_crm', 'partner_id', 'tag_id', string='Tag')
job = fields.Char('Job')
also in __manifest__.py file add crm in depends.
If you are not clear about inheritance please go through the odoo docs for inheritance from this Link for inheritance select your odoo version from top right corner for better results.
I am trying to make a duration character field visible 'only if' parent field called category_ids Many2Many field value "Non-Permanent" is selected. I have tried so many things but seems not working. Below is my code snippet
Model:
class hr_employee(models.Model):
_inherit = 'hr.employee'
identification_id = fields.Char(string="Employee No")
duration = fields.Char(string="Duration")
View:
<!-- Employee Form View -->
<record model="ir.ui.view" id="hr_custom_form_view">
<field name="name">hr.custom</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="groups_id" eval="[(4, ref('base.group_hr_user'))]"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='user_id']" position="after">
<field name="duration"/>
</xpath>
</field>
</record>
I have created one model, It contain 2 fields and one grid view. So I am trying to many2one for one field to create new id. Please let me know where i am making the mistake ?
.py code is here
from openerp.osv import fields, osv
class agile_portfolio(osv.Model):
_name = "agile.portfolio"
_rec_name = 'epic_owner'
_columns = {
'name': fields.char('Asset Name',),
'epic_owner':fields.many2one('Agile.assetid.name','Asset ID'),
'strat_id1' : fields.one2many('portfolio.grid','strat_id','Strategy Name'),
}
agile_portfolio()
class portfolio_grid(osv.Model):
_name = 'portfolio.grid'
_columns = {
'name' : fields.char('Part'),
'strat_code' : fields.char('Code'),
'strat_quty' : fields.char('Quantity '),
'strat_uom' : fields.char('UoM'),
'strat_id': fields.many2one('agile.portfolio','Strat Id'),
}
portfolio_grid()
class assetid_name(osv.Model):
_name = 'assetid.name'
_rec_name = 'asst_id'
_columns = {
'asst_id' : fields.char('Asset_ID'),
}
assetid_name()
.xml code is here
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--Portfolio View-->
<record id="agile_portfolio_form" model="ir.ui.view">
<field name="name">agile.portfolio.form</field>
<field name="model">agile.portfolio</field>
<field name="arch" type="xml">
<form string="AssetConfig">
<group>
<group>
<field name="name"/>
</group>
<group>
<field name="epic_owner"/>
</group>
</group>
<notebook>
<page string="Part Name">
<field name="strat_id1">
<form string="Part Name">
<group>
<field name="name"/>
<field name="strat_code"/>
<field name="strat_quty"/>
<field name="strat_uom"/>
</group>
</form>
<tree string="Part Name">
<field name="name"/>
<field name="strat_code"/>
<field name="strat_quty"/>
<field name="strat_uom"/>
</tree>
</field>
</page>
</notebook>
</form>
</field>
</record>
<record id="agile_portfolio_action" model="ir.actions.act_window">
<field name="name">AssetConfigs</field>
<field name="res_model">agile.portfolio</field>
<field name="view_type">form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Click to create a new portfolio</p>
</field>
</record>
<!--side menu's-->
<menuitem id="asset_config" name="AssetConfigs"/>
<menuitem id="portfolio_menu" name="AssetParts" parent="asset_config"/>
<menuitem id="portfolio_nxt_menu" name="AssetParts" parent="portfolio_menu" action="agile_portfolio_action"/>
</data>
</openerp>
openerp.py
{
'name': 'Agile',
'version':'1.0',
'description': """
Agile Methodology
- Portfolios
- Programs
- Projects
""",
'author': 'Suraj',
'depends': ['base_setup',],
'data': ['agile_view.xml',],
'installable': True,
'auto_install': False,
}
I think you have given the wrong model name in following field.
'epic_owner':fields.many2one('Agile.assetid.name','Asset ID')
Here instead of "Agile.assetid.name" you have to give "assetid.name" if you want to manage M2O of last model "assetid.name". I think no model have capital letter.
I think this will resolve your issue.
I create a new class fleet_agent that inherits from res.partner without problems
class fleet_agent(osv.Model):
_name = 'fleet.agent'
_inherit = ['res.partner']
_columns = {
'test': fields.char('Test', help='Test'),
}
then fleet_agent_form inherits base.view_partner_form also no problem
<record id="fleet_agent_form" model="ir.ui.view">
<field name="name">fleet.agent.form</field>
<field name="model">fleet.agent</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="state_id" position="before">
<field name="x" />
</field>
</field>
</record>
My problem is that this form does not appear as the formatting of view_partner_form and with all fields without any order ?
You have created a new model 'fleet.agent' by extending the base 'res.partner'. In order to show all the fields, you need to specify the fields in xml or use the classical inheritance by removing 'fleet.agent' and add your field to the base 'res.partner'.
class fleet_agent(osv.Model):
_inherit = 'res.partner'
_columns = {
'field': fields.char('Name', help='help'),
}
In xml file:
<field name="model">fleet.agent</field>
class Partner(model.Model):
_inherit = 'res.partner'
test = fields.Char(string='Test', help='Test'),
}
<record id="fleet_agent_form" model="ir.ui.view">
<field name="name">partner.test</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="test" />
</field>
</record>
Try following,
class fleet_agent(osv.Model):
_inherit = ['res.partner']
_columns = {
'test': fields.char('Test', help='Test'),
}
<record id="fleet_agent_form" model="ir.ui.view">
<field name="name">fleet.agent.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="state_id" position="before">
<field name="x" />
</field>
</field>
</record>
Remove _name = 'fleet.agent' from your python code, it's create new model, and in xml when you extend any parent model you must write parent model name into the view
<field name="model">res.partner</field>
So you will get extended functionality with your base class's functionality.
To copy table to your moule you should use inherits keyword instead of inherit. Also you have to copy view definition of partner form of base module and change it, extending wouldn't help you in creating new table.
Source
Update: additional information on ways os inheritance:
Update2: looks like you're on right way: there is a third way of inheritance: with inherit keyword and by specifying new _name for new model.
Use:
class res_partner(models.Model):
_inherit = 'res.partner'
test = fields.Char(string='test')`
Upgrade module from console:
./odoo-bin -u [module_name] -c [configuration_file
I am using openerp 6.1.Here in pos module there is no feature of selecting customer.I want to add this field.But i couldn't.Can anyone help me???
You can add extra fields by inheriting any model in your customized module.
You have to inherit the "pos.order" object & view.
Inherit 'pos.order' in your .py:
class pos_order(osv.osv):
_inherit = 'pos.order'
_columns = {
'customer_id': fields.many2one('res.partner', 'Customer'),
}
pos_order()
Above code will create a field in your database.
Now, To display your field in your form, inherit the view of 'pos.order' in your .xml,:
<record id="inherited_form_pos_view" model="ir.ui.view">
<field name="name">pos.order.form.inherit</field>
<field name="model">pos.order</field>
<field name="type">form</field>
<field name="inherit_id" ref="point_of_sale.view_pos_pos_form"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="customer_id"/>
</field>
</field>
</record>
Now, you can see "Customer" field in your pos.order form.