Problem with adding a custom field to existing view - 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>

Related

Create a new tree view in Odoo13

I´m trying to create a new tree view for the invoices in Odoo 13
my code looks like this:
<odoo>
<record model="ir.ui.view" id="new_invoice_tree">
<field name="name">New Tree</field>
<field name="model">account.move</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field name="custom_field_1"/>
<field name="custom_field_2"/>
</tree>
</field>
</record>
<record id="my_module.new_tree_action_window" model="ir.actions.act_window">
<field name="name">New tree</field>
<field name="res_model">account.move</field>
<field name="view_mode">tree</field>
<field name="view_id" ref="new_invoice_tree"/>
<field name="type">ir.actions.act_window</field>
<field name="domain">[('type','=','out_invoice')]</field>
</record>
<menuitem name="Libro de ventas"
id="my_module.new_tree_menu"
parent="my_parent_menu"
action="my_module.new_tree_action_window"
sequence="1"/>
</odoo>
But when I try to open the menu appears this error:
Rastreo de error:
Error: Unknown field state in domain
at Class.compute (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:322:55)
at evalModifier (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:1197:91)
at Class._evalModifiers (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:1200:44)
at Class._registerModifiers (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:1401:101)
at Class._renderBodyCell (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:2076:70)
at http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:2100:117
at Array.map (<anonymous>)
at Class._renderRow [as _super] (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:2100:80)
at Class._renderRow (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:2010:69)
at Class._renderRow (http://192.168.1.7:8070/web/content/312-75a923f/web.assets_common.js:3863:371)
I´m not sure how my domain should look like, what´s what I´m doing wrong?
The way to avoid this kind of error is by adding the "state" field with the attribute invisible as True, like this:
<odoo>
<record model="ir.ui.view" id="new_invoice_tree">
<field name="name">New Tree</field>
<field name="model">account.move</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field name="state" invisible="True"/>
<field name="custom_field_1"/>
<field name="custom_field_2"/>
</tree>
</field>
</record>
This error appears on databases that are working with the Enterprise version of Odoo.

AssertionError: Element odoo has extra content: record, line 4

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>

How to correctly inherit an inherited view in odoo?

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>

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 selection field for country in information panel

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')

Resources