From 67adc9d9a9be92dfdc9b9514f60a68e8395426cd Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 22 Aug 2017 10:20:49 +0200 Subject: [PATCH] [FIX] account: update the reconciliation line on input instead of on blur This change is used to view the residual amount when the amount used for the write-off. Create a new line on key press enter. --- .../reconciliation/reconciliation_renderer.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/addons/account/static/src/js/reconciliation/reconciliation_renderer.js b/addons/account/static/src/js/reconciliation/reconciliation_renderer.js index d750f73503d..ff0abf316ec 100644 --- a/addons/account/static/src/js/reconciliation/reconciliation_renderer.js +++ b/addons/account/static/src/js/reconciliation/reconciliation_renderer.js @@ -253,10 +253,13 @@ var LineRenderer = Widget.extend(FieldManagerMixin, { 'click .accounting_view .line_info_button.fa-exclamation-triangle': '_onTogglePartialReconcile', 'click .reconcile_model_create': '_onCreateReconcileModel', 'click .reconcile_model_edit': '_onEditReconcileModel', + 'keyup input': '_onInputKeyup', + 'blur input': '_onInputKeyup', }, custom_events: _.extend({}, FieldManagerMixin.custom_events, { 'field_changed': '_onFieldChanged', }), + _avoidFieldUpdate: {}, /** * create partner_id field in editable mode @@ -400,6 +403,7 @@ var LineRenderer = Widget.extend(FieldManagerMixin, { this.model.notifyChanges(this.handleCreateRecord, state.createForm); var record = this.model.get(this.handleCreateRecord); _.each(this.fields, function (field, fieldName) { + if (self._avoidFieldUpdate[fieldName]) return; if (fieldName === "partner_id") return; if ((data[fieldName] || state.createForm[fieldName]) && !_.isEqual(state.createForm[fieldName], data[fieldName])) { field.reset(record); @@ -591,6 +595,32 @@ var LineRenderer = Widget.extend(FieldManagerMixin, { _onFilterChange: function () { this.trigger_up('change_filter', {'data': _.str.strip($(event.target).val())}); }, + /** + * @private + * @param {keyup event} event + */ + _onInputKeyup: function (event) { + if(event.keyCode === 13) { + if (_.findWhere(this.model.lines, {mode: 'create'}).balance.amount) { + this._onCreateProposition(); + } + return; + } + + var self = this; + for (var fieldName in this.fields) { + var field = this.fields[fieldName]; + if (!field.$el.is(event.target)) { + continue; + } + this._avoidFieldUpdate[field.name] = event.type !== 'focusout'; + field.value = false; + field._setValue($(event.target).val()).then(function () { + self._avoidFieldUpdate[field.name] = false; + }); + break; + } + }, /** * @private */