Merge lp:~unifield-team/unifield-web/us-2156 into lp:unifield-web

Proposed by Quentin THEURET @Amaris
Status: Rejected
Rejected by: jftempo
Proposed branch: lp:~unifield-team/unifield-web/us-2156
Merge into: lp:unifield-web
Diff against target: 208 lines (+36/-19)
7 files modified
addons/openerp/controllers/form.py (+12/-8)
addons/openerp/utils/utils.py (+1/-1)
addons/openerp/validators.py (+2/-1)
addons/openerp/widgets/form/_form.py (+2/-2)
addons/openerp/widgets/listgrid.py (+6/-3)
addons/openerp/widgets/listgroup.py (+6/-3)
openobject/i18n/format.py (+7/-1)
To merge this branch: bzr merge lp:~unifield-team/unifield-web/us-2156
Reviewer Review Type Date Requested Status
UniField Dev Team Pending
Review via email: mp+317945@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

4838. By Quentin THEURET @Amaris

Merge https://code.launchpad.net/~jfb-tempo-consulting/unifield-web/utp-830

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'addons/openerp/controllers/form.py'
--- addons/openerp/controllers/form.py 2017-02-06 11:21:15 +0000
+++ addons/openerp/controllers/form.py 2017-02-22 08:04:53 +0000
@@ -84,8 +84,8 @@
84 data = data or {}84 data = data or {}
8585
86 proxy = rpc.RPCProxy(model)86 proxy = rpc.RPCProxy(model)
87 fields = proxy.fields_get([], rpc.session.context)87 if data:
8888 fields = proxy.fields_get(data.keys(), rpc.session.context)
89 search_domain = domain[:]89 search_domain = domain[:]
90 search_data = {}90 search_data = {}
9191
@@ -1206,6 +1206,7 @@
1206 # apply validators (transform values from python)1206 # apply validators (transform values from python)
1207 values = result['value']1207 values = result['value']
1208 values2 = {}1208 values2 = {}
1209 float_to_check = []
1209 for k, v in values.items():1210 for k, v in values.items():
1210 key = ((prefix or '') and prefix + '/') + k1211 key = ((prefix or '') and prefix + '/') + k
12111212
@@ -1218,14 +1219,17 @@
1218 values2[k] = {'value': v}1219 values2[k] = {'value': v}
12191220
1220 if kind == 'float':1221 if kind == 'float':
1221 field = proxy.fields_get([k], ctx2)1222 float_to_check.append(k)
1222 digit = field[k].get('digits')1223 if float_to_check:
1223 if digit: digit = digit[1]1224 fields = proxy.fields_get(float_to_check, ctx2)
1225 for k in float_to_check:
1226 digit = fields[k].get('digits')
1227 if digit:
1228 digit = digit[1]
1224 values2[k]['digit'] = digit or 21229 values2[k]['digit'] = digit or 2
1225
1226 # custom fields - decimal_precision computation1230 # custom fields - decimal_precision computation
1227 computation = field[k].get('computation')1231 values2[k]['computation'] = fields[k].get('computation')
1228 values2[k]['computation'] = computation1232 values2[k]['truncate'] = fields[k].get('truncate', False)
12291233
1230 values = TinyForm(**values2).from_python().make_plain()1234 values = TinyForm(**values2).from_python().make_plain()
12311235
12321236
=== modified file 'addons/openerp/utils/utils.py'
--- addons/openerp/utils/utils.py 2017-01-17 11:01:12 +0000
+++ addons/openerp/utils/utils.py 2017-02-22 08:04:53 +0000
@@ -367,7 +367,7 @@
367367
368 v = _VALIDATORS.get(kind, openobject.validators.DefaultValidator)()368 v = _VALIDATORS.get(kind, openobject.validators.DefaultValidator)()
369 if kind == "float" and attrs.get("digit"):369 if kind == "float" and attrs.get("digit"):
370 v = validators.Float(digit=attrs.get("digit"), computation=attrs.get("computation"))370 v = validators.Float(digit=attrs.get("digit"), computation=attrs.get("computation"), truncate=attrs.get("truncate"))
371 v.not_empty = (required or False) and True371 v.not_empty = (required or False) and True
372372
373 try:373 try:
374374
=== modified file 'addons/openerp/validators.py'
--- addons/openerp/validators.py 2017-01-02 14:59:00 +0000
+++ addons/openerp/validators.py 2017-02-22 08:04:53 +0000
@@ -65,9 +65,10 @@
65 if_empty = False65 if_empty = False
66 digit = 266 digit = 2
67 computation = False67 computation = False
68 truncate = False
6869
69 def _from_python(self, value, state):70 def _from_python(self, value, state):
70 return format.format_decimal(float(value) or 0.0, self.digit, computation=self.computation)71 return format.format_decimal(float(value) or 0.0, self.digit, computation=self.computation, truncate=self.truncate)
7172
72 def _to_python(self, value, state):73 def _to_python(self, value, state):
73 try:74 try:
7475
=== modified file 'addons/openerp/widgets/form/_form.py'
--- addons/openerp/widgets/form/_form.py 2017-01-02 14:59:00 +0000
+++ addons/openerp/widgets/form/_form.py 2017-02-22 08:04:53 +0000
@@ -455,13 +455,13 @@
455 digits = eval(digits)455 digits = eval(digits)
456456
457 integer, digit = digits457 integer, digit = digits
458 458 truncate = attrs.get('truncate', False)
459 # custom fields - decimal_precision computation459 # custom fields - decimal_precision computation
460 computation = attrs.get('computation', False)460 computation = attrs.get('computation', False)
461 if isinstance(computation, basestring):461 if isinstance(computation, basestring):
462 computation = eval(computation)462 computation = eval(computation)
463463
464 self.validator = validators.Float(digit=digit, computation=computation)464 self.validator = validators.Float(digit=digit, computation=computation, truncate=truncate)
465465
466# if not self.default:466# if not self.default:
467# self.default = 0.0467# self.default = 0.0
468468
=== modified file 'addons/openerp/widgets/listgrid.py'
--- addons/openerp/widgets/listgrid.py 2017-02-08 15:03:00 +0000
+++ addons/openerp/widgets/listgrid.py 2017-02-22 08:04:53 +0000
@@ -323,11 +323,12 @@
323323
324 # custom fields - decimal_precision computation324 # custom fields - decimal_precision computation
325 computation = attrs.get('computation', False)325 computation = attrs.get('computation', False)
326 truncate = attrs.get('truncate', False)
326 if isinstance(computation, basestring):327 if isinstance(computation, basestring):
327 computation = eval(computation)328 computation = eval(computation)
328329
329 integer, digit = digits330 integer, digit = digits
330 return format.format_decimal(sum or 0.0, digit, computation=computation)331 return format.format_decimal(sum or 0.0, digit, computation=computation, truncate=truncate)
331332
332 def do_real_sum(self, data, field):333 def do_real_sum(self, data, field):
333 sum = 0.0334 sum = 0.0
@@ -348,11 +349,12 @@
348349
349 # custom fields - decimal_precision computation350 # custom fields - decimal_precision computation
350 computation = attrs.get('computation', False)351 computation = attrs.get('computation', False)
352 truncate = attrs.get('truncate', False)
351 if isinstance(computation, basestring):353 if isinstance(computation, basestring):
352 computation = eval(computation)354 computation = eval(computation)
353355
354 integer, digit = digits356 integer, digit = digits
355 return format.format_decimal(sum or 0.0, digit, computation=computation)357 return format.format_decimal(sum or 0.0, digit, computation=computation, truncate=truncate)
356358
357359
358 def display(self, value=None, **params):360 def display(self, value=None, **params):
@@ -608,11 +610,12 @@
608610
609 # custom fields - decimal_precision computation611 # custom fields - decimal_precision computation
610 computation = self.attrs.get('computation', False)612 computation = self.attrs.get('computation', False)
613 truncate = self.attrs.get('truncate', False)
611 if isinstance(computation, basestring):614 if isinstance(computation, basestring):
612 computation = eval(computation)615 computation = eval(computation)
613616
614 integer, digit = digits617 integer, digit = digits
615 return format.format_decimal(self.value or 0.0, digit, computation=computation)618 return format.format_decimal(self.value or 0.0, digit, computation=computation, truncate=truncate)
616619
617 def get_sortable_text(self):620 def get_sortable_text(self):
618 return ustr(self.value or '0.0')621 return ustr(self.value or '0.0')
619622
=== modified file 'addons/openerp/widgets/listgroup.py'
--- addons/openerp/widgets/listgroup.py 2017-01-02 14:59:00 +0000
+++ addons/openerp/widgets/listgroup.py 2017-02-22 08:04:53 +0000
@@ -81,7 +81,8 @@
81 digits = (16,2)81 digits = (16,2)
82 # custom fields - decimal_precision computation82 # custom fields - decimal_precision computation
83 computation = False83 computation = False
84 84 truncate = False
85
85 if fields:86 if fields:
86 for key, val in fields.items():87 for key, val in fields.items():
87 if val.get('digits'):88 if val.get('digits'):
@@ -89,6 +90,8 @@
89 # custom fields - decimal_precision computation90 # custom fields - decimal_precision computation
90 if val.get('computation'):91 if val.get('computation'):
91 computation = val['computation']92 computation = val['computation']
93 if val.get('truncate'):
94 truncate = val['truncate']
92 if isinstance(digits, basestring):95 if isinstance(digits, basestring):
93 digits = eval(digits)96 digits = eval(digits)
94 integer, digit = digits97 integer, digit = digits
@@ -101,14 +104,14 @@
101 if grp_records[0].has_key(sum_key):104 if grp_records[0].has_key(sum_key):
102 value = sum(map(lambda x: x[sum_key], grp_records))105 value = sum(map(lambda x: x[sum_key], grp_records))
103 if isinstance(value, float):106 if isinstance(value, float):
104 total_fields[sum_key][1] = format.format_decimal(value or 0.0, digit, computation=computation)107 total_fields[sum_key][1] = format.format_decimal(value or 0.0, digit, computation=computation, truncate=truncate)
105 else:108 else:
106 total_fields[sum_key][1] = value109 total_fields[sum_key][1] = value
107 if grp_records:110 if grp_records:
108 for rec in grp_records:111 for rec in grp_records:
109 for key, val in rec.items():112 for key, val in rec.items():
110 if isinstance(val, float):113 if isinstance(val, float):
111 rec[key] = format.format_decimal(val or 0.0, digit, computation=computation)114 rec[key] = format.format_decimal(val or 0.0, digit, computation=computation, truncate=truncate)
112115
113 for grp_by in group_by:116 for grp_by in group_by:
114 if not rec.get(grp_by):117 if not rec.get(grp_by):
115118
=== modified file 'openobject/i18n/format.py'
--- openobject/i18n/format.py 2017-01-02 14:59:00 +0000
+++ openobject/i18n/format.py 2017-02-22 08:04:53 +0000
@@ -291,6 +291,7 @@
291 return fixed_domain291 return fixed_domain
292292
293def format_decimal(value, digits=2, **kwargs):293def format_decimal(value, digits=2, **kwargs):
294 truncate = kwargs.get('truncate', False)
294 locale = get_locale()295 locale = get_locale()
295 # fix issue where "%.2f"%a != '%s'%round(a, 2) exple a=51.345 depends on python version / win / linux296 # fix issue where "%.2f"%a != '%s'%round(a, 2) exple a=51.345 depends on python version / win / linux
296 value = round(value, digits)297 value = round(value, digits)
@@ -315,8 +316,13 @@
315 if len(decimals) < min_digits:316 if len(decimals) < min_digits:
316 decimals = decimals + '0'*(min_digits - len(decimals))317 decimals = decimals + '0'*(min_digits - len(decimals))
317318
319 if truncate:
320 decimals = decimals.rstrip('0')
321 if not decimals:
322 return val
323
318 result = val + unicode(numbers.get_decimal_symbol(locale) + decimals)324 result = val + unicode(numbers.get_decimal_symbol(locale) + decimals)
319 325
320 return result326 return result
321327
322def parse_decimal(value):328def parse_decimal(value):

Subscribers

People subscribed via source and target branches

to all changes: