Odoo 13 error in xml file while adding fields in custom module - odoo

I am getting this error while upgrading my custom module in odoo13 while upgrading it , the error is within this xml file.i have added somoe fields in xml file then it showing me this erro
error :
Odoo Server Error
Traceback (most recent call last):
File "/odoo/odoo-server/odoo/addons/base/models/ir_ui_view.py", line 392, in _check_xml
self.postprocess_and_fields(view.model, view_doc, view.id)
File "/odoo/odoo-server/odoo/addons/base/models/ir_ui_view.py", line 964, in postprocess_and_fields
self.raise_view_error(message, view_id)
File "/odoo/odoo-server/odoo/addons/base/models/ir_ui_view.py", line 592, in raise_view_error
raise ValueError(message)
ValueError: Field state does not exist
Error context:
View view.demo.form
[view_id: 1710, xml_id: gunalan_demo.request_form, model: car.request, parent_id: n/a]
models.py:
# -*- coding: utf-8 -*-
from odoo import models, fields, api , _
class gunalan_demo(models.Model):
_name = 'car.request' #Tables in DB =>car_request
_description = 'demo module'
name = fields.Char(string="Request_demo",required = True ,)
date_from = fields.Datetime(string='starting date',default=fields.Datetime.now(),)
date_to = fields.Datetime(string='Ending date',required=False,)
emplyoee_id= fields.Many2one(comodel_name="hr.employee", string="Emplyoee ", required=True,)
car_id = fields.Many2one(comodel_name="fleet.vehicle", string="Car ", required=True,)
state = fields.Selection(string="Status", selection=[('draft', 'Draft'), ('confirm', 'Confirm'),('validate','Validate'),('refuse','Refuse')('approved','Approved'),], default="draft", )
views.xml:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id ="request_form" model ="ir.ui.view">
<field name="name">view.demo.form</field>
<field name="model">car.request</field>
<field name="arch" type="xml">
<form string ="Car Request Form">
<header>
<!--<button name="" string="" class="oe_highlight" states="" type=""/>-->
<field name="state" widget="statusbar" statusbar_visible="draft,confirm,validate,refuse,approved"/>
</header>
<sheet>
<div class="oe_title">
<label for="name" class="oe_title_only"/>
<h1>
<field name="name" placeholder="Request Demo"/>
</h1>
</div>
<group>
<group>
<field name="date_from"/>
<field name="date_to"/>
</group>
<group>
<field name="emplyoee_id"/>
<field name="car_id"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
<record id='request_tree' model='ir.ui.view' >
<field name='name'>view.demo.tree</field>
<field name='model'>car.request</field>
<field name='arch' type='xml'>
<tree string='Car Request Tree'>
<field name="name"/>
<field name="emplyoee_id"/>
<field name="car_id"/>
<field name="date_from"/>
<field name="date_to"/>
</tree>
</field>
</record>
<record id="action_request_views" model="ir.actions.act_window">
<field name="name">Car Request</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">car.request</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Car Request
</p><p>
Click here to add
</p>
</field>
</record>
<!-- This Menu Item will appear in the Upper bar, That's why It needs NO parent or action -->
<menuitem id="menu_car_request_root" name="Car Request" sequence="10"/>
<menuitem id="menu_car_request_categ" name="Car Request" parent="menu_car_request_root" sequence="1"/>
<menuitem id="menu_car_request" name="Car Request" parent="menu_car_request_categ" action="action_request_views" sequence="1"/>

Make sure you have added your model.py file in init.py file. If you have added model.py inside model folder, then make sure model is given in init.py file.

Related

Odoo 10 adding field to sale order line

I am trying to code a module to provide a markup cell in each sale order line for quotes (Odoo 10). But I consistently get an error while loading the quote/sale order. Any help is welcomed.
This is the view:
<?xml version="1.0"?>
<odoo>
<record id="view_order_form_markup model" model="ir.ui.view">
<field name="name">sale.order.form.markup</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr='//field[#name="order_line"]/form/group/group/field[#name="price_unit"]' position="before">
<label for="markup" string="Markup"/><field name="markup"/>
<label for="markup_per" string="Markup (%)"/><field name="markup_per"/>
</xpath>
<xpath expr='//field[#name="order_line"]/tree/field[#name="price_unit"]' position="before">
<label for="markup" string="Markup"/><field name="markup"/>
<label for="markup_per" string="Markup (%)"/><field name="markup_per"/>
</xpath>
</field>
</record>
</odoo>
And the model:
# -*- coding: utf-8 -*-
from odoo import api, fields, models
import odoo.addons.decimal_precision as dp
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
markup = fields.Float(compute='_compute_markup', digits=dp.get_precision('.2f%'), store=False, readonly=True)
markup_per = fields.Float(compute='_compute_markup_per', digits=dp.get_precision('.2f%'), store=False, readonly=False)
#api.depends('price_unit', 'purchase_price')
def _compute_markup(self):
for record in self:
if record.price_unit and record.purchase_price:
record.markup = record.price_unit - record.purchase_price
#api.depends('price_unit', 'purchase_price')
def _compute_markup_per(self):
for record in self:
if record.purchase_price > 0:
record.markup_per = 100.0 * (record.price_unit - record.purchase_price) / record.purchase_price
#api.onchange('markup_per')
def _onchange_markup_per(self):
if self.markup_per:
if self.markup_per > -9999.99 and self.markup_per < 9999.99:
self.price_unit = self.purchase_price * (1 + self.markup_per / 100.0)
But I am getting this error when I open a quote/sales order:
Uncaught TypeError: Type is not a constructor
http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2119
Traceback: TypeError: Type is not a constructor
at for_ (http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2119:1208)
at http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2035:312
at Function..map..collect (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:13:270)
at _.(anonymous function) [as map] (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:69:526)
at Class.setup_columns (http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2035:261)
at Class. (http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2036:480)
at http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2099:11
at Object. (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:3202:136)
at Object. (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:547:681)
at fire (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:541:299)
Just change your xml view like this.
<?xml version="1.0"?>
<odoo>
<record id="view_order_form_markup model" model="ir.ui.view">
<field name="name">sale.order.form.markup</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr='//field[#name="order_line"]/form/group/group/field[#name="price_unit"]' position="before">
<label for="markup" string="Markup"/><field name="markup"/>
<label for="markup_per" string="Markup (%)"/><field name="markup_per"/>
</xpath>
<xpath expr='//field[#name="order_line"]/tree/field[#name="price_unit"]' position="before">
<field name="markup" string="Markup"/>
<field name="markup_per" string="Markup (%)"/>
</xpath>
</field>
</record>
</odoo>
Remove <label> from tree view definition. Use attribute string to change label.
Try below code.
<record id="view_order_form_markup_model" model="ir.ui.view">
<field name="name">sale.order.form.markup</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr='//field[#name="order_line"]/form/group/group/field[#name="price_unit"]' position="before">
<label for="markup" string="Markup"/><field name="markup"/>
<label for="markup_per" string="Markup (%)"/><field name="markup_per"/>
</xpath>
<xpath expr='//field[#name="order_line"]/tree/field[#name="price_unit"]' position="after">
<field name="markup"/>
<field name="markup_per" string="Markup (%)"/>
</xpath>
</field>
</record>
Hope this will help you.

odoo many2many show selection Odoo10

we have a list of items in one model named us_inventory_line. We have another model named ladings...
class inventory_line(models.Model):
# ...
lading_item = fields.Many2one('res.lading', ondelete='set null', string="lading", index=True)
class Lading(models.Model):
# ...
us_inventory_line_item = fields.One2many(comodel_name='rodals.us_inventory_line', string="shippments", inverse_name='lading_item')
In the form, we have just simply put the field that represent one2many:
<!-- Form -->
<record model="ir.ui.view" id="us_inventory_line_form_view">
<field name="name">lading.form</field>
<field name="model">rodals.lading</field>
<field name="arch" type="xml">
<form string="Invetory Line Form">
<sheet>
<group>
<field name="delivery_date"/>
<field name="us_inventory_line_item"/>
</group>
</sheet>
</form>
</field>
</record>
When the application is opened, when the user opens the lading page, he is only able to add new us_inventory_line.
How do we go about in order to connect the tow ? Like the user need to choose, from a list of us_inventory_line that does not have a lading (because if its has lading, this means that its already shipped).
Thank you very much for the help !
<record model="ir.ui.view" id="us_inventory_line_form_view">
<field name="name">lading.form</field>
<field name="model">rodals.lading</field>
<field name="arch" type="xml">
<form string="Invetory Line Form">
<sheet>
<group>
<field name="delivery_date"/>
<field name="us_inventory_line_item">
<tree string="US Inventory Item">
<field name="lading_item"/>
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>

How can I delete the "sheet" node keeping its content intact?

I would like to remove the node <sheet></sheet> from a form view. For instance, I have this view:
<record id="view_account_period_form" model="ir.ui.view">
<field name="name">account.period.form</field>
<field name="model">account.period</field>
<field name="arch" type="xml">
<form string="Account Period">
<header>
[...]
</header>
<sheet>
<group>
<group>
<field name="name"/>
<field name="fiscalyear_id" widget="selection"/>
<label for="date_start" string="Duration"/>
<div>
<field name="date_start" class="oe_inline" nolabel="1"/> -
<field name="date_stop" nolabel="1" class="oe_inline"/>
</div>
</group>
<group>
<field name="code"/>
<field name="special"/>
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
I would like to convert it in this other view without the node, but keeping all the elements within it:
<record id="view_account_period_form" model="ir.ui.view">
<field name="name">account.period.form</field>
<field name="model">account.period</field>
<field name="arch" type="xml">
<form string="Account Period">
<header>
[...]
</header>
<group>
<group>
<field name="name"/>
<field name="fiscalyear_id" widget="selection"/>
<label for="date_start" string="Duration"/>
<div>
<field name="date_start" class="oe_inline" nolabel="1"/> -
<field name="date_stop" nolabel="1" class="oe_inline"/>
</div>
</group>
<group>
<field name="code"/>
<field name="special"/>
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
</group>
</group>
</form>
</field>
</record>
Is that possible or I need to override the complete code again?
Maybe something similar to:
<xpath expr="//form/sheet" position="replace">
<!-- [...] -->
</xpath>
There is an open issue in Git Hub asking for solving this here, but I think that maybe anyone knows how to do it without programming a new feature in Odoo.
Just use fields_view_get:
from lxml import etree
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = models.Model.fields_view_get(self, cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
if view_type == 'form':
doc = etree.XML(res['arch'])
for sheet in doc.xpath("//sheet"):
parent = sheet.getparent()
index = parent.index(sheet)
for child in sheet:
parent.insert(index, child)
index += 1
parent.remove(sheet)
res['arch'] = etree.tostring(doc)
return res
improved in case of oe_chatting presence
I am from the future. I found a module time ago that made wider forms in a much easier way: web_sheet_full_width. It works for all the forms. The sheet is not removed, but the result is almost the same because the form fits in the entire screen with full width.

getting error like relation "_unknown" does not exist?

I have created one model, It contain 2 fields and one grid view. So I am trying to many2one for one field to create new id. Please let me know where i am making the mistake ?
.py code is here
from openerp.osv import fields, osv
class agile_portfolio(osv.Model):
_name = "agile.portfolio"
_rec_name = 'epic_owner'
_columns = {
'name': fields.char('Asset Name',),
'epic_owner':fields.many2one('Agile.assetid.name','Asset ID'),
'strat_id1' : fields.one2many('portfolio.grid','strat_id','Strategy Name'),
}
agile_portfolio()
class portfolio_grid(osv.Model):
_name = 'portfolio.grid'
_columns = {
'name' : fields.char('Part'),
'strat_code' : fields.char('Code'),
'strat_quty' : fields.char('Quantity '),
'strat_uom' : fields.char('UoM'),
'strat_id': fields.many2one('agile.portfolio','Strat Id'),
}
portfolio_grid()
class assetid_name(osv.Model):
_name = 'assetid.name'
_rec_name = 'asst_id'
_columns = {
'asst_id' : fields.char('Asset_ID'),
}
assetid_name()
.xml code is here
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--Portfolio View-->
<record id="agile_portfolio_form" model="ir.ui.view">
<field name="name">agile.portfolio.form</field>
<field name="model">agile.portfolio</field>
<field name="arch" type="xml">
<form string="AssetConfig">
<group>
<group>
<field name="name"/>
</group>
<group>
<field name="epic_owner"/>
</group>
</group>
<notebook>
<page string="Part Name">
<field name="strat_id1">
<form string="Part Name">
<group>
<field name="name"/>
<field name="strat_code"/>
<field name="strat_quty"/>
<field name="strat_uom"/>
</group>
</form>
<tree string="Part Name">
<field name="name"/>
<field name="strat_code"/>
<field name="strat_quty"/>
<field name="strat_uom"/>
</tree>
</field>
</page>
</notebook>
</form>
</field>
</record>
<record id="agile_portfolio_action" model="ir.actions.act_window">
<field name="name">AssetConfigs</field>
<field name="res_model">agile.portfolio</field>
<field name="view_type">form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Click to create a new portfolio</p>
</field>
</record>
<!--side menu's-->
<menuitem id="asset_config" name="AssetConfigs"/>
<menuitem id="portfolio_menu" name="AssetParts" parent="asset_config"/>
<menuitem id="portfolio_nxt_menu" name="AssetParts" parent="portfolio_menu" action="agile_portfolio_action"/>
</data>
</openerp>
openerp.py
{
'name': 'Agile',
'version':'1.0',
'description': """
Agile Methodology
- Portfolios
- Programs
- Projects
""",
'author': 'Suraj',
'depends': ['base_setup',],
'data': ['agile_view.xml',],
'installable': True,
'auto_install': False,
}
I think you have given the wrong model name in following field.
'epic_owner':fields.many2one('Agile.assetid.name','Asset ID')
Here instead of "Agile.assetid.name" you have to give "assetid.name" if you want to manage M2O of last model "assetid.name". I think no model have capital letter.
I think this will resolve your issue.

How to add autoincremental field in OpenERP 7?

I searched and modified the source code of a simple custom module of openerp, I give the code below
init.py
import sim
openerp.py
{
'name': 'Student Information Management',
'version': '0.1',
'category': 'Tools',
'description': """This module is for the Student Information Management.""",
'author': 'Mr Praveen Srinivasan',
'website': 'http://praveenlearner.wordpress.com/',
'depends': ['base'],
'data': ['sim_view.xml'],
'demo': [],
'installable': True,
'auto_install': False,
'application': True,
}
sim_view.xml
<?xml version="1.0"?>
<openerp>
<data>
<!-- ============== student================= -->
<!-- 1st part of the sim_view start-->
<record model="ir.ui.view" id="student_form">
<field name="name">Student</field>
<field name="model">sim.student</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Student" version="7.0">
<group>
<field name="reg_no"/>
<field name="student_name"/>
<field name="father_name"/>
<field name="gender"/>
<field name="contact_no"/>
<field name="address"/>
</group>
</form>
</field>
</record>
<!-- 1st part of the sim_view end-->
<!--2nd part of the sim_view start-->
<record model="ir.ui.view" id="student_tree">
<field name="name">Student</field>
<field name="model">sim.student</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Student">
<field name="reg_no"/>
<field name="student_name"/>
<field name="father_name"/>
<field name="gender"/>
<field name="contact_no"/>
<field name="address"/>
</tree>
</field>
</record>
<!--2nd part of the sim_view end-->
<!-- 3rd part of the sim_view start-->
<record model="ir.actions.act_window" id="action_student">
<field name="name">Student</field>
<field name="res_model">sim.student</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<!--3rd part of the sim_view end-->
<!--4th part of the sim_view start-->
<menuitem name="SIM/Student/StudentInfo" id="menu_sim_student"
action="action_student"/>
<!--4th part of the sim_view end-->
</data>
</openerp>
sim.py
**
from openerp.osv import fields, osv
class student(osv.osv):
_name = "sim.student"
_description = "This table is for keeping personal data of student"
_columns = {
'reg_no': fields.integer('Registration Number',size=7,required=True),
'student_name': fields.char('Student Name',size=25,required=True),
'father_name': fields.char("Father's Name",size=25),
'gender':fields.selection([('male','Male'),('female','Female')],'Gender'),
'contact_no':fields.char('Contact Number',size=10),
'address':fields.char('Address',size=256)
}
_sql_constraints = [
('uniq_name', 'unique(reg_no)', 'This Reg.No is number already registered!')
]
student()
**
All is working good, but I want to add an auto incremented registration Id field. I searched the Internet how to do it, but I can't get a proper solution. Please help me.
After creating sequence file you can add this function to your sim.py
def create(self, cr, uid, vals, context=None):
sequence=self.pool.get('ir.sequence').get(cr, uid, 'reg_code')
vals['reg_no']=sequence
return super(student, self).create(cr, uid, vals, context=context)
This function will work properly
Create a record in ir.sequence. First make your reg_no field to char.
<record id="seq_type_1" model="ir.sequence.type">
<field name="name">REG Type</field>
<field name="code">reg_code</field>
</record>
<record id="seq_1" model="ir.sequence">
<field name="name">reg</field>
<field name="code">reg_code</field>
<field name="prefix">REG</field>
<field name="padding">3</field>
</record>
In your py file you can define when to generate the sequence. Either in defaults to get default reg number or override the create method and call the sequence Or in any other methods:
_defaults = { 'reg_no': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'reg_code'), }