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

Proposed by Xavier ALT
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 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

[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
=== 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 @@
479 return frm;479 return frm;
480}480}
481481
482function getFrameElement() {
483 if ('frameElement' in window) {
484 return window.frameElement;
485 }
486 var iframes = window.parent.document.getElementsByTagName('iframe');
487 for (var i=iframes.length; i-->0;) {
488 var iframe = iframes[i];
489 try {
490 var idoc = 'contentDocument' in iframe ? iframe.contentDocument : iframe.contentWindow.document;
491 } catch (e) {
492 continue;
493 }
494 if (idoc === document) {
495 return iframe;
496 }
497 }
498 return null;
499}
500
501function getPopupParentWindow() {
502 if (window.top === window.self) {
503 return null; // we are already on top window
504 }
505 var current_frame = getFrameElement();
506 if (current_frame) {
507 return window.top.jQuery(current_frame).data('source-window');
508 }
509 return null;
510}
511
482function onChange(caller){512function onChange(caller){
483 if (openobject.http.AJAX_COUNT > 0) {513 if (openobject.http.AJAX_COUNT > 0) {
484 callLater(1, onChange, caller);514 callLater(1, onChange, caller);
@@ -517,6 +547,27 @@
517 var post_url = callback ? '/openerp/form/on_change' : '/openerp/form/change_default_get';547 var post_url = callback ? '/openerp/form/on_change' : '/openerp/form/change_default_get';
518548
519 var form_data = getFormData(1, true);549 var form_data = getFormData(1, true);
550 if (window.top !== window.self) {
551 // we're in a popup window
552 var parent_window = getPopupParentWindow();
553 if (parent_window) {
554 var parent_formdata = parent_window.getFormData(1, true);
555 var parent_prefix = $caller.attr('name') || $caller.attr('id');
556 parent_prefix = parent_prefix.slice(0, parent_prefix.lastIndexOf('/'));
557 parent_prefix = parent_prefix.slice(0, parent_prefix.lastIndexOf('/')+1);
558
559 var update_formdata = {};
560 if (parent_prefix.length) {
561 for (var k in parent_formdata) {
562 if (k.slice(0, parent_prefix.length) === parent_prefix) {
563 update_formdata[k] = parent_formdata[k];
564 form_data[k] = parent_formdata[k];
565 }
566 }
567 }
568 }
569 }
570
520 /* testing if the record is an empty record, if it does not contain anything except571 /* testing if the record is an empty record, if it does not contain anything except
521 * an id, the on_change method is not called572 * an id, the on_change method is not called
522 */573 */