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

unrecognized field in odoo tree view

我创建了一个产品 class,它与 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:

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

有人知道问题出在哪里吗? 谢谢

问题出在您的字段 date 定义上,因为 fields.datetime.todaya function returning a string 而不是 Odoo 字段类型, 因此 date 被 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)

另请注意,product_id 字段定义中的 string 参数应为小写。