diff options
| author | David Monjoie <dmo@odoo.com> | 2017-08-04 15:31:51 +0200 |
|---|---|---|
| committer | David Monjoie <dmo@odoo.com> | 2017-08-08 11:18:10 +0200 |
| commit | e2252c35c15df9ccf9132c72348723790d76a676 (patch) | |
| tree | 60aa4cc19c52f171accc26d8fdbd24c712cd010c /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | 587751aa0dbd095db99e93398cf98d705c35679c (diff) | |
[FIX] web: handle create in many2many default_get
Previously, we did not handle the case where the result of the m2m
default get was a new record. In this case, we can't just send a
replace all command giving the ids since the new record has no id.
We decided to keep the replace all command even when it is empty
to stay consistent with the o2m implementation, even though saas-15
did not behave like that.
Steps to reproduce the bug:
- Enable lots in Iventory
- Choose a product which is a component of another (through mrp bom)
- Set this product as tracked by lot
- Set this product inventory quantity to 0
- Create a new manufacturing order for the product for which it is a
component
- Click on "Check Availability"
- Click on Produce
- You'll get an error as the id given to the onchange is a virtual one,
rather than a create which would not include an id.
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 | 10 |
1 files changed, 9 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 fc3b68eeab7..acb0dddbcb6 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2310,12 +2310,20 @@ var BasicModel = AbstractModel.extend({ }); list = this._applyX2ManyOperations(list); if (type === 'many2many' || list._forceM2MLink) { + var relRecordCreated = _.filter(relRecordAdded, function (rec) { + return typeof rec.res_id === 'string'; + }); + var realIDs = _.difference(list.res_ids, _.pluck(relRecordCreated, 'res_id')); // deliberately generate a single 'replace' command instead // of a 'delete' and a 'link' commands with the exact diff // because 1) performance-wise it doesn't change anything // and 2) to guard against concurrent updates (policy: force // a complete override of the actual value of the m2m) - commands[fieldName].push(x2ManyCommands.replace_with(list.res_ids)); + commands[fieldName].push(x2ManyCommands.replace_with(realIDs)); + _.each(relRecordCreated, function (relRecord) { + var changes = self._generateChanges(relRecord, options); + commands[fieldName].push(x2ManyCommands.create(changes)); + }); // generate update commands for records that have been // updated (it may happen with editable lists) _.each(relRecordUpdated, function (relRecord) { |
