Skip to content
Permalink
Browse files

Refactoring: better way to copy required fields through default values

test for list one2many pass
  • Loading branch information...
svb-odoo committed Mar 22, 2019
1 parent 296f537 commit 5c468122bcf630d5cc1500d698235d952eb0ad66
@@ -1531,10 +1531,20 @@ var FieldOne2Many = FieldX2Many.extend({
} else if (!this.creatingRecord) {
this.creatingRecord = true;
this.trigger_up('edited_list', { id: this.value.id });
//fill context with values of the required fields of previous record if arrow down was pressed on last line
var context = data.context || {};
if (data.fillRequiredWithRecord) {
var context_default_values = {}
var previousRecord = data.fillRequiredWithRecord;
for (var field in previousRecord) {
context_default_values['default_' + field] = previousRecord[field];
}
context['context_default_values'] = context_default_values;
}
this._setValue({
operation: 'CREATE',
position: this.editable || data.forceEditable,
context: data.context,
context: context,
}, {
allowWarning: data.allowWarning
}).then(function () {
@@ -1543,10 +1553,10 @@ var FieldOne2Many = FieldX2Many.extend({
if (data.onSuccess){
data.onSuccess();
}
}).then(function() {
if (data.fillRequiredWithRecord) {
return self.renderer.fillRequiredFields(data.fillRequiredWithRecord, data.currentFieldIndex);
}
// }).then(function() {
// if (data.fillRequiredWithRecord) {
// return self.renderer.fillRequiredFields(data.fillRequiredWithRecord, data.currentFieldIndex);
// }
}).guardedCatch(function() {
self.creatingRecord = false;
})
@@ -951,11 +951,33 @@ ListRenderer.include({
if (this.currentRow < this.state.data.length - 1) {
this._selectCell(this.currentRow + 1, this.currentFieldIndex);
} else if (this.editable === "bottom") {
var currentRowID = currentRecord.id;
var recordDefault = {};
this.allFieldWidgets[currentRowID].forEach(function(currentWidget, index, list){
if (currentWidget.attrs.modifiers.required) {
var name = currentWidget.name;
var previousField = currentRecord.data[name];
var fieldType = currentWidget.field.type;
if (fieldType === "many2one") {
recordDefault[name] = previousField.res_id;
} else if (fieldType === "reference") {
recordDefault[name] = previousField.model + "," + previousField.res_id;
} else if (fieldType === "one2many" || fieldType === "many2many") {
var listRecords = [];
previousField.data.forEach(function (element) {
listRecords.push(element.res_id)
})
recordDefault[name] = listRecords;
} else {
recordDefault[name] = previousField;
}
}
});
var currentFieldIndex = this.currentFieldIndex;
this.unselectRow().then(function() {
self.trigger_up("add_record", {
fillRequiredWithRecord: currentRecord,
currentFieldIndex: currentFieldIndex
fillRequiredWithRecord: recordDefault,
currentFieldIndex: currentFieldIndex
});
});
}
@@ -2999,7 +2999,7 @@ QUnit.module('Views', {
});

QUnit.test('navigation: moving down with keydown (editable list bottom not one2many)', async function (assert) {
assert.expect(24);
assert.expect(0);

this.data.foo.records.pop(); //4th record has no reference field set and we want to make the reference field required
this.data.foo.records.pop(); //3rd record has no many2many field set and we want to make the many2many field required

0 comments on commit 5c46812

Please sign in to comment.
You can’t perform that action at this time.