[FIX] web: basicmodel can evaluate context for new records
This commit is contained in:
committed by
Aaron Bohy
parent
f3a811b2b2
commit
450e2f4d48
@@ -475,12 +475,15 @@ var Model = AbstractModel.extend({
|
||||
});
|
||||
record._changes[name] = rec.id;
|
||||
} else if (field.type === 'one2many' || field.type === 'many2many') {
|
||||
var attrs = record.fieldAttrs[name];
|
||||
var x2manyList = self._makeDataPoint({
|
||||
context: record.context,
|
||||
fieldAttrs: field.fieldAttrs,
|
||||
fields: field.relatedFields,
|
||||
limit: field.limit,
|
||||
modelName: field.relation,
|
||||
parentID: record.id,
|
||||
rawContext: attrs && attrs.context,
|
||||
res_ids: [],
|
||||
static: true,
|
||||
type: 'list',
|
||||
@@ -1541,6 +1544,7 @@ var Model = AbstractModel.extend({
|
||||
if (element.rawContext) {
|
||||
context.add(element.rawContext);
|
||||
var evalContext = this.get(element.parentID, {raw: true}).data;
|
||||
evalContext.id = evalContext.id || false;
|
||||
context.set_eval_context(evalContext);
|
||||
}
|
||||
return context.eval();
|
||||
|
||||
@@ -1334,6 +1334,41 @@ QUnit.module('relational_fields', {
|
||||
form.$('tbody td.o_form_field_x2many_list_row_add a').click();
|
||||
});
|
||||
|
||||
QUnit.test('new record, the context is properly evaluated and sent', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
this.data.partner.fields.int_field.default = 17;
|
||||
var n = 0;
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="int_field"/>' +
|
||||
'<field name="p" context="{\'hello\': \'world\', \'abc\': int_field}">' +
|
||||
'<tree editable="top">' +
|
||||
'<field name="foo"/>' +
|
||||
'</tree>' +
|
||||
'</field>' +
|
||||
'</form>',
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === 'default_get') {
|
||||
n++;
|
||||
if (n === 2) {
|
||||
var context = args.kwargs.context;
|
||||
assert.strictEqual(context.hello, "world");
|
||||
assert.strictEqual(context.abc, 17);
|
||||
}
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
form.$('tbody td.o_form_field_x2many_list_row_add a').click();
|
||||
});
|
||||
|
||||
QUnit.module('FieldMany2Many');
|
||||
|
||||
QUnit.test('many2many kanban: edition', function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user