在odoo树视图中无法识别的字段

时间:2018-01-12 16:01:56

标签: python xml odoo-10 odoo

我创建了一个与Sell具有One2many关系的产品类:

class comp_product(models.Model):
    _name = "comp.product"
    _description = "Product Description"

    name = fields.Char('Product Name')
    description = fields.Text('add description of your product here')
    sell_ids = fields.One2many('comp.sell', 'product_id', String = "Sells")

和销售类:

class comp_sell(models.Model):
    _name="comp.sell"
    _description="Sells per Product"

    name = fields.Float('How many units did you sell?')
    date = fields.datetime.today()
    product_id = fields.Many2one('comp.product', String = "Product", required = True)

在我看来,我添加了这段代码:

<notebook string="Other Informations">
    <page string="Description"><field name="description" string="Description"/></page>
    <page string="Update Sells">
        <field name="sell_ids">
            <tree string="Sells" editable="bottom">
                <field name="name"/>
                <field name="date" readonly="1" />
            </tree>
        </field>
    </page>
</notebook>

看起来odoo无法识别树内的字段。我收到了这个错误:

ParseError: "Error while validating constraint

Field `date` does not exist

有人知道问题是什么吗? 感谢。

1 个答案:

答案 0 :(得分:2)

问题在于您的字段fields.datetime.today定义,因为 datea function returning a string而不是Odoo字段类型, 因此,Odoo忽略了date = fields.Datetime(default=fields.Date.context_today)。你应该写class comp_sell(models.Model): _name = 'comp.sell' _description = 'Sells per Product' name = fields.Float('How many units did you sell?') date = fields.Datetime(default=fields.Date.context_today) product_id = fields.Many2one('comp.product', string='Product', required=True)

string

另请注意,product_id字段定义中的In file included from LdBitFieldProperty.cpp:16:0: LdBitFieldProperty.h:47:29: warning: ‘virtual std::__cxx11::string LdBitFieldProperty::GetStringValue(size_t) const’ can be marked override [-Wsuggest-override] virtual std::string GetStringValue( size_t aIndex = 0 ) const override; 参数应为小写。