Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit f22f236

Browse files
author
Paul Catinean
committed
Merge branch '12.0-T3118-fix-float-validation-input-support-comma-bizz-chp' into '12.0'
12.0 t3118 fix float validation input support comma bizz chp See merge request pledra/odoo-product-configurator!80
2 parents b6ca01e + 0eb2151 commit f22f236

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

website_product_configurator/controllers/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,12 @@ def get_orm_form_vals(self, form_vals, config_session):
270270
custom_field_value = values.get(custom_field, False)
271271

272272
if attr_line.custom and custom_field_value:
273+
lang = request.env['ir.qweb.field'].user_lang()
273274
custom_field_value = custom_field_value[0]
274275
if attr_line.attribute_id.custom_type in ['int', 'float']:
275-
custom_field_value = safe_eval(custom_field_value)
276+
custom_field_value = safe_eval(
277+
custom_field_value.replace(lang.decimal_point, '.')
278+
)
276279

277280
if attr_line.multi:
278281
field_value = [[6, False, field_value]]

website_product_configurator/data/config_form_templates.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
t-att-data-type="custom_type"
208208
t-att-name="'%s%s' % (custom_field_prefix, line.attribute_id.id)"
209209
t-att-class="'form-control custom_config_value spinner_qty' + (' required_config_attrib' if (custom_value or not line.value_ids) and line.required else '')"
210-
t-att-value="custom_value and custom_value.value or line.attribute_id.min_val or '0'"/>
210+
t-att-value="custom_value and product_tmpl.get_float_custom_val(custom_value.value) or line.attribute_id.min_val or '0'"/>
211211
<div class="input-group-append">
212212
<a t-attf-href="#" aria-label="Add one" title="Add one"
213213
t-att-class="'btn btn-link float_left d-md-inline-block js_add_qty' + (' btn-disabled' if custom_val and line.attribute_id.max_val and custom_val &gt;= line.attribute_id.max_val else '')">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from . import product_config
22
from . import res_config_settings
33
from . import sale_order
4+
from . import product_template
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from odoo import api, models
2+
3+
4+
class ProductTemplate(models.Model):
5+
_inherit = 'product.template'
6+
7+
@api.model
8+
def get_float_custom_val(self, custom_value):
9+
lang = self.env['ir.qweb.field'].user_lang()
10+
if not custom_value:
11+
return False
12+
return custom_value.replace('.', lang.decimal_point)

website_product_configurator/static/src/js/config_form.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ odoo.define('website_product_configurator.config_form', function (require) {
105105
} else {
106106
var values = data.value;
107107
var domains = data.domain;
108-
109108
var open_cfg_step_line_ids = data.open_cfg_step_line_ids;
110109
var config_image_vals = data.config_image_vals;
111110

@@ -483,6 +482,17 @@ odoo.define('website_product_configurator.config_form', function (require) {
483482
this._checkRequiredFields(custom_value);
484483
},
485484

485+
convert_to_float: function (value) {
486+
var l10n = _t.database.parameters;
487+
return value.split(l10n.decimal_point).join('.')
488+
},
489+
490+
convert_to_str: function (value) {
491+
value = value.toString()
492+
var l10n = _t.database.parameters;
493+
return value.split('.').join(l10n.decimal_point)
494+
},
495+
486496
_handleSppinerCustomValue: function (ev) {
487497
var self = this;
488498
ev.preventDefault();
@@ -493,7 +503,8 @@ odoo.define('website_product_configurator.config_form', function (require) {
493503
var max_val = parseFloat(custom_value.attr('max') || Infinity);
494504
var min_val = parseFloat(custom_value.attr('min') || 0);
495505
var new_qty = min_val;
496-
var ui_val = parseFloat(custom_value.val());
506+
var value = self.convert_to_float(custom_value.val())
507+
var ui_val = parseFloat(value);
497508
var custom_type = custom_value.attr('data-type');
498509
if (isNaN(ui_val)) {
499510
var message = "Please enter a number.";
@@ -522,6 +533,7 @@ odoo.define('website_product_configurator.config_form', function (require) {
522533
new_qty = min_val;
523534
}
524535
}
536+
new_qty = self.convert_to_str(new_qty)
525537
custom_value.val(new_qty);
526538
self._disableEnableAddRemoveQtyButton(current_target, new_qty ,max_val ,min_val)
527539
return custom_value;

0 commit comments

Comments
 (0)