[FIX] account: remove the warning in reconciliation widget for to_check

The goal of the to_check checkbox in the reconciliation widget is to set the to_check field present on the move that will be created. However since the UI is not perfect, the to_check checkbox was added on the wizard when we create a new line in the widget, which cause the following problem: what if we select to_check on line1 and then deselect it on line2, previously it was not possible to do this, a warning was thrown to tell the user that he had some line with to_check set and some other not. A better way to do this, and more user friendly is by preventing the user from deselecting the checkbox if some other line has the to_check value set.

closes odoo/odoo#33956

Signed-off-by: Cedric Snauwaert (csn) <csn@openerp.com>
This commit is contained in:
Cedric Snauwaert
2019-06-07 09:15:43 +00:00
parent e358c41313
commit cc6cc7ae8b
3 changed files with 28 additions and 32 deletions
@@ -281,7 +281,6 @@ var StatementModel = BasicModel.extend({
if (last && !this._isValid(last)) {
return $.Deferred().resolve(false);
}
prop = this._formatQuickCreate(line);
line.reconciliation_proposition.push(prop);
line.createForm = _.pick(prop, this.quickCreateFields);
@@ -493,13 +492,6 @@ var StatementModel = BasicModel.extend({
var focus = this._formatQuickCreate(line, _.pick(reconcileModel, fields));
focus.reconcileModelId = reconcileModelId;
if (!line.reconciliation_proposition.every(function(prop) {return prop.to_check == focus.to_check})) {
new CrashManager().show_warning({data: {
exception_type: _t("Incorrect Operation"),
message: _t("You cannot mix items with and without the 'To Check' checkbox ticked.")
}});
return $.when();
}
line.reconciliation_proposition.push(focus);
if (reconcileModel.has_second_line) {
@@ -620,18 +612,16 @@ var StatementModel = BasicModel.extend({
var self = this;
var line = this.getLine(handle);
var prop = _.last(_.filter(line.reconciliation_proposition, '__focus'));
if ('to_check' in values && values.to_check === false) {
// check if we have another line with to_check and if yes don't change value of this proposition
prop.to_check = line.reconciliation_proposition.some(function(rec_prop, index) {
return rec_prop.id !== prop.id && rec_prop.to_check;
});
}
if (!prop) {
prop = this._formatQuickCreate(line);
line.reconciliation_proposition.push(prop);
}
if ('to_check' in values && !line.reconciliation_proposition.slice(0,-1).every(function(prop) {return prop.to_check == values.to_check})) {
new CrashManager().show_warning({data: {
exception_type: _t("Incorrect Operation"),
message: _t("You cannot mix items with and without the 'To Check' checkbox ticked.")
}});
$('.create_to_check input:visible').prop('checked', !values.to_check).change();
return $.when();
}
_.each(values, function (value, fieldName) {
if (fieldName === 'analytic_tag_ids') {
switch (value.operation) {
@@ -671,7 +661,6 @@ var StatementModel = BasicModel.extend({
prop.amount = prop.base_amount;
}
line.createForm = _.pick(prop, this.quickCreateFields);
// If you check/uncheck the force_tax_included box, reset the createForm amount.
if(prop.base_amount)
line.createForm.amount = prop.base_amount;
@@ -724,16 +713,8 @@ var StatementModel = BasicModel.extend({
"new_aml_dicts": _.map(_.filter(props, function (prop) {
return isNaN(prop.id) && prop.display;
}), self._formatToProcessReconciliation.bind(self, line)),
"to_check": line.to_check,
};
line.reconciliation_proposition.some(function(prop) {
if (prop.to_check) {
values_dict['to_check'] = true;
return true;
}
})
if (line.reconciliation_proposition[0].to_check) {
values_dict['to_check'] = true;
}
// If the lines are not fully balanced, create an unreconciled amount.
// line.st_line.currency_id is never false here because its equivalent to
@@ -845,7 +826,12 @@ var StatementModel = BasicModel.extend({
var formatOptions = {
currency_id: line.st_line.currency_id,
};
line.to_check = false;
_.each(line.reconciliation_proposition, function (prop) {
if (prop.to_check) {
// If one of the proposition is to_check, set the global to_check flag to true
line.to_check = true;
}
if (prop.is_tax) {
if (!_.find(line.reconciliation_proposition, {'id': prop.link}).__tax_to_recompute) {
reconciliation_proposition.push(prop);
@@ -1129,7 +1115,7 @@ var StatementModel = BasicModel.extend({
'link': values.link,
'display': true,
'invalid': true,
'to_check': values.to_check || false,
'to_check': !!values.to_check,
'__tax_to_recompute': true,
'is_tax': values.is_tax,
'__focus': '__focus' in values ? values.__focus : true,
@@ -343,7 +343,7 @@ var LineRenderer = Widget.extend(FieldManagerMixin, {
update: function (state) {
var self = this;
// isValid
var to_check_checked = !!(state.reconciliation_proposition[0] && state.reconciliation_proposition[0].to_check);
var to_check_checked = !!(state.to_check);
this.$('caption .o_buttons button.o_validate').toggleClass('d-none', !!state.balance.type && !to_check_checked);
this.$('caption .o_buttons button.o_reconcile').toggleClass('d-none', state.balance.type <= 0 || to_check_checked);
this.$('caption .o_buttons .o_no_valid').toggleClass('d-none', state.balance.type >= 0);
@@ -460,6 +460,10 @@ var LineRenderer = Widget.extend(FieldManagerMixin, {
// Set the 'Tax Include' field editable or not depending of the 'price_include' value.
this.$('.create_force_tax_included input').attr('disabled', state.createForm.tax_id.price_include);
}
if (state.to_check) {
// Set the to_check field to true if global to_check is set
this.$('.create_to_check input').prop('checked', state.to_check).change();
}
}
this.$('.create .add_line').toggle(!!state.balance.amount_currency);
},
@@ -742,7 +742,7 @@ QUnit.module('account', {
"name": "INV/2017/0003",
"analytic_tag_ids": [[6, null, []]]
}],
payment_aml_ids: [], new_aml_dicts: []}]],
payment_aml_ids: [], new_aml_dicts: [], to_check: false}]],
"Should call process_bank_statement_line with ids");
var def = $.Deferred();
def.abort = function () {};
@@ -780,8 +780,10 @@ QUnit.module('account', {
// line is send back to server.
testUtils.mock.intercept(clientAction, 'call_service', function (event) {
assert.deepEqual(event.data.args[1].args,
[[5],[{partner_id: 8, counterpart_aml_dicts: [],
payment_aml_ids: [], new_aml_dicts: [{
[[5],[{partner_id: 8, to_check: false, counterpart_aml_dicts: [],
payment_aml_ids: [],
to_check: false,
new_aml_dicts: [{
account_id: 287,
credit: 1175,
debit: 0,
@@ -829,7 +831,7 @@ QUnit.module('account', {
// We also create a line which is the open balance.
testUtils.mock.intercept(clientAction, 'call_service', function (event) {
assert.deepEqual(event.data.args[1].args,
[[5],[{partner_id: 8,
[[5],[{partner_id: 8, to_check: false,
counterpart_aml_dicts: [{
counterpart_aml_id: 109,
credit: 650,
@@ -879,6 +881,7 @@ QUnit.module('account', {
}],
payment_aml_ids: [],
new_aml_dicts: [],
to_check: false,
}]
], "should call process_bank_statement_line with partial reconcile values");
}
@@ -1381,6 +1384,7 @@ QUnit.module('account', {
payment_aml_ids: [],
partner_id: 8,
to_check: false,
new_aml_dicts: []}]
], "should call process_bank_statement_line with partial reconcile values");
}
@@ -1472,6 +1476,7 @@ QUnit.module('account', {
payment_aml_ids: [],
partner_id: 8,
to_check: false,
new_aml_dicts: [
{account_id: 282,
credit: 0,
@@ -1580,6 +1585,7 @@ QUnit.module('account', {
payment_aml_ids: [],
partner_id: 8,
to_check: false,
new_aml_dicts: []
}]
], "should call process_bank_statement_line with correct counterpart_aml_dicts");