Community mailing list archives


Re: Updating One2many field with an onchange mehtod

- 04/01/17 04:16:44
Here are some Helpfull stuff while doing operations on one2many fields:

(0, 0, { values }) link to a new record that needs to be created with the given values dictionary

(1, ID, { values }) update the linked record with id = ID (write values on it)

(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)

(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)

(4, ID) link to existing record with id = ID (adds a relationship)

(5) unlink all (like using (3,ID) for all linked records)

(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

Thanks & Regards
Python Developer
Project & IT Department
+91 494 3015006 / 07
+91 8606827707
Facebook Twitter LinkedIn Google Plus Pinterest Company
This email and any file transmitted with it are confidential and intended solely for the use of the individual or entity whom they are addressed.If you have received this email in error please notify the system manager. The company accepts no liability for any damage caused by any virus transmitted by this email.

On Thu, Mar 30, 2017 at 3:30 PM, Dev Loper <> wrote:
Can you elaborate please because from what  i understand this magical number is used to create record (one2many).
But my problem is when i update the field i named a (many2one from the model A) i have to update the field b (one2many  from the model A) according to the data related to new field a's content, which means that i've to hide (at least) the old content of the field display the new one.

I've thought to use a helper field (i.e is_removed with to possible values YES or NO) in the relation one2many, so if i change the field a's content i modify the value of is_removed  to YES and put the inverse field in the model B to zero in the database so the old one2many records  are no longer related to the model A (and its field a's old content too) but the downside of this approach intervene when the user hit discard because i've already unliked the old one2many records from the model A (and its field a's old content too)


On Thu, Mar 30, 2017 at 9:35 AM, Omar Ouhari <> wrote:
use magical number [(0, 0, {key: value})]

Consultant IT
Tel : +

2017-03-30 9:26 GMT+01:00 Dev Loper <>:

I have the following situation:
I have two models A and B, in the model A there are these fields:
 - a (Many2one) with another model
 - b (One2many) with the model B
Using a method with the decorator @onchange('a')  i fill automatically the field b with some data related to a.
Everything works fine when i'm on the create mode.

But when i'm on edit mode, if i change the field a's content (i choose another object) it will update the one2many field with the data related to the new a field by adding this data to the already existing (already persisted in the database with create so still displayed on the tree view of the one2many field).

Is there a way to handle this situation?

I hope the message is clear, otherwise don't hesitate to ask for more explanation.

Thanks in advance!!

Post to:

Post to:

Post to: