Odoo Help


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.


Mimick One2One Implementation

tim diamond
on 9/16/13, 10:03 PM 2,363 views

Hi community,

Thank you in advance for any comments / suggestions that could help my problem.

I have two objects currently that I want to uniquely link together. A "container object" and a "calculations" object. I want every container to have one (and only) one calculations object, and one calculations object to have one and only one container object.

I know that one2one is depreciated, but my programming need does not call for inheritance. The two objects have absolutely nothing to do with each other.

Thus, I have tried adding a many2one field in container AND a many2one field in calculations. This has actually worked rather well, however I'm stuck at the final part:

A container object is always created first. So, when I create a container, I can open the "calculations" field from the form, and select "Create new" from the dropdown. My question is this:

When the new form opens to create a "calculations" object, how can I reference the ID of my "container" object, so that I can automatically assign THAT container to my calculations object, by default. In this way, if I don't present the user with a field to set the "container", the default will always be used and thus mimicking a one2one relationship with 2 many2ones.

Does anyone have a suggestion?


Daniel Reis

--Daniel Reis--
| 6 7 9
Lisbon, Portugal
--Daniel Reis--

Author of the "Odoo Development Essentials" book.

Applications Manager at Securitas Portugal

Github: https://github.com/dreispt

Twitter; @reis_pt

Daniel Reis
On 9/17/13, 7:19 AM

What you need to set a context on "Container" form's calculation_id field:.

Assuming that "Container" and a many2one calculation_id for the Calculation object, and the Calculation object has a many2one container_id:

<field name="calculation_id" context="{'default_container_id':  active_id}" />

This will tell the Calculation form to by default set the container_id field with the Container's Id.

Awesome advice!!! Thank you so much for the help. Works great.

tim diamond
on 9/19/13, 8:02 PM

This is not working ! I have crossed many2one relations to try mimick one2one and I get errors of missing ID value in the required field

on 12/12/13, 7:44 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

0 follower(s)


Asked: 9/16/13, 10:03 PM
Seen: 2363 times
Last updated: 12/21/15, 11:07 AM