diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-07-26 19:55:44 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-07-26 19:55:44 +0200 |
| commit | 4f501348c41f38befec5374e0e4b50b30c0e6989 (patch) | |
| tree | 837b3743b1b77da47451aa4b9b393ec517d5b6b1 /addons/web/static/src/js/fields/relational_fields.js | |
| parent | 8a497cdd5ff4cf93067d0519a9839ea6ec9adc21 (diff) | |
| parent | 46e1104ce12e3c31722d2f84ca79b78055e925d6 (diff) | |
[MERGE] forward port branch saas-16 up to 46e1104ce12
Diffstat (limited to 'addons/web/static/src/js/fields/relational_fields.js')
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 7522bb3bc37..1935e5804dd 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -99,7 +99,7 @@ var FieldMany2One = AbstractField.extend({ this.nodeOptions = _.defaults(this.nodeOptions, { quick_create: true, }); - this.m2o_value = field_utils.format.many2one(this.value); + this.m2o_value = this._formatValue(this.value); // 'recordParams' is a dict of params used when calling functions // 'getDomain' and 'getContext' on this.record this.recordParams = {fieldName: this.name, viewType: this.viewType}; @@ -838,8 +838,10 @@ var FieldX2Many = AbstractField.extend({ */ _onDeleteRecord: function (ev) { ev.stopPropagation(); + var shouldForget = this.attrs.widget === 'many2many' || this.field.type === 'many2many'; + var operation = shouldForget ? 'FORGET' : 'DELETE'; this._setValue({ - operation: 'REMOVE', + operation: operation, ids: [ev.data.id], }); }, @@ -1290,7 +1292,7 @@ var FieldMany2ManyBinaryMultiFiles = AbstractField.extend({ var record = _.findWhere(this.value.data, {res_id: fileID}); if (record) { this._setValue({ - operation: 'REMOVE', + operation: 'FORGET', ids: [record.id], }); var metadata = this.metadata[record.id]; @@ -1469,7 +1471,7 @@ var FieldMany2ManyTags = AbstractField.extend({ _removeTag: function (id) { var record = _.findWhere(this.value.data, {res_id: id}); this._setValue({ - operation: 'REMOVE', + operation: 'FORGET', ids: [record.id], }); }, @@ -2029,7 +2031,20 @@ var FieldReference = FieldMany2One.extend({ // needs to be copied as it is an unmutable object this.field = _.extend({}, this.field); if (this.value) { - this._setRelation(this.value.model); + 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); } }, /** @@ -2045,6 +2060,15 @@ var FieldReference = FieldMany2One.extend({ //-------------------------------------------------------------------------- /** + * Get the encompassing record's display_name + * + * @override + */ + _formatValue: function () { + return this.recordData.display_name; + }, + + /** * Add a select in edit mode (for the model). * * @override |
