how to add fields in inherited notebook/page/field - xpath

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>

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>

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>

Hide lines in odoo treeview

I want to hide equipments that are not in an inventory. I've tried with
<record id="view_inventory_equipment_tree" model="ir.ui.view">
<field name="name">maintenance.equipment.tree</field>
<field name="model">maintenance.equipment</field>
<field name="domain">[('inventory_id','=',False)]</field>
<field name="arch" type="xml">
<tree string="Lot/Serial Number Inventory">
<field name="name"/>
<field name="serial_no"/>
<field name="category_id"/>
<field name="inventory_id"/>
<field name="cost"/>
</tree>
</field>
</record>
But that did not work, also there is no luck with
<field name="domain_force">[('inventory_id','=',False)]</field>
My model:
class MaintenanceEquipment(models.Model):
_name = 'maintenance.equipment'
_description = 'Equipment'
name = fields.Char('Equipment Name', required=True, translate=True)
inventory_id = fields.Many2one('maintenance.equipment.inventory', string='Equipment Inventory', track_visibility='onchange')
Put domain in action window record. Domain not work in directly with any view like tree or form view.

Odoo use both inherited Tree View and Parent Tree View

I created a special tree view for res.partner that help me modify records on the fly.
I put this view in a special Menu: test Configuration / Modification Rapide / Modification Contacts.
Everything is working fine expect that whenever there's a res.partner tree it's my tree view that is used.
Is there a way to use my custom tree view only from my Custom menu.
and every place else is the default tree view that is used ?
<record model="ir.ui.view" id="view_test_contact_tree">
<field name="name">res.partner.tree.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<field name="email" position="replace" />
<field name="phone" position="replace" />
<xpath expr="//tree[#string='Contacts']" position="attributes">
<attribute name="editable">bottom</attribute>
</xpath>
<xpath expr="/tree/field[#name='display_name']" position="before">
<field name="isBuyer" string="A"/>
<field name="isSeller" string="V"/>
<field name="isSupplier" string="F"/>
<field name="isMiddle" string="I"/>
<field name="isBackOffice" string="B"/>
</xpath>
<xpath expr="/tree/field[#name='display_name']" position="after">
<field name="mobile"/>
<field name="phone"/>
<field name="email"/>
</xpath>
</field>
</record>
<record model="ir.actions.act_window" id="action_res_partner_rel10">
<field name="name">Menu</field>
<field name="res_model">res.partner</field>
<field name="view_mode">tree</field>
</record>
<menuitem name="test Configuration" id="test_config_id" sequence="450"/>
<menuitem name="Modification Rapide" id="modif_id" parent="test_contact.test_config_id" sequence="20" />
<menuitem name="Modification Contacts" id="sub_gestion_modif_id" parent="modif_id" sequence="11" action="action_res_partner_rel10"/>
As I understand you want to show your own created tree view in this menu.
So for this you have to pass your create tree view in ref of action to open your tree view
Like:
<record id="action_quotations" model="ir.actions.act_window">
<field name="name">Quotations</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.order</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_quotation_tree"/> <======= your tree view id
<field name="view_mode">tree,form,calendar,graph</field>
<field name="context">{'search_default_my_sale_orders_filter': 1}</field>
<field name="domain">[('state','in',('draft','sent','cancel'))]</field>
</record>
you have not have to inherit exits view and change in this, instead of create new tree view and pass in actions
Hope this help

inheritance view and adding fields

i have candidat model inherit the hr.emplyee model
i want to display the form view of hr.employee and add fields of my child model candidat
class hr_candidat(models.Model):
_name='hr_recrutement.candidat'
_inherit='hr.employee'
_description="Informations du Candidats"
situation=fields.Selection(string="Situation",selection=[('Nouveau','Nouveau'),('RDV Thechnique','RDV Technique'),('Annulation','Annulationn')])
.
.
.
<record id="hr_recrutement_candidat_form" model="ir.ui.view">
<field name="name">Candidat</field>
<field name="model">hr_recrutement.candidat</field>
<field name="arch" type="xml">
<form string="Candidat">
<sheet>
<group>
<field name="situation" />
.
.
</group>
</sheet>
</form>
</field>
</record>
I dont know how to display fields of hr.employee + my fields of candidat in view
Just we should set the below code from the view xml file and also
add the depended module as hr in your openerp.py and set the view xml file path as well.
Add below code in your .py file
class hr_employee(models.Model):
_inherit='hr.employee'
_description="Informations du Candidats"
situation=fields.Selection(string="Situation",selection=[('Nouveau','Nouveau'),('RDV Thechnique','RDV Technique'),('Annulation','Annulationn')])
Add below code in your .xml file
<record id="hr_recrutement_caindidat_form" model="ir.ui.view">
<field name="name">Candidat</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form" />
<field name="arch" type="xml">
<xpath expr="field[#name='work_location']" position="after">
<field name="situation" />
</xpath>
</field>
</record>
Hear We have to set the position of your element based on xpath using before,after,inside,replace Attributes of xpath tag.
I hope my answer may helpful for you :)

Resources