So I'm trying to inherit hr.employee in odoo but there's an error that I don't know why since I'm doing it like in the tutorials. (Link to the tutorial)
Here's my code: in
employee.py
class Employee(models.Model):
""" Class Employee """
_inherit = 'hr.employee'
_description = 'A custom class of employee'
esia = fields.Float(digits=(12, 2))
cnaps = fields.Float(digits=(12, 2))
employees.xml
<record model="ir.ui.view" id="employee_form_view">
<field name="name">employee.form</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<notebook position="inside">
<page string="Sécurité Sociale">
<group>
<field name="cnaps"/>
<field name="esia"/>
</group>
</page>
</notebook>
</field>
</record>
<record model="ir.actions.act_window" id="employee_list_action">
<field name="name">Employees</field>
<field name="res_model">hr.employee</field>
<field name="view_mode">tree,form</field>
</record>
And what I get as error when trying to upgrade my module is:
Invalid model name 'hr.employee' in action definition
Thanks to #Amal, I defined hr module in _manifest_.py then it worked.
Added hr here: 'depends': ['base', 'hr'],
Related
I am trying to inherit res.users in odoo 12. But I am getting mixing apples and oranges error. I want to create a new table having the fields of res.users models.
model.py
class SaleIndividual(models.Model):
_name = 'sale.individual'
_inherit = 'res.users'
individual_description = fields.Char()
view.xml
<odoo>
<record id="view_form_sale_custom_individual" model="ir.ui.view">
<field name="name">Individual Form</field>
<field name="model">sale.individual</field>
<field name="inherit_id" ref="auth_signup.res_users_view_form"/>
<field name="arch" type="xml">
<field name="login" position="after">
<field name="individual_description" />
</field>
</field>
</record>
</odoo>
error:
raise TypeError("Mixing apples and oranges: %s in %s" % (item, self))
TypeError: Mixing apples and oranges: sale.individual(<odoo.models.NewId object at 0x123018048>,) in res.users()
First Method:
If you want t inherit res users then please follow the below steps:
class ResUsers(models.Model):
_inherit = 'res.users'
individual_description = fields.Char()
view.xml
<odoo>
<record id="view_form_sale_custom_individual" model="ir.ui.view">
<field name="name">Individual Form</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="auth_signup.res_users_view_form"/>
<field name="arch" type="xml">
<field name="login" position="after">
<field name="individual_description" />
</field>
</field>
Second Method:
if you want create new model then follow the steps below:
class SaleIndividual(models.Model):
_name = 'sale.individual'
_inherit = 'res.users'
individual_description = fields.Char()
Need to create a new view file with out inheriting res users view file for this case.
<odoo>
<record id="view_form_sale_custom_individual" model="ir.ui.view">
<field name="name">Individual Form</field>
<field name="model">sale.individual</field>
<field name="arch" type="xml">
<form>
<field name="individual_description" />
</form>
</field>
I am using Odoo 11 and get the below error when installing a custom module. This is a module that is working in Odoo 10. I cant figure out where I am going wrong.
Field `custom_discount_product_id2` does not exist
Error context:
View `pos.config.custom.discount.form.view`
[view_id: 1029, xml_id: pos_custom.view_pos_config_form_custom_discount, model: pos.config, parent_id: 730]
None" while parsing /odoo/custom/addons/pos_custom/views/pos_custom_sale_view.xml:22, near
<record model="ir.ui.view" id="view_pos_config_form_custom_discount">
<field name="name">pos.config.custom.discount.form.view</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[#id='title']" position="after">
<group string="Custom Discount">
<field name="custom_discount_product_id2"/>
</group>
</xpath>
</field>
</record>
Here is my sale.py file
from odoo import api, fields, models
class PosConfig(models.Model):
_inherit = 'pos.config'
custom_discount_product_id2 = fields.Many2one('product.product', string='Custom Discount Product')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
And here is the view file.
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_pos_config_form_custom_discount">
<field name="name">pos.config.custom.discount.form.view</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[#id='title']" position="after">
<group string="Custom Discount">
<field name="custom_discount_product_id2" />
</group>
</xpath>
</field>
</record>
</data>
</openerp>
I've checked other modules, restarted server, but for some reason the field is not created.
Make sure <your_module>/__init__.py contains:
from . import models
and that <your_module>/models/__init__.py contains:
from . import sale
I am trying to extend the view which displays packages in Odoo 10 so it display also the product_id:
<record id="stock_view_picking_form_enhanced" model="ir.ui.view">
<field name="name">stock_view_picking_form_enhanced</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="priority">20</field>
<field name="arch" type="xml">
<xpath expr="//field[#name='pack_operation_product_ids']/tree/field[#name='package_id']" position="after">
<field name="package_id.product_id"/>
</xpath>
</field>
</record>
So basically I am looking to display related field product_id from pack_operation_product_id.
Which is the right approach to implement this?
First you must include the related field in your inherited python class.
class StockPicking(models.Model):
_inherit = "stock.picking"
product_id = fields.Many2one('product.product', related='package_id.product_id', string='Product', store=True)
Then in XML you can write like the following:
<record id="stock_view_picking_form_enhanced" model="ir.ui.view">
<field name="name">stock_view_picking_form_enhanced</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="priority">20</field>
<field name="arch" type="xml">
<xpath expr="//field[#name='pack_operation_product_ids']/tree/field[#name='package_id']" position="after">
<field name="product_id"/>
</xpath>
</field>
</record>
I am very new in odoo and i really need your help.
I've extended res.partner :
class extendedPartner(models.Model):
_name = 'extended.partner'
_inherit = 'res.partner'
auto = fields.One2Many('partner.car', 'auto_name', 'Car', required=False)
class partnerCar(models.Model):
_name = 'partner.car'
auto_model = fields.Char('Model auto', size=20, required=True)
release = fields.Integer('Year of release', required=True)
auto_name = fields.Many2One('extended.partner', 'Car Name', required=True)
But I don't know how to write xml so that I could see all partner's cars and information about them
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<notebook position="inside">
<page string="Cars">
<!-- what should I write here? -->
</page>
</notebook>
</field>
</record>
Could you please help me? Thank you in advance.
UPD:
Is it right solution?
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="auto">
<tree>
<field name="auto_name"/>
<field name="auto_model"/>
<field name="release"/>
</tree>
</field>
</field>
</record>
You are almost there, since you inherit from another view and you injecting your view into the view you inherit from, you need to give your new view a "hook" in the parent view which it can use to attach its contents. So you use an xpath expression, and then you insert your field.
When you insert a relational field you can create so called embedded views. Here you have defined a tree view for your field. That means whenever your field will be rendered as a tree that is the tree that will be used, in your case the form.
You could also create a <form> after <tree> to be shown when clicked.
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="insert_x_path_xpression here" position="after, before etc"
<field name="auto">
<tree>
<field name="auto_name"/>
<field name="auto_model"/>
<field name="release"/>
</tree>
</field>
</xpath>
</field>
</record>
my problem is that when I use inheritance, records from parent class don't display
this is my class :
class LabTestCashRegister (models.Model):
_name = "medical.cash"
_inherit = "medical.lab.patient"
comment = fields.Text(store=True,size=2000000)
type_In = fields.Char(default='Reste', readonly=False)
and this is my view:
<record model="ir.ui.view" id="medical_lab_cash_tree_id">
<field name="name">cash</field>
<field name="model">medical.cash</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field name="patient_id"/>
<field name="cat"/>
<field name="test_type_id"/>
<field name="state_money"/>
<field name="Avance"/>
<field name="Amount"/>
<field name="Reste"/>
<field name="comment"/>
<field name="type_In"/>
</tree>
</field>
</record>
(Amount, Reste, Avance,state_money exist on the parent class)
Change your LabTestCashRegister to
class LabTestCashRegister (models.Model):
_inherit = "medical.lab.patient"
comment = fields.Text(store=True,size=2000000)
type_In = fields.Char(default='Reste', readonly=False)
This should work for you. Let me know if not.