diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-07-25 10:09:42 +0200 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2017-07-25 10:58:14 +0200 |
| commit | a41db9a2cf410bb233b021651a5633180eaddf18 (patch) | |
| tree | abe29c20df74f7d5bf288972248df512ad4b5147 /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | 952c17b8a76c39f6bdf780edcd07ca5def3c8520 (diff) | |
[FIX] web: allow record creation even if onchange returns warning
Before this commit, the makeDefaultRecord could return a rejected
deferred if the onchange returned a warning. This was useful in this
usecase: the user is in a form view with a one2many (for example, an
invoice with no customer set), then click on 'Add a line' (the invoice
line). In that case, the onchange returns a warning, and we do not want
to add the line at all, so the makeDefaultRecord is rejected.
This works fine, but we then have another problem: when we create a new
record from scratch, it may happen that a warning is returned (for
example, if a vendor has its 'warning on invoice' flag set, then a
purchase order is done with this vendor, then confirmed, then the stat
button for 'vendor bills' is clicked, which opens a list view with the
vendor in the context. Clicking on 'create' will return a warning,
which is what we want). In that case, the record still needs to be
created.
To solve this issue, we simply add an option to the makeDefaultRecord
function to prevent rejecting the deferred.
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 75a0ad02971..dfc8858664d 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -509,6 +509,7 @@ var BasicModel = AbstractModel.extend({ } if (params.type === 'record' && params.res_id === undefined) { + params.allowWarning = true; return this._makeDefaultRecord(params.modelName, params); } var dataPoint = this._makeDataPoint(params); @@ -2735,6 +2736,8 @@ var BasicModel = AbstractModel.extend({ * @private * @param {any} params * @param {string} modelName model name + * @param {boolean} [params.allowWarning=false] if true, the default record + * operation can complete, even if a warning is raised * @param {Object} params.context the context for the new record * @param {Object} params.fieldsInfo contains the fieldInfo of each view, * for each field @@ -2887,7 +2890,11 @@ var BasicModel = AbstractModel.extend({ .then(function () { return self._performOnChange(record, fields_key).then(function () { if (record._warning) { - return $.Deferred().reject(); + if (params.allowWarning) { + delete record._warning; + } else { + return $.Deferred().reject(); + } } }); }) |
