[FIX] web: fix one2many default get

The one2many default get code used to meddle with basic_model's res_ids
manually, which ended up desynchronizing the data and res_ids fields
of the list representation of the one2many values.

This commit solves the issue by using the proper mechanisms of the
basic_model, that is creating a proper datapoint for those ids.

Steps to reproduce the original issue:
- Install sale_mamangement, mrp and purchase
- Create a product
- In the Inventory tab, in Routes, uncheck Buy
- Check and then uncheck back any other route than Buy
- Get a traceback because we are looking for a record with a given
  res_id in the list data but since they are desynchronized, data
  is empty at that point even though res_ids is not.
This commit is contained in:
David Monjoie
2017-09-30 09:04:29 +02:00
committed by Aaron Bohy
parent e4672db97d
commit 8d1630a40a
2 changed files with 59 additions and 2 deletions
@@ -3158,8 +3158,18 @@ var BasicModel = AbstractModel.extend({
}
if (value[0] === 6) {
// REPLACE_WITH
x2manyList.res_ids = value[2];
x2manyList.count = x2manyList.res_ids.length;
_.each(value[2], function (res_id) {
r = self._makeDataPoint({
modelName: x2manyList.model,
context: x2manyList.context,
fieldsInfo: fieldsInfo,
fields: fields,
parentID: x2manyList.id,
res_id: res_id,
viewType: viewType,
});
x2manyList._changes.push({operation: 'ADD', id: r.id});
});
var def = self._readUngroupedList(x2manyList).then(function () {
return $.when(
self._fetchX2ManysBatched(x2manyList),
@@ -6249,6 +6249,53 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('many2many checkboxes with default values', function (assert) {
assert.expect(7);
this.data.partner.fields.turtles.default = [3];
this.data.partner.fields.turtles.type = "many2many";
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form string="Partners">' +
'<field name="turtles" widget="many2many_checkboxes">' +
'</field>' +
'</form>',
mockRPC: function (route, args) {
if (args.method === 'create') {
assert.deepEqual(args.args[0].turtles, [[6, false, [1]]],
"correct values should have been sent to create");
}
return this._super.apply(this, arguments);
}
});
assert.notOk(form.$('.o_checkbox input').eq(0).prop('checked'),
"first checkbox should not be checked");
assert.notOk(form.$('.o_checkbox input').eq(1).prop('checked'),
"second checkbox should not be checked");
assert.ok(form.$('.o_checkbox input').eq(2).prop('checked'),
"third checkbox should be checked");
form.$('.o_checkbox input:checked').click(); // Uncheck default record
form.$('.o_checkbox input').first().click(); // Check first record
form.$('.o_checkbox input').first().click(); // Uncheck first record
form.$('.o_checkbox input').first().click(); // Recheck first record
assert.ok(form.$('.o_checkbox input').eq(0).prop('checked'),
"first checkbox should be checked");
assert.notOk(form.$('.o_checkbox input').eq(1).prop('checked'),
"second checkbox should not be checked");
assert.notOk(form.$('.o_checkbox input').eq(2).prop('checked'),
"third checkbox should not be checked");
form.$buttons.find('.o_form_button_save').click();
form.destroy();
});
QUnit.test('many2many list with x2many: add a record', function (assert) {
assert.expect(18);