summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2021-03-12 13:51:48 +0000
committerNasreddin (bon) <bon@odoo.com>2021-03-15 14:27:56 +0000
commite795ce5bff14b6b748c1f4a2651946aafdc299f4 (patch)
treeb1a1c3f4f49f4c71503cdcf6446914b35c2b55a5 /addons/web/static/src/js
parentd2d495bca3e91862470702f1ef07aa27c33d8e2d (diff)
[FIX] web: allow filtering with decimals on price filter + unit test
Issue - Install "Sales" - Switch to "German" language - Go to Sales -> Products -> Products - Try to filter on "Public Price" is equal to "2,3" Not possible to add decimal point at the end (only in middle of number). Cause In case the 'decimal point' in DB params is not a dot '.', the filter input will be considered as 'text' instead of 'number'. In case of the 'number' type; HTML do already a pre and post processing, including managing decimal point (who, for example, is not included in ev.target.value if last char is a '.'). Unfortunalty, the library is not well working with other language and not supported on every browser, therefore, must use own logic. In case of a 'text' type, the value will be send to 'parseFloat' ,then `parseNumber` will replace decimal_point by dot (also one the issues since needed to display decimal_point according user language), and `Number` will remove the decimal_point in case of '123,' -> '123', and therefore we will not be able to write decimals ( apart of adding the decimal point after writing the whole number...) Solution If user input is well parsed, store parsed value in condition.value and set condition.displayedValue to the input value (an so without updating input value). Else, replace input value with previous value (who should be the condition.DisplayedValue). opw-2463441 closes odoo/odoo#67767 Signed-off-by: bon-odoo <nboulif@users.noreply.github.com>
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/control_panel/custom_filter_item.js32
1 files changed, 22 insertions, 10 deletions
diff --git a/addons/web/static/src/js/control_panel/custom_filter_item.js b/addons/web/static/src/js/control_panel/custom_filter_item.js
index 98080f6a418..0b9b1ccb8f4 100644
--- a/addons/web/static/src/js/control_panel/custom_filter_item.js
+++ b/addons/web/static/src/js/control_panel/custom_filter_item.js
@@ -105,6 +105,7 @@ odoo.define('web.CustomFilterItem', function (require) {
const fieldType = this.fields[condition.field].type;
const genericType = FIELD_TYPES[fieldType];
const operator = FIELD_OPERATORS[genericType][condition.operator];
+ // Logical value
switch (genericType) {
case 'id':
case 'number':
@@ -129,6 +130,12 @@ odoo.define('web.CustomFilterItem', function (require) {
default:
condition.value = "";
}
+ // Displayed value
+ if (["float", "monetary"].includes(fieldType)) {
+ condition.displayedValue = `0${this.DECIMAL_POINT}0`;
+ } else {
+ condition.displayedValue = String(condition.value);
+ }
}
//---------------------------------------------------------------------
@@ -235,20 +242,25 @@ odoo.define('web.CustomFilterItem', function (require) {
* @param {Event} ev
*/
_onValueInput(condition, ev) {
- const type = this.fields[condition.field].type;
- if (['float', 'integer', 'id'].includes(type)) {
- const previousValue = condition.value;
- const parser = field_utils.parse[type === 'float' ? 'float' : 'integer'];
+ if (!ev.target.value) {
+ return this._setDefaultValue(condition);
+ }
+ let { type } = this.fields[condition.field];
+ if (type === "id") {
+ type = "integer";
+ }
+ if (FIELD_TYPES[type] === "number") {
try {
- const parsed = parser(ev.target.value || 0);
- // Force parsed value in the input.
- ev.target.value = condition.value = (parsed || 0);
+ // Write logical value into the 'value' property
+ condition.value = field_utils.parse[type](ev.target.value);
+ // Write displayed value in the input and 'displayedValue' property
+ condition.displayedValue = ev.target.value;
} catch (err) {
- // Force previous value if non-parseable.
- ev.target.value = previousValue || 0;
+ // Parsing error: reverts to previous value
+ ev.target.value = condition.displayedValue;
}
} else {
- condition.value = ev.target.value || "";
+ condition.value = condition.displayedValue = ev.target.value;
}
}
}