diff options
| author | Lucas Perais (lpe) <lpe@odoo.com> | 2019-07-12 15:14:15 +0000 |
|---|---|---|
| committer | Lucas Perais (lpe) <lpe@odoo.com> | 2019-07-16 07:22:16 +0000 |
| commit | 1112ca05ab81ad4a716f042ede21d957dec754a1 (patch) | |
| tree | fc8213405e3c4c811a778c9e07c4e6fd3793fc89 /addons/account/static/src | |
| parent | 1bd434da34731b5467cc17fdffe6f3ed5dfea2d4 (diff) | |
[FIX] account: reconciliation model support tags in widget
Activate analytic tags
Create an reconciliation model on which you set at least one tag
Create a bank statement and a line
Click on reconcile (or access the reconciliation widget by another means)
Quick Create a writeoff line
Click on the button corresponding to the reconciliation model
Before this commit:
The many2many tags was buggy, there was one empty tag, corresponding to nothing
clicking on the field triggered errors
validating the reconciliation by clicking on reconcile triggered a server traceback
in the real backend, opening the tag form view triggered an access error
This was because the data were not formatted the right way to be passed to the m2m_tag_field through
notifyChanges
After this commit, the reconciliation model's tag renders and behaves well
Validating the reconciliation works
OPW 2033350
As a side note, in the future, the reconciliation widget Model should fully implement basicModel
or not at all. Some of the heavy plumbing that the ReconciliationModel does (fetch records, data...)
is imitating what fetchRecord does
closes odoo/odoo#34838
Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Diffstat (limited to 'addons/account/static/src')
| -rw-r--r-- | addons/account/static/src/js/reconciliation/reconciliation_model.js | 75 |
1 files changed, 56 insertions, 19 deletions
diff --git a/addons/account/static/src/js/reconciliation/reconciliation_model.js b/addons/account/static/src/js/reconciliation/reconciliation_model.js index ede81ea2043..d655d94ed01 100644 --- a/addons/account/static/src/js/reconciliation/reconciliation_model.js +++ b/addons/account/static/src/js/reconciliation/reconciliation_model.js @@ -384,14 +384,7 @@ var StatementModel = BasicModel.extend({ if (context && context.active_model === 'account.journal' && context.active_ids) { domainReconcile.push(['journal_id', 'in', [false].concat(context.active_ids)]); } - var def_reconcileModel = this._rpc({ - model: 'account.reconcile.model', - method: 'search_read', - domain: domainReconcile, - }) - .then(function (reconcileModels) { - self.reconcileModels = reconcileModels; - }); + var def_reconcileModel = this._loadReconciliationModel({domainReconcile: domainReconcile}); var def_account = this._rpc({ model: 'account.account', method: 'search_read', @@ -411,7 +404,59 @@ var StatementModel = BasicModel.extend({ return self._formatLine(self.statement.lines); }); }, - + _readAnalyticTags: function (params) { + var self = this; + this.analyticTags = {}; + if (!params || !params.res_ids || !params.res_ids.length) { + return $.when(); + } + var fields = (params && params.fields || []).concat(['id', 'display_name']); + return this._rpc({ + model: 'account.analytic.tag', + method: 'read', + args: [ + params.res_ids, + fields, + ], + }).then(function (tags) { + for (var i=0; i<tags.length; i++) { + var tag = tags[i]; + self.analyticTags[tag.id] = tag; + } + }); + }, + _loadReconciliationModel: function (params) { + var self = this; + return this._rpc({ + model: 'account.reconcile.model', + method: 'search_read', + domain: params.domainReconcile || [], + }) + .then(function (reconcileModels) { + var analyticTagIds = []; + for (var i=0; i<reconcileModels.length; i++) { + var modelTags = reconcileModels[i].analytic_tag_ids || []; + for (var j=0; j<modelTags.length; j++) { + if (analyticTagIds.indexOf(modelTags[j]) === -1) { + analyticTagIds.push(modelTags[j]); + } + } + } + return self._readAnalyticTags({res_ids: analyticTagIds}).then(function () { + for (var i=0; i<reconcileModels.length; i++) { + var recModel = reconcileModels[i]; + var analyticTagData = []; + var modelTags = reconcileModels[i].analytic_tag_ids || []; + for (var j=0; j<modelTags.length; j++) { + var tagId = modelTags[j]; + analyticTagData.push([tagId, self.analyticTags[tagId].display_name]) + } + recModel.analytic_tag_ids = analyticTagData; + } + self.reconcileModels = reconcileModels; + }); + }); + }, _loadTaxes: function(){ var self = this; self.taxes = {}; @@ -949,7 +994,7 @@ var StatementModel = BasicModel.extend({ _formatMany2ManyTags: function (value) { var res = []; for (var i=0, len=value.length; i<len; i++) { - res[i] = {data: {'id': value[i][0], 'display_name': value[i][1]}}; + res[i] = {'id': value[i][0], 'display_name': value[i][1]}; } return res; }, @@ -1290,15 +1335,7 @@ var ManualModel = StatementModel.extend({ if (company_ids) { domainReconcile.push(['company_id', 'in', company_ids]); } - var def_reconcileModel = this._rpc({ - model: 'account.reconcile.model', - method: 'search_read', - domain: domainReconcile, - }) - .then(function (reconcileModels) { - self.reconcileModels = reconcileModels; - }); - + var def_reconcileModel = this._loadReconciliationModel({domainReconcile: domainReconcile}); var def_taxes = this._loadTaxes(); return $.when(def_reconcileModel, def_account, def_taxes).then(function () { |
