Tessnim
Tessnim

Reputation: 453

unrecognized field in odoo tree view

I created a product class that has a One2many relation with Sell:

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")

and the 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)

And inside my view I added this code:

<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>

It looks like odoo doesn't recognize the fields inside the tree. I got this error:

ParseError: "Error while validating constraint

Field `date` does not exist

Does anybody knows what the problem is? Thanks.

Upvotes: 1

Views: 195

Answers (1)

Naglis Jonaitis
Naglis Jonaitis

Reputation: 2633

The problem is with your field date definition, because fields.datetime.today is a function returning a string and not an Odoo field type, thus date is ignored by Odoo. You should write 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)

Also note that the string parameter in your product_id field definition should be lowercase.

Upvotes: 2

Related Questions