mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[FIX] account_reconciliation_widget: Javascript make propositions
This commit is contained in:
@@ -559,40 +559,53 @@ odoo.define("account.ReconciliationModel", function (require) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
_loadReconciliationModel: function (params) {
|
_loadReconciliationModel: function (params) {
|
||||||
var self = this;
|
const def = $.Deferred();
|
||||||
return this._rpc({
|
this._rpc({
|
||||||
model: "account.reconcile.model",
|
model: "account.reconcile.model",
|
||||||
method: "search_read",
|
method: "search_read",
|
||||||
domain: params.domainReconcile || [],
|
domain: params.domainReconcile || [],
|
||||||
}).then(function (reconcileModels) {
|
}).then((reconcileModels) => {
|
||||||
var analyticTagIds = [];
|
const recIds = _.map(reconcileModels, "id");
|
||||||
for (var i = 0; i < reconcileModels.length; i++) {
|
// Clean
|
||||||
var modelTags = reconcileModels[i].analytic_tag_ids || [];
|
for (const reconcileModel of reconcileModels) {
|
||||||
for (var j = 0; j < modelTags.length; j++) {
|
reconcileModel.line_ids = [];
|
||||||
if (analyticTagIds.indexOf(modelTags[j]) === -1) {
|
|
||||||
analyticTagIds.push(modelTags[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return self
|
this._rpc({
|
||||||
._readAnalyticTags({res_ids: analyticTagIds})
|
model: "account.reconcile.model.line",
|
||||||
.then(function () {
|
method: "search_read",
|
||||||
for (var i = 0; i < reconcileModels.length; i++) {
|
domain: [["model_id", "in", recIds]],
|
||||||
var recModel = reconcileModels[i];
|
}).then((reconcileModelLines) => {
|
||||||
|
let analyticTagIds = [];
|
||||||
|
for (const reconcileModelLine of reconcileModelLines) {
|
||||||
|
const reconcileModelByLine = _.findWhere(reconcileModels, {
|
||||||
|
id: reconcileModelLine.model_id[0],
|
||||||
|
});
|
||||||
|
reconcileModelByLine.line_ids.push(reconcileModelLine);
|
||||||
|
analyticTagIds = analyticTagIds.concat(
|
||||||
|
reconcileModelLine.analytic_tag_ids || []
|
||||||
|
);
|
||||||
|
}
|
||||||
|
analyticTagIds = _.unique(analyticTagIds);
|
||||||
|
this._readAnalyticTags({res_ids: analyticTagIds}).then(() => {
|
||||||
|
for (const reconcileModel of reconcileModels) {
|
||||||
var analyticTagData = [];
|
var analyticTagData = [];
|
||||||
var modelTags = reconcileModels[i].analytic_tag_ids || [];
|
var modelTags = reconcileModel.analytic_tag_ids || [];
|
||||||
for (var j = 0; j < modelTags.length; j++) {
|
for (const tagId of modelTags) {
|
||||||
var tagId = modelTags[j];
|
|
||||||
analyticTagData.push([
|
analyticTagData.push([
|
||||||
tagId,
|
tagId,
|
||||||
self.analyticTags[tagId].display_name,
|
this.analyticTags[tagId].display_name,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
recModel.analytic_tag_ids = analyticTagData;
|
reconcileModel.analytic_tag_ids = analyticTagData;
|
||||||
}
|
}
|
||||||
self.reconcileModels = reconcileModels;
|
|
||||||
|
this.reconcileModels = reconcileModels;
|
||||||
|
return def.resolve();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return def;
|
||||||
},
|
},
|
||||||
_loadTaxes: function () {
|
_loadTaxes: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
@@ -624,7 +637,6 @@ odoo.define("account.ReconciliationModel", function (require) {
|
|||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
quickCreateProposition: function (handle, reconcileModelId) {
|
quickCreateProposition: function (handle, reconcileModelId) {
|
||||||
var self = this;
|
|
||||||
var line = this.getLine(handle);
|
var line = this.getLine(handle);
|
||||||
var reconcileModel = _.find(this.reconcileModels, function (r) {
|
var reconcileModel = _.find(this.reconcileModels, function (r) {
|
||||||
return r.id === reconcileModelId;
|
return r.id === reconcileModelId;
|
||||||
@@ -640,34 +652,41 @@ odoo.define("account.ReconciliationModel", function (require) {
|
|||||||
"tax_ids",
|
"tax_ids",
|
||||||
"analytic_tag_ids",
|
"analytic_tag_ids",
|
||||||
"to_check",
|
"to_check",
|
||||||
"amount_from_label_regex",
|
"amount_string",
|
||||||
"decimal_separator",
|
"decimal_separator",
|
||||||
];
|
];
|
||||||
this._blurProposition(handle);
|
this._blurProposition(handle);
|
||||||
var focus = this._formatQuickCreate(line, _.pick(reconcileModel, fields));
|
let focus = null;
|
||||||
focus.reconcileModelId = reconcileModelId;
|
const defs = [];
|
||||||
line.reconciliation_proposition.push(focus);
|
for (const reconcileModelLineIndex in reconcileModel.line_ids) {
|
||||||
var defs = [];
|
const reconcileModelLine =
|
||||||
if (reconcileModel.has_second_line) {
|
reconcileModel.line_ids[reconcileModelLineIndex];
|
||||||
defs.push(
|
if (reconcileModelLineIndex === "0") {
|
||||||
self._computeLine(line).then(function () {
|
focus = this._formatQuickCreate(
|
||||||
var second = {};
|
line,
|
||||||
_.each(fields, function (key) {
|
_.pick(reconcileModelLine, fields),
|
||||||
second[key] =
|
reconcileModel
|
||||||
"second_" + key in reconcileModel
|
);
|
||||||
? reconcileModel["second_" + key]
|
focus.reconcileModelId = reconcileModelId;
|
||||||
: reconcileModel[key];
|
line.reconciliation_proposition.push(focus);
|
||||||
});
|
} else {
|
||||||
var second_focus = self._formatQuickCreate(line, second);
|
defs.push(
|
||||||
second_focus.reconcileModelId = reconcileModelId;
|
this._computeLine(line).then(() => {
|
||||||
line.reconciliation_proposition.push(second_focus);
|
const second_focus = this._formatQuickCreate(
|
||||||
self._computeReconcileModels(handle, reconcileModelId);
|
line,
|
||||||
})
|
_.pick(reconcileModelLine, fields),
|
||||||
);
|
reconcileModel
|
||||||
|
);
|
||||||
|
second_focus.reconcileModelId = reconcileModelId;
|
||||||
|
line.reconciliation_proposition.push(second_focus);
|
||||||
|
this._computeReconcileModels(handle, reconcileModelId);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Promise.all(defs).then(function () {
|
return Promise.all(defs).then(() => {
|
||||||
line.createForm = _.pick(focus, self.quickCreateFields);
|
line.createForm = _.pick(focus, this.quickCreateFields);
|
||||||
return self._computeLine(line);
|
return this._computeLine(line);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@@ -1566,7 +1585,7 @@ odoo.define("account.ReconciliationModel", function (require) {
|
|||||||
* @param {Object} values
|
* @param {Object} values
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
_formatQuickCreate: function (line, values) {
|
_formatQuickCreate: function (line, values, reconcileModel) {
|
||||||
values = values || {};
|
values = values || {};
|
||||||
var today = new moment().utc().format();
|
var today = new moment().utc().format();
|
||||||
var account = this._formatNameGet(values.account_id);
|
var account = this._formatNameGet(values.account_id);
|
||||||
@@ -1580,14 +1599,17 @@ odoo.define("account.ReconciliationModel", function (require) {
|
|||||||
break;
|
break;
|
||||||
case "regex":
|
case "regex":
|
||||||
var matching = line.st_line.name.match(
|
var matching = line.st_line.name.match(
|
||||||
new RegExp(values.amount_from_label_regex)
|
new RegExp(values.amount_string)
|
||||||
);
|
);
|
||||||
if (matching && matching.length == 2) {
|
if (matching && matching.length == 2) {
|
||||||
matching = matching[1].replace(
|
matching = matching[1].replace(
|
||||||
new RegExp("\\D" + values.decimal_separator, "g"),
|
new RegExp("\\D" + reconcileModel.decimal_separator, "g"),
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
matching = matching.replace(values.decimal_separator, ".");
|
matching = matching.replace(
|
||||||
|
reconcileModel.decimal_separator,
|
||||||
|
"."
|
||||||
|
);
|
||||||
amount = parseFloat(matching) || 0;
|
amount = parseFloat(matching) || 0;
|
||||||
amount = line.balance.amount > 0 ? amount : -amount;
|
amount = line.balance.amount > 0 ? amount : -amount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -514,11 +514,11 @@ odoo.define("account.ReconciliationRenderer", function (require) {
|
|||||||
|
|
||||||
// Create form
|
// Create form
|
||||||
if (state.createForm) {
|
if (state.createForm) {
|
||||||
var createPromise = null;
|
var createPromise = Promise.resolve();
|
||||||
if (!this.fields.account_id) {
|
if (!this.fields.account_id) {
|
||||||
createPromise = this._renderCreate(state);
|
createPromise = this._renderCreate(state);
|
||||||
}
|
}
|
||||||
Promise.resolve(createPromise).then(function () {
|
createPromise.then(function () {
|
||||||
var data = self.model.get(self.handleCreateRecord).data;
|
var data = self.model.get(self.handleCreateRecord).data;
|
||||||
return self.model
|
return self.model
|
||||||
.notifyChanges(self.handleCreateRecord, state.createForm)
|
.notifyChanges(self.handleCreateRecord, state.createForm)
|
||||||
|
|||||||
Reference in New Issue
Block a user