[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
This commit is contained in:
parent
e1daaff8e0
commit
b97578f689
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue