Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to add field to res_partner in Odoo version 9

By
Trevor Nemanic
on 1/15/16, 6:16 PM 799 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')

0
O Sluys
On 1/16/16, 3:16 AM

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.


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/15/16, 6:16 PM
Seen: 799 times
Last updated: 1/16/16, 3:16 AM