summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
authorMartin Geubelle <mge@odoo.com>2017-08-18 15:35:17 +0200
committerMartin Geubelle <mge@odoo.com>2017-08-22 14:18:14 +0200
commitdbab6f74171c895ba8196653b2755361ac34a823 (patch)
tree61c3ca8e4d85c79cc2db78cbb6e308010a4bcd79 /addons/web/static/src/js/fields
parent717b472ef9ad6d2998cbefb4aafe2d1199e6235d (diff)
[FIX] web: advanced use of widget `reference`
The reference widget is also meant to be used on a char field, not only on a reference field. The rev. https://github.com/odoo/odoo/commit/a4e30a1b43d0b9acd76508d9e6c466cd1dbdffab removed the use of `field_utils.format.many2one` and replaced it by `_formatValue` to support this use case. The replacement wasn't complete as some occurences was remaining (in reset), which led to traceback when the widget was reset (impossible to create an External Identifier anymore). Also, the reference `_formatValue` wasn't correct as it was displaying the record `display_name` and not the reference field value ; this only makes sense for the External Identifier as its display name is the reference field value but it doesn't make any sense for other reference field. Last but not least, this commit implements the `onchange` and `default_get` for the reference field.
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js49
1 files changed, 28 insertions, 21 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index 0dce6ec2bb4..7b1aa80a835 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -21,7 +21,6 @@ var dialogs = require('web.view_dialogs');
var core = require('web.core');
var data = require('web.data');
var Dialog = require('web.Dialog');
-var field_utils = require('web.field_utils');
var KanbanRenderer = require('web.KanbanRenderer');
var ListRenderer = require('web.ListRenderer');
var Pager = require('web.Pager');
@@ -290,7 +289,7 @@ var FieldMany2One = AbstractField.extend({
_reset: function () {
this._super.apply(this, arguments);
this.floating = false;
- this.m2o_value = field_utils.format.many2one(this.value);
+ this.m2o_value = this._formatValue(this.value);
},
/**
* @private
@@ -567,7 +566,7 @@ var KanbanFieldMany2One = AbstractField.extend({
tagName: 'span',
init: function () {
this._super.apply(this, arguments);
- this.m2o_value = field_utils.format.many2one(this.value);
+ this.m2o_value = this._formatValue(this.value);
},
//--------------------------------------------------------------------------
@@ -2023,7 +2022,8 @@ var FieldRadio = FieldSelection.extend({
* `name_get` as data).
*/
var FieldReference = FieldMany2One.extend({
- supportedFieldTypes: ['reference'],
+ specialData: "_fetchSpecialReference",
+ supportedFieldTypes: ['char', 'reference'],
template: 'FieldReference',
events: _.extend({}, FieldMany2One.prototype.events, {
'change select': '_onSelectionChange',
@@ -2036,22 +2036,8 @@ var FieldReference = FieldMany2One.extend({
// needs to be copied as it is an unmutable object
this.field = _.extend({}, this.field);
- if (this.value) {
- var model = null;
- // The value of a Reference field can either be a string in the form
- // of model,record_id or an object
- if (typeof this.value === "string") {
- var value = this.value.split(',');
- model = value[0];
- this.value = {
- res_id: parseInt(value[1]),
- };
- } else {
- model = this.value.model;
- }
- this._setRelation(model);
- }
+ this._setState();
},
/**
* @override
@@ -2071,7 +2057,13 @@ var FieldReference = FieldMany2One.extend({
* @override
*/
_formatValue: function () {
- return this.recordData.display_name;
+ var value;
+ if (this.field.type === 'char') {
+ value = this.record.specialData[this.name];
+ } else {
+ value = this.value;
+ }
+ return value && value.data && value.data.display_name || '';
},
/**
@@ -2097,8 +2089,10 @@ var FieldReference = FieldMany2One.extend({
* @private
*/
_reset: function () {
+ var value = this.$('select').val();
+ this._setState();
this._super.apply(this, arguments);
- this._setRelation(this.value && this.value.model);
+ this.$('select').val(this.value && this.value.model || value);
},
/**
* Set `relation` key in field properties.
@@ -2111,6 +2105,19 @@ var FieldReference = FieldMany2One.extend({
this.field.relation = model;
},
/**
+ * @private
+ */
+ _setState: function () {
+ if (this.field.type === 'char') {
+ // in this case, the value is stored in specialData instead
+ this.value = this.record.specialData[this.name];
+ }
+
+ if (this.value) {
+ this._setRelation(this.value.model);
+ }
+ },
+ /**
* @override
* @private
*/