How do I add a selection field for country in information panel of product.product_normal_form_view
Here is the solution.
<record id="product_normal_form_view_inherit" model="ir.ui.view">
<field name="name">product.normal.form.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet/notebook/page[#string='Information']/group/group/field[#name='list_price']" position="after">
<field name="country_id"/>
</xpath>
</field>
</record>
Inherit product.template.
Your xml file should be:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="product_template_product_form_inherited" model="ir.ui.view">
<field name="name">product.template.product.form.inherited</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="//page[#string='Information']/group/group" position="inside">
<field name='country_id'/>
</xpath>
</field>
</record>
</data>
</openerp>
python file:
from openerp import models, fields
class product_template(models.Model):
_inherit = 'product.template'
country_id = fields.Many2one('res.country', 'Country')
Related
[![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>
I'm trying to add multi field to timesheet module to work as a tasks manage app i did inheritance to account.analytic.line the problem is in the view i got that error "AssertionError: Element odoo has extra content: record, line 4"
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="todo_timesheet_line_tree" model="ir.ui.view">
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
<field name="model">account.analytic.line</field>
<field name="arch" type="xml"/>
<field name="task_id" position="after">
<field name="priority"/>
</field>
<field name="company_id" groups="base.group_multi_company" position="before">
<field name="gov_department"/>
<field name="priority"/>
<field name="date_deadline"/>
</field>
</record>
</odoo>
from odoo import models, fields, api
class TodoTask(models.Model):
_inherit = 'account.analytic.line'
startdate=fields.Date('start Date', required=True, index=True, default=fields.Date.context_today)
date_deadline=fields.Date('Deadline', required=True, index=True, default=fields.Date.context_today)
priority = fields.Selection(selection=[('1', 'فوري'), ('2','هام جدا' ),('3','اقل اهمية')])
is_done = fields.Boolean ('Done?')
gov_department = fields.Many2one('govauthority','الجهة الحكومية')
class govauthority(models.Model):
govname = fields.Char('GOV_Department', size=25, required=True)
The error is in this line
<field name="arch" type="xml" />
You closed the tag while you really should not. Within this tag the actual XML body should be.
<record id="todo_timesheet_line_tree" model="ir.ui.view">
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree" />
<field name="model">account.analytic.line</field>
<field name="arch" type="xml">
<field name="task_id" position="after">
<field name="priority" />
</field>
<field name="company_id" groups="base.group_multi_company" position="before">
<field name="gov_department" />
<field name="priority" />
<field name="date_deadline" />
</field>
</field>
</record>
I have been trying to target an inherited element in the view, but it's not working for me.
So I have a view that inherits from the form view of hr.contract as shown here:
<record id="hr_contract_view_form_cayor" model="ir.ui.view">
<field name="name">name</field>
<field name="model">hr.contract</field>
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
<field name="arch" type="xml">
<data>
<!-- more elements define with xpath -->
<xpath expr="//field[#name='job_id']" position="after">
<field name="retirement_age"/>
</xpath>
...
<xpath expr="//page[#name='information']" position="after">
<page string="Allowances" groups="hr_payroll.group_hr_payroll_user">
<group>
<group name="allowances_group1">
...
<field name="car_allowance"/>
...
</group>
<group name="allowances_group2">
...
</group>
</group>
</page>
</xpath>
</data>
</field>
</record>
I have defined a new file to inherit from this form view, which adds a new field to it, as follows:
<record id="hr_contract.hr_contract_view_form_inherited" model="ir.ui.view">
<field name="name">hr.contract.grade.rank.form.inherit</field>
<field name="model">hr.contract</field>
<field name="inherit_id" ref="module.hr_contract_view_form_cayor"/>
<field name="arch" type="xml">
<data>
<xpath expr="//group[#name='allowances_group1']" position="inside">
<field name="medical_allowance" />
</xpath>
</data>
</field>
</record>
But when I upgrade my module, I get the following error:
Field `retirement_age` does not exist
How can I correctly inherit from the first one, and add my new field?
Any help will be greatly appreciated, thanks in advance.
Please try this code :
Python :
class HrContract(models.Model):
_inherit = 'hr.contract'
retirement_age = fields.Char(string="Retirement Age:")
XML :
<record id="hr_contract_view_form_cayor" model="ir.ui.view">
<field name="name">name</field>
<field name="model">hr.contract</field>
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
<field name="arch" type="xml">
<data>
<!-- more elements define with xpath -->
<xpath expr="//field[#name='job_id']" position="after">
<field name="retirement_age"/>
</xpath>
</data>
</field>
</record>
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>
I am trying to install a module, then I am getting below error.
AssertionError: Element openerp has extra content: data, line 2
What type of mistake I did for getting this error.
In which file I have to search for error rectify. I am using odoo9.
Files:
This is my xmlfile.xml
<data>
<record model="ir.ui.view" id="10">
<field name="name">model.name</field>
<field name="model">smp.model2</field>
<field name="arch" type="xml">
<form>
<sheet>
<group colspan="4">
<group colspan="2" cal="2">
<field name="name"/>
<field name="active"/>
</group>
<group colspan="2" cal="2">
<field name="age"/>
<field name="sal"/>
</group>
<group colspan="2" cal="2">
<field name="adharid"/>
<field name="cell"/>
</group>
<notebook colspan="4">
<page string="extrainfo"><field name="extrainfo"/></page>
<page string="temporaryaddress"><field name="temporaryaddress"/></page>
<page string="perminantaddress"><field name="perminantaddress"/></page>
</notebook>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="20">
<field name="name">model.name</field>
<field name="model">smp.model2</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="active"/>
<field name="age"/>
<field name="sal"/>
<field name="adharid"/>
<field name="cell"/>
<field name="extrainfo"/>
<field name="temporaryaddress"/>
<field name="perminantaddress"/>
</tree>
</field>
</record>
<record model ="ir.actions.act_window" id="action_smp_model2">
<field name="name">sampmodel</field>
<field name="res_model">smp.model2</field>
<field name="view_type">form</field>
<field name="viwe_mode">tree,form</field>
</record>
<menuitem id="smp_main_menu1" name="smp model2"/>
<menuitem id="subsmp_main_menu1" name="Sub sample model"
parent="smp_main_menu1"/>
<menuitem id="actsmp_main_menu" name="action smp model"
parent="subsmp_main_menu1" action="action_smp_model2"/>
</data>
</openerp>
This is my data.xml file
<data>
<record id='1' name="smp.model2">
<filed name="name">name1</filed>
<filed name="age">23</filed>
<filed name="cell">123456434</filed>
</record>
<record id='2' name="smp.model2">
<filed name="name">name1</filed>
<filed name="age">23</filed>
<filed name="cell">123456434</filed>
</record>
<record id='3' name="smp.model2">
<filed name="name">name1</filed>
<filed name="age">23</filed>
<filed name="cell">123456434</filed>
</record>
</data>
</openerp>
This is python_file.py
from openerp import models,fields
class model2(models.Model):
_name="smp.model2"
name=fields.Char(string="model name", requred=True, help="name of the
model")
active=fields.Boolean(String="Active")
age=fields.Integer(string="person age",help="age of person")
sal=fields.Integer(string="sal")
adharid=fields.Integer(string="Adhar Id")
cell=fields.Integer(string="phone number",requred=True)
extrainfo=fields.Text(string="Extra information")
temporaryaddress=fields.Text(string="Temporary address")
perminantaddress=fields.Text(string="perminant address")
This is __openerp__.py file
{
'name':'module12',
'description':'module12',
'author':'naveen',
'version':'9.0',
'depends':['base'],
'data':['xmlfile.xml','data.xml']
}
you have errors in a xml, example:
requred=True is required=True
<filed is <field