This question has been flagged
1 Reply
3196 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'

Avatar
Discard

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

Best Answer

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

Avatar
Discard
Author

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.

Author

I've edited my post with the result.