我想在销售模块的机会视图中添加一个新字段。我创建了一个新模块。当我尝试安装时,它显示以下错误(在快照中提到) -
下面是我要添加字段的表单。
以下是.py
档案:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
import math
from datetime import date
from openerp.osv import osv, fields, orm
class crm_lead(osv.osv):
_inherit = "crm.lead"
_description="modification"
_columns = {
'quantite': fields.text('Quantité'),
}
这是xml
档案:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="crm_case_tree_view_oppor" model="ir.ui.view">
<field name="name">crm.case.tree.view.oppor</field>
<field name="model">crm.lead</field>
<field name="view_type">tree</field>
<field name="inherit_id" ref="crm.crm_case_tree_view_oppor"/>
<field name="arch" type="xml">
<tree>
<xpath expr="//field[@name='probability']" position="after">
<field name="quantite"/>
</xpath>
</tree>
</field>
</record>
</data>
</openerp>
答案 0 :(得分:1)
我注意到另一个视图继承自同一个树视图。这是他们所做的。他们没有使用xpath,不知道为什么。我想我以前有过,但值得一试。
<record id="view_crm_opportunity_geo_assign_tree" model="ir.ui.view">
<field name="name">crm.lead.geo_assign.tree.inherit</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_tree_view_oppor"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="partner_assigned_id"/>
<field name="date_assign" invisible="1"/>
</field>
</field>
</record>
所以我猜你的看起来像这样。您必须更改视图的名称以匹配您的示例,但您可能会明白这一点。
<record id="view_crm_opportunity_geo_assign_tree" model="ir.ui.view">
<field name="name">crm.lead.geo_assign.tree.inherit</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_tree_view_oppor"/>
<field name="arch" type="xml">
<field name="probability" position="after">
<field name="quantite"/>
</field>
</field>
</record>
答案 1 :(得分:1)
Phillip Stack的回答是正确的,但我想在此提及两件事。
from openerp import models, fields
class CrmLead(models.Model):
_inherit = "crm.lead"
_name = "crm.lead" # optional
quantite = fields.Text(string="Quantité")
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="crm_case_tree_view_oppor" model="ir.ui.view">
<field name="name">crm.case.tree.view.oppor</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_tree_view_oppor"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='probability']" position="after">
<field name="quantite" />
</xpath>
</field>
</record>
</data>
</openerp>