summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-03-27 11:41:05 +0200
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commitc94b4b3b5fdbb234ad62111d5e44165e257f9a6b (patch)
tree451f8ba800904e63fc201f20fdf2bbd6f019ac67 /addons/web/static/src/js/fields
parent95919924698e8b8e2458c86d98ec2b61834c022f (diff)
[FIX] web: o2m: reset fieldsInfo after edition
One2Many fields edition (creation of new related records or edition of existing ones) needs a specific handling, because the related records aren't saved when the user clicks on 'Save' in the dialog, but when he clicks on 'Save' in the main form view. To make this work, the model (instance of BasicModel) and the representation of the edited record in the model must be given to the form in the dialog. Problem is that the fields to display in the kanban or list view and the form view in the dialog may be different, so when opening the dialog, the list of fields in the record is updated, and this list must be reset to its original value when the user closes the dialog. This last part wasn't done correctly before this commit, which causes tracebacks when the kanban/list view contained fields that weren't in the form view.
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js73
1 files changed, 38 insertions, 35 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index ef463338338..bdd291c6fab 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -704,19 +704,13 @@ var FieldX2Many = AbstractField.extend({
}
},
/**
- * Intercepts the 'open_record' event to edit its data and lets it bubble up
- * to the form view.
+ * Called when the user clicks on a relational record.
*
+ * @abstract
* @private
*/
- _onOpenRecord: function (event) {
- _.extend(event.data, {
- context: this.record.getContext({fieldName: this.name}),
- domain: this.record.getDomain({fieldName: this.name}),
- form_view: this.attrs.views && this.attrs.views.form,
- readonly: this.mode === 'readonly',
- string: this.string,
- });
+ _onOpenRecord: function () {
+ // to implement
},
/**
* Adds field name information to the event, so that the view upstream is
@@ -780,6 +774,19 @@ var FieldOne2Many = FieldX2Many.extend({
this._super.apply(this, arguments);
}
},
+ /**
+ * @private
+ * @param {Object} params
+ */
+ _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}),
+ field: this.field,
+ fields_view: this.attrs.views && this.attrs.views.form,
+ viewInfo: this.view,
+ }));
+ },
//--------------------------------------------------------------------------
// Handlers
@@ -804,17 +811,11 @@ var FieldOne2Many = FieldX2Many.extend({
position: this.editable,
});
} else {
- this.trigger_up('add_one2many_record', {
- domain: this.record.getDomain({fieldName: this.name}),
- context: this.record.getContext({fieldName: this.name}),
- field: this.field,
- attrs: this.attrs,
- on_save: function (record) {
- this._setValue({
- operation: 'ADD',
- id: record.id
- });
- }.bind(this),
+ var self = this;
+ this._openFormDialog({
+ on_saved: function (record) {
+ self._setValue({ operation: 'ADD', id: record.id });
+ },
});
}
},
@@ -825,19 +826,18 @@ var FieldOne2Many = FieldX2Many.extend({
* this change is saved in DB when the user clicks on 'Save' in the main
* form view.
*
- * @override
* @private
- * @param {OdooEvent}
+ * @param {OdooEvent} event
*/
_onOpenRecord: function (event) {
- var self = this;
- _.extend(event.data, {
- shouldSaveLocally: true,
- on_saved: function () {
- self._setValue({ operation: 'NOOP' });
- },
+ // we don't want interference with the components upstream.
+ event.stopPropagation();
+
+ this._openFormDialog({
+ id: event.data.id,
+ on_saved: this._setValue.bind(this, { operation: 'NOOP' }),
+ readonly: this.mode === 'readonly',
});
- this._super.apply(this, arguments);
},
});
@@ -864,7 +864,6 @@ var FieldMany2Many = FieldX2Many.extend({
*
* @override
* @private
- * @param {OdooEvent}
*/
_onAddRecord: function () {
var self = this;
@@ -893,17 +892,21 @@ var FieldMany2Many = FieldX2Many.extend({
}).open();
},
/**
- * Overrides the handler to reload the field when the subrecord is saved.
+ * Intercepts the 'open_record' event to edit its data and lets it bubble up
+ * to the form view.
*
- * @override
* @private
- * @param {OdooEvent}
+ * @param {OdooEvent} event
*/
_onOpenRecord: function (event) {
_.extend(event.data, {
+ context: this.record.getContext({fieldName: this.name}),
+ domain: this.record.getDomain({fieldName: this.name}),
+ 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',
+ string: this.string,
});
- this._super.apply(this, arguments);
},
});