我是Odoo v8.0的初学者。我想在模块“sale”中添加一个自定义字段。错误是“字段type_customer
不存在”
所以我的代码在这里。
__init__.py
:
from . import modify_type_quotation
__openerp__.py
:
{
'name' : "Modify report template",
'description' : """Modify report template for Quotation/Sale report""",
'author' : "Nhu Van Tran",
'category' : "Tools",
'depends' : ['sale'],
'data' : ['modify_create_quotation.xml'],
'demo' : [],
'installable' : True,
}
modify_type_quotation.py
:
# -*- coding: utf-8 -*-
from openerp import models, fields
class modify_print_content(models.Model):
_inherit = "sale.order"
_description = "Modify Print Content"
type_customer = fields.selection([
('Commercial', 'Commercial Customer'),
('Residential', 'Risidential Customer'),
], string = "Type of Customer", help = "Type of Customer", default = "Commercial", required = True)
和modify_create_quotation.xml
:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model = "ir.ui.view" id = "modify_view_sale">
<field name ="name">sale.order.form</field>
<field name = "model">sale.order</field>
<field name = "inherit_id" ref="sale.view_order_form"></field>
<field name="arch" type="xml">
<xpath expr="/form/sheet/group/group[2]/field[@name='client_order_ref']" position="after">
<field name="type_customer">Type customer</field>
</xpath>
</field>
</record>
</data>
</openerp>
答案 0 :(得分:1)
我认为错误是fields.selection
你在哪里制作了&#39;小写,这可能是错误。
type_customer = fields.Selection([
('Commercial', 'Commercial Customer'),
('Residential', 'Risidential Customer')
], string = "Type of Customer", help = "Type of Customer", default = "Commercial", required = True)
确保重新启动odoo服务器,以使这些事情生效。
答案 1 :(得分:1)
xpath中的字段可能更短:
<xpath expr="/form/sheet/group/group[2]/field[@name='client_order_ref']" position="after">
<field name="type_customer"/>
</xpath>
我不知道是否存在问题,只是在选择字段声明中添加了一个aditional参数:
type_customer = fields.selection([
('Commercial', 'Commercial Customer'),
('Residential', 'Risidential Customer'),
], "Type of Customer", help = "Type of Customer", default = "Commercial",select=True, required = True)
我认为解决方案可能是这样的: 这会将字段添加到sale.order而不是仅继承已有的字段
_name = "sale.order"
_inherit = "sale.order"