diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-03-31 14:10:46 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 3d959382fd92aca6c48ea2413c646edcc1f178f4 (patch) | |
| tree | cd66edd59c9629b08bf314afd9156dbfb8d1bfa8 /addons/web/static/src/js/fields/relational_fields.js | |
| parent | 2d449f8f1ac314452285e0952a9228b1460a0910 (diff) | |
[FIX] web,mail: one2many records: multiple views
A record of the basic model may need to be displayed in different
views (e.g. a o2m record is displayed in the, e.g., Kanban view
inside the main form view, and if clicked, it is also displayed
in the form view opened in a dialog). However, the fields present
in those views may differ.
The previous implementation of fieldsInfo in the record didn't
handle that, as it was a dict whose keys were field names. With
this commit, the fieldsInfo is dict whose keys are view types, and
the values are dicts whose keys are field names (the fields of
the corresponding views, with they attrs in the view).
This allows to create multiple o2m records in a row in a form view.
Diffstat (limited to 'addons/web/static/src/js/fields/relational_fields.js')
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 7cd3ce8598e..e4ea88db789 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -99,6 +99,9 @@ var FieldMany2One = AbstractField.extend({ quick_create: true, }); this.m2o_value = field_utils.format.many2one(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}; }, start: function () { // what is 'this.floating' for? add a comment! @@ -201,7 +204,7 @@ var FieldMany2One = AbstractField.extend({ model: this.field.relation, method: 'name_create', args: [name], - context: this.record.getContext({fieldName: this.name}) + context: this.record.getContext(this.recordParams), }) .then(function (result) { if (self.mode === "edit") { @@ -261,8 +264,8 @@ var FieldMany2One = AbstractField.extend({ var def = $.Deferred(); this.orderer.add(def); - var context = this.record.getContext({fieldName: this.name}); - var domain = this.record.getDomain({fieldName: this.name}); + var context = this.record.getContext(this.recordParams); + var domain = this.record.getDomain(this.recordParams); var blacklisted_ids = this._getSearchBlacklist(); if (blacklisted_ids.length > 0) { @@ -356,7 +359,7 @@ var FieldMany2One = AbstractField.extend({ new dialogs.SelectCreateDialog(this, _.extend({}, this.nodeOptions, { res_model: this.field.relation, domain: this.record.getDomain({fieldName: this.name}), - context: _.extend({}, this.record.getContext({fieldName: this.name}), context || {}), + context: _.extend({}, this.record.getContext(this.recordParams), context || {}), title: (view === 'search' ? _t("Search: ") : _t("Create: ")) + this.string, initial_ids: ids ? _.map(ids, function (x) { return x[0]; }) : undefined, initial_view: view, @@ -394,7 +397,7 @@ var FieldMany2One = AbstractField.extend({ model: this.field.relation, method: 'get_formview_action', args: [[this.value.res_id]], - context: this.record.getContext({fieldName: this.name}), + context: this.record.getContext(this.recordParams), }) .then(function (action) { self.trigger_up('do_action', {action: action}); @@ -410,7 +413,7 @@ var FieldMany2One = AbstractField.extend({ return; } var self = this; - var context = this.record.getContext({fieldName: this.name}); + var context = this.record.getContext(this.recordParams); this._rpc({ model: this.field.relation, method: 'get_formview_id', @@ -531,6 +534,7 @@ var FieldX2Many = AbstractField.extend({ this.isReadonly = this.mode === 'readonly'; this.view = this.attrs.views.list || this.attrs.views.kanban; this.activeActions = {}; + this.recordParams = {fieldName: this.name, viewType: this.viewType}; var arch = this.view && this.view.arch; if (arch) { this.activeActions.create = arch.attrs.create ? @@ -780,8 +784,8 @@ var FieldOne2Many = FieldX2Many.extend({ */ _openFormDialog: function (params) { this.trigger_up('open_one2many_record', _.extend(params, { - domain: this.record.getDomain({fieldName: this.name}), - context: this.record.getContext({fieldName: this.name}), + domain: this.record.getDomain(this.recordParams), + context: this.record.getContext(this.recordParams), field: this.field, fields_view: this.attrs.views && this.attrs.views.form, viewInfo: this.view, @@ -873,7 +877,7 @@ var FieldMany2Many = FieldX2Many.extend({ new dialogs.SelectCreateDialog(this, { res_model: this.field.relation, domain: domain.concat(["!", ["id", "in", this.value.res_ids]]), - context: this.record.getContext({fieldName: this.name}), + context: this.record.getContext(this.recordParams), title: _t("Add: ") + this.string, no_create: this.nodeOptions.no_create || !this.activeActions.create, fields_view: this.attrs.views.form, @@ -900,8 +904,8 @@ var FieldMany2Many = FieldX2Many.extend({ */ _onOpenRecord: function (event) { _.extend(event.data, { - context: this.record.getContext({fieldName: this.name}), - domain: this.record.getDomain({fieldName: this.name}), + context: this.record.getContext(this.recordParams), + domain: this.record.getDomain(this.recordParams), fields_view: this.attrs.views && this.attrs.views.form, on_saved: this.trigger_up.bind(this, 'reload', {db_id: event.data.id}), readonly: this.mode === 'readonly', @@ -976,6 +980,7 @@ var FieldMany2ManyTags = AbstractField.extend({ this.many2one = new FieldMany2One(this, this.name, this.record, { idForLabel: this.idForLabel, mode: 'edit', + viewType: this.viewType, }); // to prevent the M2O to take the value of the M2M this.many2one.value = false; |
