From 6b907bb4d0421bc1c408846dec7c2a57a778cca6 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 11 Jul 2012 16:14:02 +0200 Subject: [PATCH] [FIX] can't perform action on a o2m record which is not saved in db, so forbid it. Also yet-another-shitty-undoc-change to the way widgets and form view communicate bzr revid: xmo@openerp.com-20120711141402-1x7frd0v3vc3649e --- addons/web/static/src/js/view_form.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 0211b934a4e..e6e78a46ab8 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3196,6 +3196,11 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ })); this.on('edit:before', this, this.proxy('_beforeEdit')); this.on('save:before cancel:before', this, this.proxy('_beforeUnEdit')); + + this.records + .bind('add', this.proxy("changedRecords")) + .bind('edit', this.proxy("changedRecords")) + .bind('remove', this.proxy("changedRecords")); }, start: function () { var ret = this._super(); @@ -3204,6 +3209,9 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ .on('mousedown.handleButtons', 'table button', this.proxy('_buttonDown')); return ret; }, + changedRecords: function () { + this.o2m.trigger_on_change(); + }, is_valid: function () { var form = this.editor.form; @@ -3276,13 +3284,19 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ readonly: self.o2m.get("effective_readonly") }); }, - do_button_action: function () { + do_button_action: function (name, id, callback) { + if (!_.isNumber(id)) { + instance.webclient.notification.warn( + _t("Action Button"), + _t("The o2m record must be saved before an action can be used")); + return; + } var parent_form = this.o2m.view; - var self = this, args = arguments; - return this.ensureSaved().pipe(function () { + var self = this; + this.ensureSaved().pipe(function () { return parent_form.do_save(); }).then(function () { - self.handleButton.apply(self, args); + self.handleButton(name, id, callback); }); },