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.

1

[Bug] O2M lines populated from Onchange Event, gets appended rather than overriding, when saving....

By
deep
on 9/15/14, 6:27 AM 1,204 views

Using Onchange Event am trying to populate values to One2Many field.. (which is working fine)

But, Consider a scenario... 

Once the record is saved, And again I try to change the value (event triggering field), which in turn calls the Onchange Event, and it again populates the fresh  new One2Many lists... (which is also working perfectly)

But when I save the record, then list  values are changed... i.e. instead of overriding the O2M values, with new lists, it actually appends to the existing list.,....

Let me explain with acute scenario...

I have an object, based on Sale Order Id, am trying to capture its Order lines.... So all i have done is... I have added Order_id (M2O) and Order_lines(O2M)... Onchange Event is written for Order_id, which returns Order_lines pertaining to its order.... (which is obsolutely working fine)...

But the problem arises, with the saved records, If I change the Order_id, surely onchange fetches me the new lines pertaining to the new Order_id, but when I save the record... Order_lines are changed... (i.e. lines of pervious Order and lines of new Order gets saved)...

So I believe, this is a bug in Openerp, because am pretty sure there is nothing wrong in my code... Anybody faced this kind of problem, do let me know....

can u post your code?..

Prakash
on 9/15/14, 6:30 AM

In xml file field set context and in python file onchange using context.get('') check particular field is called then return o2m lines populated values otherwise return {}

Prakash
on 9/15/14, 6:48 AM

Hmmmm... I think you didnt get my question.... let me explain with other example... consider field A and field B... Now when field A is changed say XXX, then value of field B is also changed right say YYYY.... again if you change the field A to PPPP, then certainly field B value will also be overriden with new value QQQ...

deep
on 9/15/14, 6:57 AM

Same thing wont happen when field B happened to be an One2many field... have you ever come across such scenario ?

deep
on 9/15/14, 6:59 AM

similar issue i faced more than one many2one field onchange applied. Using context fixed the issues.

Prakash
on 9/15/14, 7:16 AM

Thanks.. I tried context, even that didn't help me...

deep
on 9/17/14, 1:39 AM
1

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 9/15/14, 8:41 AM

Hi Deep,

You have to just take care and learn from the following thing.

# (0, 0,  { fields })    create
# (1, ID, { fields })    update (write fields to ID)
# (2, ID)                remove (calls unlink on ID, that will also delete the relationship because of the ondelete)
# (3, ID)                unlink (delete the relationship between the two objects but does not delete ID)
# (4, ID)                link (add a relationship)
# (5, ID)                unlink all
# (6, 0, ids)            set a list of link

Here you have to use the 'one2many_fieldname':[6,0,[(), (), (), ...] ] into return value. It will never append records, It will always create new record.

Let me knwo if it is not clear to you.

 

Hi Chirag... what you are telling is all about Many2Many... but what i need is w.r.t One2many... and I do know these things... but thanks anyway....

deep
on 9/15/14, 9:52 AM

Only one thing chirag forgot to mention... and it is the same for m2m and o2m fields... if you fill it with onchange action... do not forget to empty old vals before filling it... be careful with that part, because you do not want to unlink actual data.. just break the relationship for that field... so the simplest way is to call unlink for all record curently related, and then fill them again...

Bole
on 9/16/14, 10:15 AM

Hi Bole, yes presently i have done tat only, unlinking current records.... but i dont understand.. how can u use [6,0... for One2Many.. would you to care to share the code.... thanks

deep
on 9/16/14, 10:35 AM

what chirag wrote is for many2many... fro one2many you can only use this: (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) so you will probably need to do (2,id) for id in ids... then add new records with 0 or 1...

Bole
on 9/16/14, 12:12 PM
0

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 9/17/14, 1:38 AM

Guys... I really appreciate the efforts you took to help me out... but this is not the solution am looking for..... And am perfectly well aware of the OneMany & Many2Many semantics, and indeed those things have served my other requirements efficiently...

But what am looking for is not this, I guess it is a bug in openerp....

Thanks anyway...

Yes, I have similar problem with you. In my case I also get mysterious first entry in lines (I'm investigating bank.statement.lines) which should be not there. I let the append bug through and call it my use case (unless someone ask me to do proper update, sigh). I think you can submit proper bug report in the github repo.

Ben Bernard
on 9/24/14, 4:12 AM

Forget to mention, don't add string "bug" in the title or your post will be closed by the founder itself, usually. Just add a proper tag ;)

Ben Bernard
on 9/24/14, 4:19 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: 9/15/14, 6:27 AM
Seen: 1204 times
Last updated: 3/16/15, 8:10 AM