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 achieve a one2one behaviour between two tables?

By
Juan Formoso
on 12/15/14, 11:07 AM 524 views

I'm working with OpenERP7. I have a table res.partner and a table event.event. I have another table which is the relationship between them, named event.registration (it has the partner_id and the event_id columns). And I have another table named diploma, which represents the diplomas delivered to each partner in each event.

So, I have a relationship one2one between event.registration and diploma. So, I have the many2one field diploma_id in event.registration table and the many2one field event_registration_id in diploma table.

When I open the diploma form, I can select the event_registration_id through a dropdown. When I open the event.registration form, I can select the diploma_id. I need to be able to relate them from both sites.

But, if I open the event.registration form and I select a diploma_id and save, then, when I open the diploma form, the event_registration_id must be fill in with the value I selected earlier from the event.registration form, and the other way around.

It means that if I store a event.registration record with a diploma_id, the record of diploma with that id must be updated with the new event_registration_id, and once again, the other way around too.

How to achieve this?

EDIT

I followed the tutorial to use _inherits:

In the Python code of event.registration:

class event_registration(orm.Model):
    _inherit = 'event.registration'
    _inherits = {'ee.diploma': "diploma"}

   _columns = { ...
        'diploma': fields.many2one('ee.diploma', 'Diploma'), ... }

In the XML view of event.registration:

<group name="diploma">
     <field name="diploma"/>
     <field name="code"/>
     <field name="sent_date"/>
</group>

I did nothing in ee.diploma, this is its class:

class ee_diploma(orm.Model):
    _name = 'ee.diploma'
    _order = 'code'
    _rec_name = 'code'
    _description = 'Event Diploma'

    _columns = {
        'code': fields.char('Code', size=64, required=True),
        'sent_date': fields.datetime('Sent date', required=True),
    }

    _sql_constraints = [
        ('unique_ee_diploma_code', 'unique(code)', 'There is already a diploma with this code!'),
    ]

I'm getting next error:

KeyError: 'code'

Where is the field "diploma" in ee.diploma ? Try to restart your server

Med Said BARA
on 12/16/14, 6:29 AM
0

Med Said BARA

--Med Said BARA--
2664
| 5 5 7
Algeria
--Med Said BARA--
Med Said BARA
On 12/15/14, 3:22 PM

You should make the event_registration _inherits from diploma and add the field diploma_id  ...

See this question and the solution

NB: one2one replaced by many2one

Thank you @Med Said BARA. I tried to follow that tutorial before asking the question but I wasn't able to manage any result. I'm going to do it again and I'll post the problems I had.

Juan Formoso
on 12/16/14, 3:24 AM

I've edited my post with the result.

Juan Formoso
on 12/16/14, 3:52 AM

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

2 follower(s)

Stats

Asked: 12/15/14, 11:07 AM
Seen: 524 times
Last updated: 3/16/15, 8:10 AM