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 on 2017-02-21

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
1=== modified file 'addons/openerp/controllers/form.py'
2--- addons/openerp/controllers/form.py 2017-02-06 11:21:15 +0000
3+++ addons/openerp/controllers/form.py 2017-02-22 08:04:53 +0000
4@@ -84,8 +84,8 @@
5 data = data or {}
6
7 proxy = rpc.RPCProxy(model)
8- fields = proxy.fields_get([], rpc.session.context)
9-
10+ if data:
11+ fields = proxy.fields_get(data.keys(), rpc.session.context)
12 search_domain = domain[:]
13 search_data = {}
14
15@@ -1206,6 +1206,7 @@
16 # apply validators (transform values from python)
17 values = result['value']
18 values2 = {}
19+ float_to_check = []
20 for k, v in values.items():
21 key = ((prefix or '') and prefix + '/') + k
22
23@@ -1218,14 +1219,17 @@
24 values2[k] = {'value': v}
25
26 if kind == 'float':
27- field = proxy.fields_get([k], ctx2)
28- digit = field[k].get('digits')
29- if digit: digit = digit[1]
30+ float_to_check.append(k)
31+ if float_to_check:
32+ fields = proxy.fields_get(float_to_check, ctx2)
33+ for k in float_to_check:
34+ digit = fields[k].get('digits')
35+ if digit:
36+ digit = digit[1]
37 values2[k]['digit'] = digit or 2
38-
39 # custom fields - decimal_precision computation
40- computation = field[k].get('computation')
41- values2[k]['computation'] = computation
42+ values2[k]['computation'] = fields[k].get('computation')
43+ values2[k]['truncate'] = fields[k].get('truncate', False)
44
45 values = TinyForm(**values2).from_python().make_plain()
46
47
48=== modified file 'addons/openerp/utils/utils.py'
49--- addons/openerp/utils/utils.py 2017-01-17 11:01:12 +0000
50+++ addons/openerp/utils/utils.py 2017-02-22 08:04:53 +0000
51@@ -367,7 +367,7 @@
52
53 v = _VALIDATORS.get(kind, openobject.validators.DefaultValidator)()
54 if kind == "float" and attrs.get("digit"):
55- v = validators.Float(digit=attrs.get("digit"), computation=attrs.get("computation"))
56+ v = validators.Float(digit=attrs.get("digit"), computation=attrs.get("computation"), truncate=attrs.get("truncate"))
57 v.not_empty = (required or False) and True
58
59 try:
60
61=== modified file 'addons/openerp/validators.py'
62--- addons/openerp/validators.py 2017-01-02 14:59:00 +0000
63+++ addons/openerp/validators.py 2017-02-22 08:04:53 +0000
64@@ -65,9 +65,10 @@
65 if_empty = False
66 digit = 2
67 computation = False
68+ truncate = False
69
70 def _from_python(self, value, state):
71- return format.format_decimal(float(value) or 0.0, self.digit, computation=self.computation)
72+ return format.format_decimal(float(value) or 0.0, self.digit, computation=self.computation, truncate=self.truncate)
73
74 def _to_python(self, value, state):
75 try:
76
77=== modified file 'addons/openerp/widgets/form/_form.py'
78--- addons/openerp/widgets/form/_form.py 2017-01-02 14:59:00 +0000
79+++ addons/openerp/widgets/form/_form.py 2017-02-22 08:04:53 +0000
80@@ -455,13 +455,13 @@
81 digits = eval(digits)
82
83 integer, digit = digits
84-
85+ truncate = attrs.get('truncate', False)
86 # custom fields - decimal_precision computation
87 computation = attrs.get('computation', False)
88 if isinstance(computation, basestring):
89 computation = eval(computation)
90
91- self.validator = validators.Float(digit=digit, computation=computation)
92+ self.validator = validators.Float(digit=digit, computation=computation, truncate=truncate)
93
94 # if not self.default:
95 # self.default = 0.0
96
97=== modified file 'addons/openerp/widgets/listgrid.py'
98--- addons/openerp/widgets/listgrid.py 2017-02-08 15:03:00 +0000
99+++ addons/openerp/widgets/listgrid.py 2017-02-22 08:04:53 +0000
100@@ -323,11 +323,12 @@
101
102 # custom fields - decimal_precision computation
103 computation = attrs.get('computation', False)
104+ truncate = attrs.get('truncate', False)
105 if isinstance(computation, basestring):
106 computation = eval(computation)
107
108 integer, digit = digits
109- return format.format_decimal(sum or 0.0, digit, computation=computation)
110+ return format.format_decimal(sum or 0.0, digit, computation=computation, truncate=truncate)
111
112 def do_real_sum(self, data, field):
113 sum = 0.0
114@@ -348,11 +349,12 @@
115
116 # custom fields - decimal_precision computation
117 computation = attrs.get('computation', False)
118+ truncate = attrs.get('truncate', False)
119 if isinstance(computation, basestring):
120 computation = eval(computation)
121
122 integer, digit = digits
123- return format.format_decimal(sum or 0.0, digit, computation=computation)
124+ return format.format_decimal(sum or 0.0, digit, computation=computation, truncate=truncate)
125
126
127 def display(self, value=None, **params):
128@@ -608,11 +610,12 @@
129
130 # custom fields - decimal_precision computation
131 computation = self.attrs.get('computation', False)
132+ truncate = self.attrs.get('truncate', False)
133 if isinstance(computation, basestring):
134 computation = eval(computation)
135
136 integer, digit = digits
137- return format.format_decimal(self.value or 0.0, digit, computation=computation)
138+ return format.format_decimal(self.value or 0.0, digit, computation=computation, truncate=truncate)
139
140 def get_sortable_text(self):
141 return ustr(self.value or '0.0')
142
143=== modified file 'addons/openerp/widgets/listgroup.py'
144--- addons/openerp/widgets/listgroup.py 2017-01-02 14:59:00 +0000
145+++ addons/openerp/widgets/listgroup.py 2017-02-22 08:04:53 +0000
146@@ -81,7 +81,8 @@
147 digits = (16,2)
148 # custom fields - decimal_precision computation
149 computation = False
150-
151+ truncate = False
152+
153 if fields:
154 for key, val in fields.items():
155 if val.get('digits'):
156@@ -89,6 +90,8 @@
157 # custom fields - decimal_precision computation
158 if val.get('computation'):
159 computation = val['computation']
160+ if val.get('truncate'):
161+ truncate = val['truncate']
162 if isinstance(digits, basestring):
163 digits = eval(digits)
164 integer, digit = digits
165@@ -101,14 +104,14 @@
166 if grp_records[0].has_key(sum_key):
167 value = sum(map(lambda x: x[sum_key], grp_records))
168 if isinstance(value, float):
169- total_fields[sum_key][1] = format.format_decimal(value or 0.0, digit, computation=computation)
170+ total_fields[sum_key][1] = format.format_decimal(value or 0.0, digit, computation=computation, truncate=truncate)
171 else:
172 total_fields[sum_key][1] = value
173 if grp_records:
174 for rec in grp_records:
175 for key, val in rec.items():
176 if isinstance(val, float):
177- rec[key] = format.format_decimal(val or 0.0, digit, computation=computation)
178+ rec[key] = format.format_decimal(val or 0.0, digit, computation=computation, truncate=truncate)
179
180 for grp_by in group_by:
181 if not rec.get(grp_by):
182
183=== modified file 'openobject/i18n/format.py'
184--- openobject/i18n/format.py 2017-01-02 14:59:00 +0000
185+++ openobject/i18n/format.py 2017-02-22 08:04:53 +0000
186@@ -291,6 +291,7 @@
187 return fixed_domain
188
189 def format_decimal(value, digits=2, **kwargs):
190+ truncate = kwargs.get('truncate', False)
191 locale = get_locale()
192 # fix issue where "%.2f"%a != '%s'%round(a, 2) exple a=51.345 depends on python version / win / linux
193 value = round(value, digits)
194@@ -315,8 +316,13 @@
195 if len(decimals) < min_digits:
196 decimals = decimals + '0'*(min_digits - len(decimals))
197
198+ if truncate:
199+ decimals = decimals.rstrip('0')
200+ if not decimals:
201+ return val
202+
203 result = val + unicode(numbers.get_decimal_symbol(locale) + decimals)
204-
205+
206 return result
207
208 def parse_decimal(value):

Subscribers

People subscribed via source and target branches

to all changes: