summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2015-03-16 09:10:01 +0100
committerNicolas Lempereur <nle@odoo.com>2015-03-19 09:56:12 +0100
commitb97578f689bb8be6e86de9885dd7613f37a0a7ac (patch)
tree4d9cd4988a45d392f3ebe77a9f5f02c1634d46e4 /addons/web/static/src
parente1daaff8e0711f4fc39a8360ace01f8529a4754e (diff)
[FIX] view_form: sequence at item creation
The sequence for new items in some models is simply set to a constant 10. Hence if 3 items had after reordering sequences 10, 11 and 12. If a new item is added, it would get after saving at the second position. This fix set the sequence of a new item to the maximum+1 or minimum-1 sequence of current items sequences (max if tree has editable="bottom", min if tree has editable="top"). opw-627830
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/view_form.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 52065001693..83faa5e8626 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -855,6 +855,16 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
}
}
}
+ // Heuristic to assign a proper sequence number for new records that
+ // are added in a dataset containing other lines with existing sequence numbers
+ if (!self.datarecord.id && self.fields.sequence &&
+ !_.has(values, 'sequence') && !_.isEmpty(self.dataset.cache)) {
+ // Find current max or min sequence (editable top/bottom)
+ var current = _[prepend_on_create ? "min" : "max"](
+ _.map(self.dataset.cache, function(o){return o.values.sequence})
+ );
+ values['sequence'] = prepend_on_create ? current - 1 : current + 1;
+ }
if (form_invalid) {
self.set({'display_invalid_fields': true});
first_invalid_field.focus();