From b25c054c93e7e5123fecf3e0e1165238c423e705 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Wed, 23 Mar 2016 14:50:46 +0100 Subject: [PATCH] [FIX] web: prevent crash in rare case with status field Current behavior before PR: if you create a new record within a one2many field and the model's form has a clickable status bar defined, clicking this status bar will raise an exception because the virtual id (one2many_v_XXXX) will be passed to the model's write method Desired behavior after PR is merged: clicking just changes the cached value --- addons/web/static/src/js/view_form.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 9f89f729a58..72744618fa4 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -6145,13 +6145,20 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ val = $li.data("id"); } if (val != self.get('value')) { - this.view.recursive_save().done(function() { - var change = {}; - change[self.name] = val; - self.view.dataset.write(self.view.datarecord.id, change).done(function() { - self.view.reload(); + if(!this.view.datarecord.id || + this.view.datarecord.id.toString().match(instance.web.BufferedDataSet.virtual_id_regex)) { + // don't save, only set value for not-yet-saved many2ones + self.set_value(val); + } + else { + this.view.recursive_save().done(function() { + var change = {}; + change[self.name] = val; + self.view.dataset.write(self.view.datarecord.id, change).done(function() { + self.view.reload(); + }); }); - }); + } } }, });