Home > front end >  Inherited field does not exist in odoo
Inherited field does not exist in odoo

Time:12-18

I am working on a custom addon for the sales quotation form in odoo 15 while inheriting the sale.order.template model. I am trying to add a new field next to the quantity field but i keep getting a "Field [field-name] does not exist error" in relation to my views file. Here is the code in my views file:

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record id="sales_quotation_form_inherit" model="ir.ui.view">
<field name="name">sale.order.template.form.inherit</field>
<field name="model">sale.order.template</field>
<field name="inherit_id" ref="sale_management.sale_order_template_view_form"/>
 <field name="arch" type="xml">
    <xpath expr="//field[@name='sale_order_template_line_ids']/form[@string='Quotation Template Lines']/group/group[1]/div/field[@name='product_uom_qty']" positon="after">
     <field name='price'/>
     </xpath>
</field>
</record>
</data>
</odoo>

And my model.py code:

from odoo import models, fields

class SalesQuotation(models.Model):
    _inherit = "sale.order.template"
    price = fields.Many2one(string='Unit Price')

Can someone please point me in the right direction as to what may be the issue?

CodePudding user response:

Your view extension seems to change something on the lines of sale templates. So your model extension is done for the wrong model. Extend sale.order.template.line instead:

from odoo import models, fields

class SaleOrderTemplateLine(models.Model):
    _inherit = "sale.order.template.line"
    price = fields.Float(string='Unit Price')

Oh and shouldn't a price be a float? I already changed that in my code example.

CodePudding user response:

Your new field is a Many2one. You need to specify which table it refers to i.e.:

price = fields.Many2one('other.table...', string='Unit Price')

Also can't you just use a float field? In any case I would test with a plain float field first.

CodePudding user response:

There are few things to solve the problems:

The view inheritance

  1. Make sure your custom module depends on sale_management module where sale.order.template is defined:

manifest.py

...
'depends': ['sale_management'],
...
  1. Simplify the xpath:
...
<xpath expr="//field[@name='sale_order_template_line_ids']/form//field[@name='product_uom_qty']" positon="after">
    <field name='price' />
</xpath>
...

Model

Change your code to be like this:

from odoo import models, fields

class SalesQuotation(models.Model):
    _inherit = "sale.order.template"
    price = fields.Float(string='Unit Price')
  • Related