简体   繁体   English

odoo中不存在继承的字段

[英]Inherited field does not exist in odoo

I am working on a custom addon for the sales quotation form in odoo 15 while inheriting the sale.order.template model.我正在为 odoo 15 中的销售报价单定制插件,同时继承 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:还有我的 model.py 代码:

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?有人可以为我指出可能是什么问题的正确方向吗?

Your new field is a Many2one .您的新字段是Many2one You need to specify which table it refers to ie:您需要指定它引用哪个表,即:

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

Also can't you just use a float field?你也不能只使用一个float字段吗? In any case I would test with a plain float field first.在任何情况下,我都会先用一个普通的float字段进行测试。

Your view extension seems to change something on the lines of sale templates.您的视图扩展似乎改变了销售模板的行。 So your model extension is done for the wrong model.所以你的 model 扩展是为错误的 model 完成的。 Extend sale.order.template.line instead:改为扩展sale.order.template.line

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.我已经在我的代码示例中更改了它。

There are few things to solve the problems:解决问题的方法很少:

The view inheritance视图 inheritance

  1. Make sure your custom module depends on sale_management module where sale.order.template is defined:确保您的自定义模块依赖于定义sale.order.templatesale_management模块:

manifest .py清单.py

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM