[FIX] web: date value must be parsed to moment object
This commit is contained in:
committed by
Aaron Bohy
parent
a9475e14af
commit
04f1e50ff3
@@ -1167,6 +1167,18 @@ var BasicModel = AbstractModel.extend({
|
||||
.then(function (records) {
|
||||
_.each(records, function (record) {
|
||||
list_records[record.id].data = record;
|
||||
_.each(record, function (val, fieldName) {
|
||||
var field = list.fields[fieldName];
|
||||
if (field.type === 'date') {
|
||||
// process data: convert into a moment instance
|
||||
record[fieldName] = fieldUtils.parse.date(val);
|
||||
} else if (field.type === 'datetime') {
|
||||
// process datetime: convert into a moment instance
|
||||
record[fieldName] = fieldUtils.parse.datetime(val);
|
||||
} else {
|
||||
record[fieldName] = val;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
defs.push(def);
|
||||
|
||||
@@ -38,10 +38,11 @@ QUnit.module('Views', {
|
||||
},
|
||||
partner_type: {
|
||||
fields: {
|
||||
display_name: {string: "Partner Type", type: "char"}
|
||||
display_name: {string: "Partner Type", type: "char"},
|
||||
date: {string: "Date Field", type: 'date'},
|
||||
},
|
||||
records: [
|
||||
{id: 12, display_name: "gold"},
|
||||
{id: 12, display_name: "gold", date: "2017-01-25"},
|
||||
{id: 14, display_name: "silver"},
|
||||
{id: 15, display_name: "bronze"}
|
||||
]
|
||||
@@ -328,6 +329,30 @@ QUnit.module('Views', {
|
||||
model.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('can use command add and get many2many value with date field', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
this.params.fieldNames = ['category'];
|
||||
|
||||
var model = createModel({
|
||||
Model: BasicModel,
|
||||
data: this.data,
|
||||
});
|
||||
|
||||
model.load(this.params).then(function (resultID) {
|
||||
var changes = {
|
||||
category: {operation: 'ADD_M2M', ids: [{id: 12}]}
|
||||
};
|
||||
model.notifyChanges(resultID, changes).then(function () {
|
||||
var record = model.get(resultID);
|
||||
assert.strictEqual(record.data.category.data.length, 1, "should have added one category");
|
||||
assert.strictEqual(record.data.category.data[0].data.date instanceof moment,
|
||||
true, "should have a date parsed in a moment object");
|
||||
});
|
||||
});
|
||||
model.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('can fetch a list', function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user