Odoo 9: Add custom field to HR Contract using module - odoo-9

I'm new to Odoo. All I need is to add a simple custom field (i.e. Allowance) to HR Contract. I have followed the tutorial given in https://www.odoo.com/forum/help-1/question/add-custom-fields-to-sales-order-45074 but it for sales order. I tried to apply the concept to HR Contract but there is no success. I keep receive errors when I tried to install.
See below for the current code.
__openerp__.py
{
'name': "hr_contract_customfield",
'summary': """
Add custom field to HR Contract""",
'description': """
Add custom field to HR Contract
""",
'author': "Author",
'website': "http://www.companyname.com",
'category': 'Uncategorized',
'version': '0.1',
'depends': ['base','hr'],
'data': [
'views/views.xml',
'views/templates.xml',
],
'demo': [
'demo/demo.xml',
],
}
models.py
from openerp import models, fields, api
class hr_contract_customfield(models.Model):
_inherit = 'hr.contract'
x_allowance_field = fields.Float('Allowance')
templates.xml
<openerp>
<data>
<record id="my_view_hr_contract_form_inherit" model="ir.ui.view">
<field name="name">my.view.hr.contract.form.inherit</field>
<field name="model">hr.contract</field>
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='wage']" position="after">
<field name="x_allowance_field"/>
</xpath>
</field>
</record>
</data>
</openerp>
Any advice?
Error appeared when tried to install
Error details:
Field `x_allowance_field` does not exist
Error context:
View `my.view.hr.contract.form.inherit`
[view_id: 882, xml_id: n/a, model: hr.contract, parent_id: 584]
None" while parsing /opt/odoo/addons/custom/hr_contract_customfield/views/templates.xml:3, near
<record id="my_view_hr_contract_form_inherit" model="ir.ui.view">
<field name="name">my.view.hr.contract.form.inherit</field>
<field name="model">hr.contract</field>
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='wage']" position="after">
<field name="x_allowance_field"/>
</xpath>
</field>
</record>

Related

Problem with adding a custom field to existing view

[![enter image description here][1]][1]I have a problem with adding a new field to the sale order view of odoo12. I have created a new module. I hope that you can help me.
Below the code of my view form
<odoo>
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml"></field>
<field name="payment_term_id" position="after">
<field name="additional_note"/>
</field>
</record>
</odoo>```
when i try to install the new module i have the following error:
File "src\lxml\etree.pyx", line 3557, in lxml.etree._Validator.assert_
AssertionError: Element odoo has extra content: record, line 3
[1]: https://i.stack.imgur.com/e1DOw.png
The problem is in the <field name="arch" type="xml"></field> line: the <field> tag is closed, and your additional_note field is declared outside of it.
Try this code instead:
<odoo>
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<!-- Leave the 'arch' field open -->
<field name="arch" type="xml">
<!-- Put your custom field and its position inside the 'arch' field.
Use 'xpath' tag to create a more precise positioning -->
<xpath expr="//group/group/field[#name='payment_term_id']" position="after">
<field name="additional_note"/>
</xpath>
<!-- Now, close the 'arch' field -->
</field>
</record>
</odoo>
The view is not correctly defined, you can refer to account_analytic_view.
The view definition should be (according to the provided link):
<odoo>
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<data>
<field name="payment_term_id" position="after">
<field name="additional_note"/>
</field>
</data>
</field>
</record>
</odoo>

odoo v12 xpath new field not visible

i have a issue with odoo v12.
manifest file
'depends': ['stock','product'],
# always loaded
'data': [
'views/stock_production_lot_views.xml',
# 'security/ir.model.access.csv',
],
The module class
class ProductionLot(models.Model):
_inherit = '''stock.production.lot'''
newfield = fields.Char(string='New field', store=False)
Right now the form view file
<record id="production_lot_form_view" model="ir.actions.act_window">
<field name="name">view.production.lot.form.my</field>
<field name="res_model">stock.production.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form" />
<field name="priority">10</field>
<field name="arch" type="xml">
<xpath expr="//group/field[#name='product_id']" position="after">
<field name="newfield />
</xpath>
</field>
My issue is the module was successfully installed but the field niewfield is not visible into my form.
(if i use model="ir.ui.view" ... name="model", i got an error message, that's why i use model="ir.actions.act_window" ..... name="res_model").
Help please ans thanks .
https://www.odoo.com/fr_FR/forum/aide-1/question/odoo-v12-xpath-not-visible-145057

Odoo 8 - Calendar View Error

Get an error: Odoo Warning - Insufficient fields for Calendar View! and the calendar, of course,never shows up.
I'm missing something but don't know what;
I have this view fragment:
<record model="ir.actions.act_window" id="action_soft_apps_event">
<field name="name">Applications</field>
<field name="res_model">soft.app</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="arch" type="xml">
<calendar string="App Releases" color="dev_id" date_start="release" date_delay="1">
<field name="name"/>
<field name="desc"/>
<field name="downloads"/>
<field name="valid"/>
</calendar>
</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Register a new App</p>
</field>
</record>
And the model is the following:
class soft_app(osv.osv):
"""Apps"""
_name = 'soft.app'
_columns = {
'name': fields.char('Name', size=32, required=True, help='This is the name of the application'),
'desc': fields.text('Description', help='A brief description of the application'),
'dev_id': fields.many2one('soft.dev','Developer',required=True, help='The app\'s developer'),
'release': fields.datetime('Release Date', help='The date that the app was released'),
'downloads': fields.integer('Download Count', help='Total amount of downloads'),
'user_ids': fields.many2many('soft.user','soft_user_app_rel','app_id','user_id','Users Downloaded', help='Users that have downloaded the app'),
'os_ids': fields.many2many('soft.os','soft_os_app_rel','app_id','os_id','Operating Systems', help='Operating systems survey data'),
'valid': fields.boolean('Is Valid', help='Checks if the app is validated')
}
soft_app()
I think you have to create separate calendar view and action
Like:
Calendar view
<record id="view_invoice_line_calendar" model="ir.ui.view">
<field name="name">account.invoice.calendar</field>
<field name="model">account.invoice</field>
<field name="arch" type="xml">
<calendar string="Invoices" color="journal_id" date_start="date_invoice">
<field name="partner_id"/>
<field name="amount_total"/>
</calendar>
</field>
</record>
Action
<record id="action_invoice_tree" model="ir.actions.act_window">
<field name="name">Invoices</field>
<field name="res_model">account.invoice</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="view_id" ref="invoice_tree"/>
<field name="context">{'type':'out_invoice'}</field>
<field name="search_view_id" ref="view_account_invoice_filter"/>
</record>

add a custom field to existing tree view Odoo 8

I want to add one field call validator to customer invoice (account_invoice).
openerp.py:
'depends': ['base','account'],
my model:
class account_invoice_validator(models.Model):
_inherit = "account.invoice"
validator = fields.Char()
my view:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<!-- Model: account.invoice -->
<record id="view_account_invoice_customer_validator" model="ir.ui.view">
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='user_id']" position="after">
<field name="validator"/>
</xpath>
</field>
</record>
</data>
</openerp>
the validator column was added to database but i couldn't show it on the tree view (list). What do i miss?
Can you try like this?
<record id="view_account_invoice_customer_validator" model="ir.ui.view">
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_tree"/>
<field name="arch" type="xml">
<xpath expr="//tree/field[#name='user_id']" position="after">
<field name="validator"/>
</xpath>
</field>
</record>
Try this:
<record id="view_account_invoice_customer_validator" model="ir.ui.view">
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_tree"/>
<field name="arch" type="xml">
<xpath expr="/tree/field[#name='user_id']" position="after">
<field name="validator"/>
</xpath>
</field>
</record>

how to add fields in inherited notebook/page/field

I have inherited 'sales order' from 'sales' module.
I need to add two extra fields inside 'Order Lines' tab.
.py
class SalesOrderInherit(models.Model):
_inherit = "sale.order"
type = fields.Selection([('appointment', 'Appointment'), ('walkin', 'Walk-In')], string="Type")
I need to add type field inside 'Order Lines' tab.
Which table should i inherit?
How to write to add above field.
Got Solution
<record id="inherit_sale_order_line" model="ir.ui.view">
<field name="name">inherit.sale.order.line.form.view</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="priority" eval="50" />
<field name="arch" type="xml">
<xpath expr="//field[#name='order_line']/tree/field[2]" position="after">
<field name="type"/>
</xpath>
</field>
</record>

Resources