Merge lp:~openerp-dev/openobject-client-web/6.0-opw-583495-xal into lp:openobject-client-web

Proposed by Xavier ALT on 2013-01-08
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-client-web/6.0-opw-583495-xal
Merge into: lp:openobject-client-web
Diff against target: 68 lines (+51/-0)
1 file modified
addons/openerp/static/javascript/form.js (+51/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-client-web/6.0-opw-583495-xal
Reviewer Review Type Date Requested Status
OpenERP Core Team 2013-01-08 Pending
Review via email: mp+142311@code.launchpad.net

Description of the change

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

To post a comment you must log in.

Unmerged revisions

4899. By Xavier ALT on 2013-01-04

[FIX] form onchange: correctly get data from parent window when on_change() happens within a one2many popup

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/openerp/static/javascript/form.js'
2--- addons/openerp/static/javascript/form.js 2012-10-15 13:19:24 +0000
3+++ addons/openerp/static/javascript/form.js 2013-01-08 13:34:21 +0000
4@@ -479,6 +479,36 @@
5 return frm;
6 }
7
8+function getFrameElement() {
9+ if ('frameElement' in window) {
10+ return window.frameElement;
11+ }
12+ var iframes = window.parent.document.getElementsByTagName('iframe');
13+ for (var i=iframes.length; i-->0;) {
14+ var iframe = iframes[i];
15+ try {
16+ var idoc = 'contentDocument' in iframe ? iframe.contentDocument : iframe.contentWindow.document;
17+ } catch (e) {
18+ continue;
19+ }
20+ if (idoc === document) {
21+ return iframe;
22+ }
23+ }
24+ return null;
25+}
26+
27+function getPopupParentWindow() {
28+ if (window.top === window.self) {
29+ return null; // we are already on top window
30+ }
31+ var current_frame = getFrameElement();
32+ if (current_frame) {
33+ return window.top.jQuery(current_frame).data('source-window');
34+ }
35+ return null;
36+}
37+
38 function onChange(caller){
39 if (openobject.http.AJAX_COUNT > 0) {
40 callLater(1, onChange, caller);
41@@ -517,6 +547,27 @@
42 var post_url = callback ? '/openerp/form/on_change' : '/openerp/form/change_default_get';
43
44 var form_data = getFormData(1, true);
45+ if (window.top !== window.self) {
46+ // we're in a popup window
47+ var parent_window = getPopupParentWindow();
48+ if (parent_window) {
49+ var parent_formdata = parent_window.getFormData(1, true);
50+ var parent_prefix = $caller.attr('name') || $caller.attr('id');
51+ parent_prefix = parent_prefix.slice(0, parent_prefix.lastIndexOf('/'));
52+ parent_prefix = parent_prefix.slice(0, parent_prefix.lastIndexOf('/')+1);
53+
54+ var update_formdata = {};
55+ if (parent_prefix.length) {
56+ for (var k in parent_formdata) {
57+ if (k.slice(0, parent_prefix.length) === parent_prefix) {
58+ update_formdata[k] = parent_formdata[k];
59+ form_data[k] = parent_formdata[k];
60+ }
61+ }
62+ }
63+ }
64+ }
65+
66 /* testing if the record is an empty record, if it does not contain anything except
67 * an id, the on_change method is not called
68 */