Skip to Content
Menu
This question has been flagged
1 Reply
3654 Views

I want to add a field, job_ids, to res_partner in Odoo version 9. I added the field, restarted the Odoo service, and updated the app. However, the column does not appear in the database for res_partner, but it does for Jobs. If I add another column, like "test = fields.Char()" in res_partner it works. What is the issue with creating job_ids?


class res_partner(models.Model):

    _inherit = 'res.partner'

    job_ids = fields.One2many('fix_tribe.jobs', 'res_partner_id', string="Jobs")


class Jobs(models.Model):

    _name = 'fix_tribe.jobs'

    name = fields.Char()

    customer_id = fields.Many2one('fix_tribe.customers', string="Customer")

    res_partner_id = fields.Many2one('res.partner', string="ResPartner")

    isCompleted = fields.Boolean(string="Completed?")

    datetime_start = fields.Datetime(string="Start Date/Time")

    datetime_stop = fields.Datetime(string="Stop Date/Time")

    cost = fields.Float()

    jobitem_ids = fields.One2many('fix_tribe.job_items', 'name')

Avatar
Discard
Best Answer

A one2many field doesn't create a new column in the table of the object. It's purpose is to easily browse the inverse relationship of a many2one field. In fact, no extra information needs to be encoded in the database for a one2many relationship because it can be inferred by querying the many2one relationship, and that's why an extra column is not needed for the res_partner table. The reason you are seeing the res_partner_id column in the jobs table is because of the many2one field you defined in the Jobs class.

In case you are wondering about many2many fields, you will also not see an extra column in the table for that relationship because it is represented by a separate table.

Do a search for relational database tutorials if you want to find out more about what happens on the database side.


Avatar
Discard
Related Posts Replies Views Activity
2
Oct 23
3950
3
Sep 23
993
0
May 23
1441
1
May 23
921
1
Apr 23
807