From d0a545df78092ca0d86170b34877d4d32e24e66c Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 29 Dec 2017 11:49:07 +0100 Subject: [PATCH] [FIX] account: hide 'Write-off' button if the currency balance is null Issue: display the 'Write-off' button is very confusing for the user, because in the bill, the amount is null but not in the converted value. --- .../js/reconciliation/reconciliation_model.js | 9 ++++---- .../reconciliation/reconciliation_renderer.js | 4 ++-- .../static/src/xml/account_reconciliation.xml | 8 +++---- .../static/tests/reconciliation_tests.js | 23 ++++++++++++++++--- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/addons/account/static/src/js/reconciliation/reconciliation_model.js b/addons/account/static/src/js/reconciliation/reconciliation_model.js index 4fbd083e7d9..7ff23303006 100644 --- a/addons/account/static/src/js/reconciliation/reconciliation_model.js +++ b/addons/account/static/src/js/reconciliation/reconciliation_model.js @@ -498,7 +498,7 @@ var StatementModel = BasicModel.extend({ var amount = line.balance.amount; var amount_str = _.str.sprintf('%.2f', Math.abs(amount)); amount_str = (amount > '0' ? '-' : '+') + amount_str; - if (line.balance.amount_currency) { + if (line.balance.currency_id && line.balance.amount_currency) { var amount_currency = line.balance.amount_currency; var amount_currency_str = _.str.sprintf('%.2f', Math.abs(amount_currency)); amount_str += '|' + (amount_currency > '0' ? '-' : '+') + amount_currency_str; @@ -818,14 +818,13 @@ var StatementModel = BasicModel.extend({ amount: total, amount_str: field_utils.format.monetary(Math.abs(total), {}, formatOptions), currency_id: isOtherCurrencyId, - amount_currency: isOtherCurrencyId ? amount_currency : false, + amount_currency: isOtherCurrencyId ? amount_currency : total, amount_currency_str: isOtherCurrencyId ? field_utils.format.monetary(Math.abs(amount_currency), {}, { currency_id: isOtherCurrencyId }) : false, account_code: self.accounts[line.st_line.open_balance_account_id], }; - line.balance.type = (isOtherCurrencyId && amount_currency || line.balance.amount) ? - (line.balance.amount > 0 && line.st_line.partner_id ? 0 : -1) : 1; + line.balance.type = line.balance.amount_currency ? (line.balance.amount_currency > 0 && line.st_line.partner_id ? 0 : -1) : 1; }); }, /** @@ -1293,7 +1292,7 @@ var ManualModel = StatementModel.extend({ return this._super(line).then(function () { var props = _.reject(line.reconciliation_proposition, 'invalid'); line.balance.type = -1; - if (!line.balance.amount && props.length) { + if (!line.balance.amount_currency && props.length) { line.balance.type = 1; } else if(_.any(props, function (prop) {return prop.amount > 0;}) && _.any(props, function (prop) {return prop.amount < 0;})) { diff --git a/addons/account/static/src/js/reconciliation/reconciliation_renderer.js b/addons/account/static/src/js/reconciliation/reconciliation_renderer.js index 47910876d36..31f14eb3a51 100644 --- a/addons/account/static/src/js/reconciliation/reconciliation_renderer.js +++ b/addons/account/static/src/js/reconciliation/reconciliation_renderer.js @@ -355,7 +355,7 @@ var LineRenderer = Widget.extend(FieldManagerMixin, { .attr("data-content", qweb.render('reconciliation.line.mv_line.details', {'line': line})); } - if ((state.balance.amount !== 0 || line.partial_reconcile) && props.length === 1 && + if ((state.balance.amount_currency !== 0 || line.partial_reconcile) && props.length === 1 && line.already_paid === false && ( (state.st_line.amount > 0 && state.st_line.amount < props[0].amount) || @@ -417,7 +417,7 @@ var LineRenderer = Widget.extend(FieldManagerMixin, { } }); } - this.$('.create .add_line').toggle(!!state.balance.amount); + this.$('.create .add_line').toggle(!!state.balance.amount_currency); }, //-------------------------------------------------------------------------- diff --git a/addons/account/static/src/xml/account_reconciliation.xml b/addons/account/static/src/xml/account_reconciliation.xml index 66c573a44b2..58005afa303 100644 --- a/addons/account/static/src/xml/account_reconciliation.xml +++ b/addons/account/static/src/xml/account_reconciliation.xml @@ -125,13 +125,13 @@ - + - Create Write-offOpen balanceChoose counterpart - - + Create Write-offOpen balanceChoose counterpart + + diff --git a/addons/account/static/tests/reconciliation_tests.js b/addons/account/static/tests/reconciliation_tests.js index afe44157a2a..ec763da8a3d 100644 --- a/addons/account/static/tests/reconciliation_tests.js +++ b/addons/account/static/tests/reconciliation_tests.js @@ -448,7 +448,10 @@ var move_lines_for_manual_reconciliation = { '[7,12,"",0,6]': [ {'account_type': "receivable", 'account_id': [287, "101200 Account Receivable"], 'amount_currency_str': "", 'currency_id': false, 'date_maturity': "2017-02-08", 'date': "2017-02-08", 'total_amount_str': "$ 11,000.00", 'partner_id': 12, 'account_name': "101200 Account Receivable", 'name': "INV/2017/0004: Customer Payment", 'partner_name': "Camptocamp", 'total_amount_currency_str': "", 'id': 17, 'credit': 11000.0, 'journal_id': [1, "Customer Invoices"], 'amount_str': "$ 11,000.00", 'debit': 0.0, 'account_code': "101200", 'ref': "", 'already_paid': false}, {'account_type': "receivable", 'account_id': [7, "101200 Account Receivable"], 'amount_currency_str': "", 'currency_id': false, 'date_maturity': "2017-02-09", 'date': "2017-02-09", 'total_amount_str': "$ 1,000.00", 'partner_id': 12, 'account_name': "101200 Account Receivable", 'name': "INV/2017/0005: Customer Payment", 'partner_name': "Camptocamp", 'total_amount_currency_str': "", 'id': 19, 'credit': 1000.0, 'journal_id': [1, "Customer Invoices"], 'amount_str': "$ 1,000.00", 'debit': 0.0, 'account_code': "101200", 'ref': "", 'already_paid': false}, - {'account_type': "receivable", 'account_id': [287, "101200 Account Receivable"], 'amount_currency_str': "", 'currency_id': false, 'date_maturity': "2017-02-09", 'date': "2017-02-09", 'total_amount_str': "$ 180.00", 'partner_id': 12, 'account_name': "101200 Account Receivable", 'name': "BILL/2017/0003: Customer Payment", 'partner_name': "Camptocamp", 'total_amount_currency_str': "", 'id': 21, 'credit': 180.0, 'journal_id': [2, "Vendor Bills"], 'amount_str': "$ 180.00", 'debit': 0.0, 'account_code': "101200", 'ref': "fddfgfdgfdgsdfg", 'already_paid': false}, + {'account_type': "receivable", 'account_id': [287, "101200 Account Receivable"], 'amount_currency': 100, 'amount_currency_str': "100.00 €", 'currency_id': 1, 'date_maturity': "2017-02-09", 'date': "2017-02-09", 'total_amount_str': "$ 170.00", 'partner_id': 12, 'account_name': "101200 Account Receivable", 'name': "INV/2017/0003: Customer Payment", 'partner_name': "Camptocamp", 'total_amount_currency_str': "", 'id': 21, 'credit': 0.0, 'journal_id': [1, "Customer Invoices"], 'amount_str': "$ 170.00", 'debit': 170.0, 'account_code': "101200", 'ref': "INV fddfgfdgfdgsdfg", 'already_paid': false}, + {'account_type': "receivable", 'account_id': [287, "101200 Account Receivable"], 'amount_currency': 100, 'amount_currency_str': "100.00 €", 'currency_id': 1, 'date_maturity': "2017-02-10", 'date': "2017-02-10", 'total_amount_str': "$ 180.00", 'partner_id': 12, 'account_name': "101200 Account Receivable", 'name': "BILL/2017/0003: Customer Payment", 'partner_name': "Camptocamp", 'total_amount_currency_str': "", 'id': 22, 'credit': 180.0, 'journal_id': [2, "Vendor Bills"], 'amount_str': "$ 180.00", 'debit': 0.0, 'account_code': "101200", 'ref': "fddfgfdgfdgsdfg", 'already_paid': false}, + {'account_type': "receivable", 'account_id': [287, "101200 Account Receivable"], 'amount_currency': 170, 'amount_currency_str': "170.00 €", 'currency_id': 1, 'date_maturity': "2017-02-09", 'date': "2017-02-09", 'total_amount_str': "$ 100.00", 'partner_id': 12, 'account_name': "101200 Account Receivable", 'name': "INV/2017/0003: Customer Payment", 'partner_name': "Camptocamp", 'total_amount_currency_str': "", 'id': 23, 'credit': 0.0, 'journal_id': [1, "Customer Invoices"], 'amount_str': "$ 100.00", 'debit': 100.0, 'account_code': "101200", 'ref': "INV fddfgfdgfdgsdfg", 'already_paid': false}, + {'account_type': "receivable", 'account_id': [287, "101200 Account Receivable"], 'amount_currency': 180, 'amount_currency_str': "180.00 €", 'currency_id': 1, 'date_maturity': "2017-02-10", 'date': "2017-02-10", 'total_amount_str': "$ 100.00", 'partner_id': 12, 'account_name': "101200 Account Receivable", 'name': "BILL/2017/0003: Customer Payment", 'partner_name': "Camptocamp", 'total_amount_currency_str': "", 'id': 24, 'credit': 100.0, 'journal_id': [2, "Vendor Bills"], 'amount_str': "$ 100.00", 'debit': 0.0, 'account_code': "101200", 'ref': "fddfgfdgfdgsdfg", 'already_paid': false}, ], '[284,8,"",0,6]': [ {'account_type': "receivable", 'account_id': [284, "111100 Account Payable"], 'amount_currency_str': "", 'currency_id': false, 'date_maturity': "2017-02-08", 'date': "2017-02-08", 'total_amount_str': "$ 11,000.00", 'partner_id': 8, 'account_name': "101200 Account Receivable", 'name': "INV/2017/0004: Customer Payment", 'partner_name': "Agrolait", 'total_amount_currency_str': "", 'id': 17, 'credit': 11000.0, 'journal_id': [1, "Customer Invoices"], 'amount_str': "$ 11,000.00", 'debit': 0.0, 'account_code': "111100", 'ref': "", 'already_paid': false}, @@ -1117,7 +1120,7 @@ QUnit.module('account', { testUtils.addMockEnvironment(clientAction, { 'data': this.params.data, }); - clientAction.appendTo($('body')); + clientAction.appendTo($('#qunit-fixture')); clientAction.$('button.o_automatic_reconciliation').trigger('click'); @@ -1141,7 +1144,7 @@ QUnit.module('account', { }); QUnit.test('Reconciliation manual', function (assert) { - assert.expect(8); + assert.expect(12); var clientAction = new ReconciliationClientAction.ManualAction(null, this.params.options); @@ -1171,6 +1174,20 @@ QUnit.module('account', { assert.strictEqual(clientAction.$('.accounting_view:first .o_no_valid:visible').length, 1, "should display the skip button"); + clientAction.$('.accounting_view:eq(1) thead td:first').trigger('click'); + clientAction.$('.o_reconciliation_line:eq(1) [data-line-id="21"] .cell_label').trigger('click'); + clientAction.$('.o_reconciliation_line:eq(1) [data-line-id="22"] .cell_label').trigger('click'); + + assert.strictEqual(clientAction.$('.o_reconciliation_line:eq(1) tfoot tr').length, 0, "should not display the 'Write-off' line because the balance is null in Euro"); + assert.strictEqual(clientAction.$('.o_reconciliation_line:eq(1) .o_reconcile:visible').length, 1, "should display 'Reconcile' button in green"); + + clientAction.$('.o_reconciliation_line:eq(1) .o_reconcile:visible').trigger('click'); + clientAction.$('.o_reconciliation_line:eq(1) [data-line-id="23"] .cell_label').trigger('click'); + clientAction.$('.o_reconciliation_line:eq(1) [data-line-id="24"] .cell_label').trigger('click'); + + assert.strictEqual(clientAction.$('.o_reconciliation_line:eq(1) tfoot tr').length, 1, "should display the 'Write-off' line because the balance is not null in Euro"); + assert.strictEqual(clientAction.$('.o_reconciliation_line:eq(1) .o_validate:visible').length, 1, "should display 'Reconcile' button"); + clientAction.destroy(); });