[FIX] account: reconciliation widget monetary values comparison
Since monetary values are stored as float, use the method intented for float comparison using the maximum number of digits a currency can use. Until V9, the number of digits used was fetched from table decimal.precision, but as of V9, the accounting module stopped using it in favour of the digits number defined on currencies.
This commit is contained in:
@@ -76,6 +76,8 @@ var abstractReconciliation = Widget.extend(ControlPanelMixin, {
|
||||
|
||||
this.action_manager = this.findAncestor(function(ancestor){ return ancestor instanceof ActionManager });
|
||||
this.crash_manager = new CrashManager();
|
||||
// Method that tests if a monetary amount == 0, we use 4 digits because no currency uses more
|
||||
this.monetaryIsZero = _.partial(utils.float_is_zero, _, 4);
|
||||
this.formatCurrencies; // Method that formats the currency ; loaded from the server
|
||||
this.model_res_users = new Model("res.users");
|
||||
this.model_tax = new Model("account.tax");
|
||||
@@ -343,7 +345,7 @@ var abstractReconciliation = Widget.extend(ControlPanelMixin, {
|
||||
keyboardShortcutsHandler: function(e) {
|
||||
var self = this;
|
||||
if ((e.which === 13 || e.which === 10) && (e.ctrlKey || e.metaKey)) {
|
||||
self.processReconciliations(_.filter(self.getChildren(), function(o) { return o.get("balance").toFixed(3) === "0.000"; }));
|
||||
self.processReconciliations(_.filter(self.getChildren(), function(o) { return self.monetaryIsZero(o.get("balance")); }));
|
||||
}
|
||||
},
|
||||
|
||||
@@ -393,6 +395,7 @@ var abstractReconciliationLine = Widget.extend({
|
||||
|
||||
this.decorateMoveLine = this.getParent().decorateMoveLine;
|
||||
this.formatCurrencies = this.getParent().formatCurrencies;
|
||||
this.monetaryIsZero = this.getParent().monetaryIsZero;
|
||||
this.renderPresetsButtons = this.getParent().renderPresetsButtons;
|
||||
|
||||
if (context.initial_data_provided === true && (context.reconciliation_proposition === undefined || context.line === undefined))
|
||||
@@ -791,7 +794,7 @@ var abstractReconciliationLine = Widget.extend({
|
||||
_(self.getCreatedLines()).each(function(line){
|
||||
line.amount_str = self.formatCurrencies(Math.abs(line.amount), self.get("currency_id"));
|
||||
// Hack to show debit/credit 0 (can make sense for tax lines)
|
||||
if (previous_line !== undefined && line.amount.toFixed(3) === "0.000" && previous_line.id === line.id)
|
||||
if (previous_line !== undefined && self.monetaryIsZero(line.amount) && previous_line.id === line.id)
|
||||
line.amount = 0.000001 * (previous_line.amount < 0 ? -1 : 1);
|
||||
var $line = $(QWeb.render(template_name, {line: line}));
|
||||
self.$(".tbody_created_lines").append($line);
|
||||
@@ -1553,7 +1556,7 @@ var bankStatementReconciliation = abstractReconciliation.extend({
|
||||
.filter([['id', 'in', self.statement_ids]])
|
||||
.all()
|
||||
.then(function(data){
|
||||
if (_.all(data, function(o) { return o.balance_end_real === o.balance_end })) {
|
||||
if (_.all(data, function(o) { return self.monetaryIsZero(o.balance_end_real - o.balance_end) })) {
|
||||
self.$(".button_close_statement").show();
|
||||
self.$(".button_close_statement").click(function() {
|
||||
self.$(".button_close_statement").attr("disabled", "disabled");
|
||||
@@ -1605,6 +1608,7 @@ var bankStatementReconciliationLine = abstractReconciliationLine.extend({
|
||||
this.line_id = context.line_id;
|
||||
this.model_bank_statement_line = this.getParent().model_bank_statement_line;
|
||||
this.formatCurrencies = this.getParent().formatCurrencies;
|
||||
this.monetaryIsZero = this.getParent().monetaryIsZero;
|
||||
|
||||
if (context.initial_data_provided) {
|
||||
// Process data
|
||||
@@ -1850,7 +1854,7 @@ var bankStatementReconciliationLine = abstractReconciliationLine.extend({
|
||||
|
||||
// Find out if the counterpart is lower than, equal or greater than the transaction being reconciled
|
||||
var balance_type = undefined;
|
||||
if (Math.abs(self.get("balance")).toFixed(3) === "0.000") balance_type = "equal";
|
||||
if (self.monetaryIsZero(self.get("balance"))) balance_type = "equal";
|
||||
else if (self.get("balance") * self.st_line.amount > 0) balance_type = "greater";
|
||||
else if (self.get("balance") * self.st_line.amount < 0) balance_type = "lower";
|
||||
|
||||
@@ -2045,7 +2049,7 @@ var bankStatementReconciliationLine = abstractReconciliationLine.extend({
|
||||
var payment_aml = _.filter(this.get("mv_lines_selected"), function(line) { return line.already_paid });
|
||||
var payment_aml_ids = _.collect(payment_aml, function(line) { return line.id });
|
||||
var new_aml_dicts = this.prepareCreatedMoveLinesForPersisting(this.getCreatedLines());
|
||||
if (Math.abs(this.get("balance")).toFixed(4) !== "0.0000") new_aml_dicts.push(this.prepareOpenBalanceForPersisting());
|
||||
if (! self.monetaryIsZero(this.get("balance"))) new_aml_dicts.push(this.prepareOpenBalanceForPersisting());
|
||||
return {
|
||||
'counterpart_aml_dicts': counterpart_aml_dicts,
|
||||
'payment_aml_ids': payment_aml_ids,
|
||||
@@ -2449,12 +2453,12 @@ var manualReconciliationLine = abstractReconciliationLine.extend({
|
||||
if (self.get("mv_lines_selected").length < 2) {
|
||||
self.$(".button_reconcile").text(_t("Done"));
|
||||
self.persist_action = "mark_as_reconciled";
|
||||
} else if (Math.abs(balance).toFixed(4) === "0.0000") {
|
||||
} else if (self.monetaryIsZero(balance)) {
|
||||
self.$(".button_reconcile").addClass("btn-primary");
|
||||
}
|
||||
|
||||
self.$(".tbody_open_balance").empty();
|
||||
if (Math.abs(balance).toFixed(4) !== "0.0000" && self.get("mv_lines_selected").length > 1) {
|
||||
if ((! self.monetaryIsZero(balance)) && self.get("mv_lines_selected").length > 1) {
|
||||
var debit = (balance > 0 ? self.formatCurrencies(balance, self.get("currency_id")) : "");
|
||||
var credit = (balance < 0 ? self.formatCurrencies(-1*balance, self.get("currency_id")) : "");
|
||||
var $line = $(QWeb.render("manual_reconciliation_line_open_balance", {
|
||||
|
||||
Reference in New Issue
Block a user