Xavier ALT (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-client-web/6.0-opw-583495-xal into 
lp:openobject-client-web.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-client-web/6.0-opw-583495-xal/+merge/142311

Hi,

This fix some onchange problems with nested one2many popup which was not able 
to get the "parent" data.

Steps:

0) Edit sale.shop form view, and put sale.order object as o2m.
1) Sale > Configuration > Sales > Shop
2) Create a new shop.
3) Fill the required fields and click on new button in "Sale Order" o2m.
4) Add customer and click on new button in "Sale Order Line" o2m.

Current: we get a popup with warning "You have to select a customer in the 
sales form ! Please set one customer before choosing a product."

Reason: no "sale_ids" value are passed to server call - resulting in no 
partner_id when evaluating on_change call.

Regards,
Xavier
-- 
https://code.launchpad.net/~openerp-dev/openobject-client-web/6.0-opw-583495-xal/+merge/142311
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-client-web/6.0-opw-583495-xal.
=== modified file 'addons/openerp/static/javascript/form.js'
--- addons/openerp/static/javascript/form.js	2012-10-15 13:19:24 +0000
+++ addons/openerp/static/javascript/form.js	2013-01-08 13:34:21 +0000
@@ -479,6 +479,36 @@
     return frm;
 }
 
+function getFrameElement() {
+    if ('frameElement' in window) {
+        return window.frameElement;
+    }
+    var iframes = window.parent.document.getElementsByTagName('iframe');
+    for (var i=iframes.length; i-->0;) {
+        var iframe = iframes[i];
+        try {
+            var idoc = 'contentDocument' in iframe ? iframe.contentDocument : iframe.contentWindow.document;
+        } catch (e) {
+            continue;
+        }
+        if (idoc === document) {
+            return iframe;
+        }
+    }
+    return null;
+}
+
+function getPopupParentWindow() {
+    if (window.top === window.self) {
+        return null; // we are already on top window
+    }
+    var current_frame = getFrameElement();
+    if (current_frame) {
+        return window.top.jQuery(current_frame).data('source-window');
+    }
+    return null;
+}
+
 function onChange(caller){
     if (openobject.http.AJAX_COUNT > 0) {
         callLater(1, onChange, caller);
@@ -517,6 +547,27 @@
     var post_url = callback ? '/openerp/form/on_change' : '/openerp/form/change_default_get';
 
     var form_data = getFormData(1, true);
+    if (window.top !== window.self) {
+        // we're in a popup window
+        var parent_window = getPopupParentWindow();
+        if (parent_window) {
+            var parent_formdata = parent_window.getFormData(1, true);
+            var parent_prefix = $caller.attr('name') || $caller.attr('id');
+            parent_prefix = parent_prefix.slice(0, parent_prefix.lastIndexOf('/'));
+            parent_prefix = parent_prefix.slice(0, parent_prefix.lastIndexOf('/')+1);
+
+            var update_formdata = {};
+            if (parent_prefix.length) {
+                for (var k in parent_formdata) {
+                    if (k.slice(0, parent_prefix.length) === parent_prefix) {
+                        update_formdata[k] = parent_formdata[k];
+                        form_data[k] = parent_formdata[k];
+                    }
+                }
+            }
+        }
+    }
+
     /* testing if the record is an empty record, if it does not contain anything except
      * an id, the on_change method is not called
      */

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : openerp-dev-gtk@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to