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