[FIX] web: allow virtual ids for integer fields
Before this change, the redering throw an exception when we try to open a form view with a virtual id. eg: recurrent event in calendar
This commit is contained in:
@@ -482,6 +482,7 @@ var FieldMonetary = InputField.extend({
|
||||
* @override
|
||||
* @private
|
||||
* @param {float} value
|
||||
* @returns {string}
|
||||
*/
|
||||
_formatValue: function (value) {
|
||||
var format = field_utils.format[this.mode === 'edit' ? "float" : "monetary"];
|
||||
@@ -598,6 +599,10 @@ var FieldBoolean = AbstractField.extend({
|
||||
var FieldInteger = InputField.extend({
|
||||
supportedFieldTypes: ['integer'],
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* For integer fields, 0 is a valid value.
|
||||
*
|
||||
@@ -606,6 +611,34 @@ var FieldInteger = InputField.extend({
|
||||
isSet: function () {
|
||||
return this.value === 0 || this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Format integer value
|
||||
*
|
||||
* Note: We have to overwrite this method to allow virtual ids. A virtual id
|
||||
* is a character string composed of an integer and has a dash and other
|
||||
* information.
|
||||
* E.g: in calendar, the recursive event have virtual id linked to a real id
|
||||
* virtual event id "23-20170418020000" is linked to the event id 23
|
||||
*
|
||||
* @override
|
||||
* @private
|
||||
* @param {integer|string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
_formatValue: function (value) {
|
||||
if (typeof value === 'string') {
|
||||
if (!/^[0-9]+-/.test(value)) {
|
||||
throw new Error('"' + value + '" is not an integer or a virtual id');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return field_utils.format.integer(value, this.field);
|
||||
},
|
||||
});
|
||||
|
||||
var FieldFloat = InputField.extend({
|
||||
|
||||
@@ -292,7 +292,7 @@ return AbstractModel.extend({
|
||||
return this._rpc({
|
||||
model: this.modelName,
|
||||
method: 'write',
|
||||
args: [record.id, data],
|
||||
args: [[record.id], data],
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -1521,6 +1521,31 @@ QUnit.module('basic_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('integer field in form view with virtual id', function(assert) {
|
||||
assert.expect(2);
|
||||
var params = {
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch:'<form string="Partners"><field name="id"/></form>',
|
||||
};
|
||||
|
||||
params.res_id = this.data.partner.records[1].id = "2-20170808020000";
|
||||
var form = createView(params);
|
||||
assert.strictEqual(form.$('.o_form_field').text(), "2-20170808020000",
|
||||
"Should display virtual id");
|
||||
form.destroy();
|
||||
|
||||
params.res_id = this.data.partner.records[1].id = "2.65-20170808020000";
|
||||
try {
|
||||
form = createView(params);
|
||||
} catch (error) {
|
||||
assert.strictEqual(error.message, '"2.65-20170808020000" is not an integer or a virtual id',
|
||||
"Should throw an exception because it's a wrong value");
|
||||
}
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('integer field in editable list view', function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user