Merge lp:~openerp-dev/openobject-addons/trunk-bug-1025649-api into lp:openobject-addons

Proposed by Arnaud Pineux (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-bug-1025649-api
Merge into: lp:openobject-addons
Diff against target: 740 lines (+83/-59)
23 files modified
account/account.py (+10/-9)
account/account_analytic_line.py (+2/-1)
account/account_invoice.py (+2/-1)
account_analytic_analysis/account_analytic_analysis.py (+16/-15)
analytic_user_function/analytic_user_function.py (+3/-2)
base_calendar/base_calendar.py (+3/-2)
hr_attendance/report/attendance_by_month.py (+2/-1)
hr_attendance/report/timesheet.py (+2/-1)
hr_timesheet_invoice/hr_timesheet_invoice.py (+2/-1)
hr_timesheet_invoice/report/account_analytic_profit.py (+2/-1)
l10n_be_coda/l10n_be_coda.py (+2/-1)
l10n_ch/wizard/bvr_import.py (+5/-4)
point_of_sale/point_of_sale.py (+3/-2)
project/project.py (+3/-2)
project_long_term/project_long_term.py (+2/-1)
resource/faces/task.py (+3/-1)
resource/resource.py (+2/-1)
sale/sale.py (+2/-1)
sale_margin/sale_margin.py (+3/-2)
survey/report/survey_analysis_report.py (+6/-5)
survey/report/survey_browse_response.py (+3/-2)
survey/report/survey_form.py (+3/-2)
survey/survey.py (+2/-1)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-bug-1025649-api
Reviewer Review Type Date Requested Status
qdp (OpenERP) Needs Fixing
Review via email: mp+137822@code.launchpad.net

Description of the change

Method round(value, precision) changed into float_round.

To post a comment you must log in.
Revision history for this message
qdp (OpenERP) (qdp) wrote :

Hi,

even if this is better than before, i must admit that seeing this merge prop annoy me a little because you're changing a lot of lines of code and leaving issues in them.

I'm talking about the common hardcoded precision issue. For example in
line 121 + res[id][f] = float_round(res.get(id, {}).get(f, 0.0), dp) + float_round(res2.get(id, 0.0), 2)

this last precision of '2' is hardcoded and probably wrongly prevails on a defined decimal precision in the system. I didn't check the code but i guess it should be replaced by 'dp', to sum numbers with the same rounding parameter.

SO it would be a very nice improvement to check on each of your line diff to see if you're using a decimal precision from the system instead of an arbitrary hardcoded value. To know which decimal precision you should take, you can check the decimal precision of the field you're computing.

And if you really want to do amazing job, you can move the definitions of existing decimal precisions into the decimal_precision module and comment in few words what's the most common use for each of them ;-)

Thank you

review: Needs Fixing
Revision history for this message
Paulius Sladkevičius @ hbee (komsas) wrote :

Hey guys

I'm thinking that this bug is important and we need to have a good rounding method (specially for accounting part). Any further plants to finish this fix?

Unmerged revisions

8190. By Arnaud Pineux (OpenERP)

[IMP] Round method changed

8189. By Arnaud Pineux (OpenERP)

[IMP] Round method changed

8188. By Arnaud Pineux (OpenERP)

[MERGE] with trunk

8187. By Arnaud Pineux (OpenERP)

[IMP] round -> float_round

8186. By Arnaud Pineux (OpenERP)

[FIX] python round(val, precision) replace by float_round(val, precision)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account.py'
2--- account/account.py 2012-12-04 10:31:46 +0000
3+++ account/account.py 2012-12-04 12:19:24 +0000
4@@ -36,7 +36,8 @@
5 _logger = logging.getLogger(__name__)
6
7 def check_cycle(self, cr, uid, ids, context=None):
8- """ climbs the ``self._table.parent_id`` chains for 100 levels or
9+ """
10+ climbs the ``self._table.parent_id`` chains for 100 levels or
11 until it can't find any more parent(s)
12
13 Returns true if it runs out of parents (no cycle), false if
14@@ -78,11 +79,11 @@
15 for line in pt.line_ids:
16 prec = obj_precision.precision_get(cr, uid, 'Account')
17 if line.value == 'fixed':
18- amt = round(line.value_amount, prec)
19+ amt = float_round(line.value_amount, prec)
20 elif line.value == 'procent':
21- amt = round(value * line.value_amount, prec)
22+ amt = float_round(value * line.value_amount, prec)
23 elif line.value == 'balance':
24- amt = round(amount, prec)
25+ amt = float_round(amount, prec)
26 if amt:
27 next_date = (datetime.strptime(date_ref, '%Y-%m-%d') + relativedelta(days=line.days))
28 if line.days2 < 0:
29@@ -1727,7 +1728,7 @@
30 for rec in record.child_ids:
31 amount += _rec_get(rec) * rec.sign
32 return amount
33- res2[record.id] = round(_rec_get(record), obj_precision.precision_get(cr, uid, 'Account'))
34+ res2[record.id] = float_round(_rec_get(record), obj_precision.precision_get(cr, uid, 'Account'))
35 return res2
36
37 def _sum_year(self, cr, uid, ids, name, args, context=None):
38@@ -2128,9 +2129,9 @@
39 total = 0.0
40 for r in res:
41 if r.get('balance',False):
42- r['amount'] = round(r.get('balance', 0.0) * quantity, precision) - total
43+ r['amount'] = float_round(r.get('balance', 0.0) * quantity, precision) - total
44 else:
45- r['amount'] = round(r.get('amount', 0.0) * quantity, precision)
46+ r['amount'] = float_round(r.get('amount', 0.0) * quantity, precision)
47 total += r['amount']
48 return res
49
50@@ -2224,9 +2225,9 @@
51 total = 0.0
52 for r in res:
53 if r.get('balance',False):
54- r['amount'] = round(r['balance'] * quantity, precision) - total
55+ r['amount'] = float_round(r['balance'] * quantity, precision) - total
56 else:
57- r['amount'] = round(r['amount'] * quantity, precision)
58+ r['amount'] = float_round(r['amount'] * quantity, precision)
59 total += r['amount']
60 return res
61
62
63=== modified file 'account/account_analytic_line.py'
64--- account/account_analytic_line.py 2012-11-29 22:26:45 +0000
65+++ account/account_analytic_line.py 2012-12-04 12:19:24 +0000
66@@ -22,6 +22,7 @@
67 from osv import fields
68 from osv import osv
69 from tools.translate import _
70+from tools.float_utils import float_round
71
72 class account_analytic_line(osv.osv):
73 _inherit = 'account.analytic.line'
74@@ -121,7 +122,7 @@
75 amount_unit = prod.price_get(pricetype.field, context=ctx)[prod.id]
76 prec = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')
77 amount = amount_unit * quantity or 0.0
78- result = round(amount, prec)
79+ result = float_round(amount, prec)
80 if not flag:
81 result *= -1
82 return {'value': {
83
84=== modified file 'account/account_invoice.py'
85--- account/account_invoice.py 2012-12-04 10:31:46 +0000
86+++ account/account_invoice.py 2012-12-04 12:19:24 +0000
87@@ -27,6 +27,7 @@
88 import pooler
89 from osv import fields, osv, orm
90 from tools.translate import _
91+from tools.float_utils import float_round
92
93 class account_invoice(osv.osv):
94 def _amount_all(self, cr, uid, ids, name, args, context=None):
95@@ -1306,7 +1307,7 @@
96 total += (l.debit or 0.0) - (l.credit or 0.0)
97
98 inv_id, name = self.name_get(cr, uid, [invoice.id], context=context)[0]
99- if (not round(total,self.pool.get('decimal.precision').precision_get(cr, uid, 'Account'))) or writeoff_acc_id:
100+ if (not float_round(total,self.pool.get('decimal.precision').precision_get(cr, uid, 'Account'))) or writeoff_acc_id:
101 self.pool.get('account.move.line').reconcile(cr, uid, line_ids, 'manual', writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context)
102 else:
103 code = invoice.currency_id.symbol
104
105=== modified file 'account_analytic_analysis/account_analytic_analysis.py'
106--- account_analytic_analysis/account_analytic_analysis.py 2012-11-29 22:26:45 +0000
107+++ account_analytic_analysis/account_analytic_analysis.py 2012-12-04 12:19:24 +0000
108@@ -24,6 +24,7 @@
109 import tools.sql
110 from tools.translate import _
111 from decimal_precision import decimal_precision as dp
112+from tools.float_utils import float_round
113
114
115 class account_analytic_account(osv.osv):
116@@ -95,7 +96,7 @@
117
118 # sum both result on account_id
119 for id in ids:
120- res[id][f] = round(res.get(id, {}).get(f, 0.0), dp) + round(res2.get(id, 0.0), 2)
121+ res[id][f] = float_round(res.get(id, {}).get(f, 0.0), dp) + float_round(res2.get(id, 0.0), 2)
122 elif f == 'last_invoice_date':
123 for id in ids:
124 res[id][f] = False
125@@ -139,9 +140,9 @@
126 for account_id, sua in cr.fetchall():
127 if account_id not in res:
128 res[account_id] = {}
129- res[account_id][f] = round(sua, dp)
130+ res[account_id][f] = float_round(sua, dp)
131 for id in ids:
132- res[id][f] = round(res[id][f], dp)
133+ res[id][f] = float_round(res[id][f], dp)
134 elif f == 'hours_quantity':
135 for id in ids:
136 res[id][f] = 0.0
137@@ -157,9 +158,9 @@
138 for account_id, hq in ff:
139 if account_id not in res:
140 res[account_id] = {}
141- res[account_id][f] = round(hq, dp)
142+ res[account_id][f] = float_round(hq, dp)
143 for id in ids:
144- res[id][f] = round(res[id][f], dp)
145+ res[id][f] = float_round(res[id][f], dp)
146 elif f == 'ca_theorical':
147 # TODO Take care of pricelist and purchase !
148 for id in ids:
149@@ -188,7 +189,7 @@
150 AND account_analytic_journal.type IN ('purchase', 'general')
151 GROUP BY account_analytic_line.account_id""",(parent_ids,))
152 for account_id, sum in cr.fetchall():
153- res[account_id][f] = round(sum, dp)
154+ res[account_id][f] = float_round(sum, dp)
155 return res
156
157 def _ca_invoiced_calc(self, cr, uid, ids, name, arg, context=None):
158@@ -209,7 +210,7 @@
159 AND account_analytic_journal.type = 'sale' \
160 GROUP BY account_analytic_line.account_id", (child_ids,))
161 for account_id, sum in cr.fetchall():
162- res[account_id] = round(sum,2)
163+ res[account_id] = float_round(sum,2)
164 res_final = res
165 return res_final
166
167@@ -230,7 +231,7 @@
168 AND amount<0 \
169 GROUP BY account_analytic_line.account_id""",(child_ids,))
170 for account_id, sum in cr.fetchall():
171- res[account_id] = round(sum,2)
172+ res[account_id] = float_round(sum,2)
173 res_final = res
174 return res_final
175
176@@ -242,7 +243,7 @@
177 else:
178 res[account.id] = 0.0
179 for id in ids:
180- res[id] = round(res.get(id, 0.0),2)
181+ res[id] = float_round(res.get(id, 0.0),2)
182 return res
183
184 def _remaining_hours_to_invoice_calc(self, cr, uid, ids, name, arg, context=None):
185@@ -258,7 +259,7 @@
186 if res[account.id] < 0:
187 res[account.id] = 0.0
188 for id in ids:
189- res[id] = round(res.get(id, 0.0),2)
190+ res[id] = float_round(res.get(id, 0.0),2)
191 return res
192
193 def _revenue_per_hour_calc(self, cr, uid, ids, name, arg, context=None):
194@@ -269,7 +270,7 @@
195 else:
196 res[account.id] = account.ca_invoiced / account.hours_qtt_invoiced
197 for id in ids:
198- res[id] = round(res.get(id, 0.0),2)
199+ res[id] = float_round(res.get(id, 0.0),2)
200 return res
201
202 def _real_margin_rate_calc(self, cr, uid, ids, name, arg, context=None):
203@@ -282,7 +283,7 @@
204 else:
205 res[account.id] = 0.0
206 for id in ids:
207- res[id] = round(res.get(id, 0.0),2)
208+ res[id] = float_round(res.get(id, 0.0),2)
209 return res
210
211 def _fix_price_to_invoice_calc(self, cr, uid, ids, name, arg, context=None):
212@@ -323,7 +324,7 @@
213 for account in self.browse(cr, uid, ids, context=context):
214 res[account.id] = account.ca_invoiced + account.total_cost
215 for id in ids:
216- res[id] = round(res.get(id, 0.0),2)
217+ res[id] = float_round(res.get(id, 0.0),2)
218 return res
219
220 def _theorical_margin_calc(self, cr, uid, ids, name, arg, context=None):
221@@ -331,7 +332,7 @@
222 for account in self.browse(cr, uid, ids, context=context):
223 res[account.id] = account.ca_theorical + account.total_cost
224 for id in ids:
225- res[id] = round(res.get(id, 0.0),2)
226+ res[id] = float_round(res.get(id, 0.0),2)
227 return res
228
229 def _is_overdue_quantity(self, cr, uid, ids, fieldnames, args, context=None):
230@@ -508,7 +509,7 @@
231 for sum_id, unit_amount in cr.fetchall():
232 res[sum_id] = unit_amount
233 for id in ids:
234- res[id] = round(res.get(id, 0.0), 2)
235+ res[id] = float_round(res.get(id, 0.0), 2)
236 return res
237
238 _columns = {
239
240=== modified file 'analytic_user_function/analytic_user_function.py'
241--- analytic_user_function/analytic_user_function.py 2012-11-29 22:26:45 +0000
242+++ analytic_user_function/analytic_user_function.py 2012-12-04 12:19:24 +0000
243@@ -22,6 +22,7 @@
244 from osv import fields,osv
245 from tools.translate import _
246 import decimal_precision as dp
247+from tools.float_utils import float_round
248
249 class analytic_user_funct_grid(osv.osv):
250 _name="analytic.user.funct.grid"
251@@ -112,7 +113,7 @@
252 amount_unit = self.on_change_unit_amount(cr, uid, ids,
253 r.product_id.id, unit_amount, False, r.product_id.uom_id.id)['value']['amount']
254 amount = unit_amount * amount_unit
255- res ['value']['amount']= - round(amount, 2)
256+ res ['value']['amount']= - float_round(amount, 2)
257 res ['value']['general_account_id']= a
258 return res
259
260@@ -142,7 +143,7 @@
261 r.product_id.id, unit_amount, False, r.product_id.uom_id.id)['value']['amount']
262
263 amount = unit_amount * amount_unit
264- res ['value']['amount']= - round(amount, 2)
265+ res ['value']['amount']= - float_round(amount, 2)
266 res ['value']['general_account_id']= a
267 return res
268
269
270=== modified file 'base_calendar/base_calendar.py'
271--- base_calendar/base_calendar.py 2012-11-29 22:26:45 +0000
272+++ base_calendar/base_calendar.py 2012-12-04 12:19:24 +0000
273@@ -30,6 +30,7 @@
274 import re
275 import time
276 import tools
277+from tools.float_utils import float_round
278
279 months = {
280 1: "January", 2: "February", 3: "March", 4: "April", \
281@@ -932,7 +933,7 @@
282 end = datetime.strptime(end_date, "%Y-%m-%d %H:%M:%S")
283 diff = end - start
284 duration = float(diff.days)* 24 + (float(diff.seconds) / 3600)
285- value['duration'] = round(duration, 2)
286+ value['duration'] = float_round(duration, 2)
287 elif not end_date:
288 end = start + timedelta(hours=duration)
289 value['date_deadline'] = end.strftime("%Y-%m-%d %H:%M:%S")
290@@ -943,7 +944,7 @@
291 end = datetime.strptime(end_date, "%Y-%m-%d %H:%M:%S")
292 diff = end - start
293 duration = float(diff.days)* 24 + (float(diff.seconds) / 3600)
294- value['duration'] = round(duration, 2)
295+ value['duration'] = float_round(duration, 2)
296
297 return {'value': value}
298
299
300=== modified file 'hr_attendance/report/attendance_by_month.py'
301--- hr_attendance/report/attendance_by_month.py 2012-11-29 22:26:45 +0000
302+++ hr_attendance/report/attendance_by_month.py 2012-12-04 12:19:24 +0000
303@@ -32,13 +32,14 @@
304 from tools import ustr
305 from tools.translate import _
306 from tools import to_xml
307+from tools.float_utils import float_round
308
309 one_day = relativedelta(days=1)
310 month2name = [0, 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
311
312 def hour2str(h):
313 hours = int(h)
314- minutes = int(round((h - hours) * 60, 0))
315+ minutes = int(float_round((h - hours) * 60, 0))
316 return '%02dh%02d' % (hours, minutes)
317
318 def lengthmonth(year, month):
319
320=== modified file 'hr_attendance/report/timesheet.py'
321--- hr_attendance/report/timesheet.py 2012-11-29 22:26:45 +0000
322+++ hr_attendance/report/timesheet.py 2012-12-04 12:19:24 +0000
323@@ -30,12 +30,13 @@
324 from report import report_sxw
325 from tools.translate import _
326 import tools
327+from tools.float_utils import float_round
328
329 one_week = relativedelta(days=7)
330 num2day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
331
332 def to_hour(h):
333- return int(h), int(round((h - int(h)) * 60, 0))
334+ return int(h), int(float_round((h - int(h)) * 60, 0))
335
336 class report_custom(report_rml):
337
338
339=== modified file 'hr_timesheet_invoice/hr_timesheet_invoice.py'
340--- hr_timesheet_invoice/hr_timesheet_invoice.py 2012-11-29 22:26:45 +0000
341+++ hr_timesheet_invoice/hr_timesheet_invoice.py 2012-12-04 12:19:24 +0000
342@@ -23,6 +23,7 @@
343
344 from osv import fields, osv
345 from tools.translate import _
346+from tools.float_utils import float_round
347
348 class hr_timesheet_invoice_factor(osv.osv):
349 _name = "hr_timesheet_invoice.factor"
350@@ -59,7 +60,7 @@
351 res.setdefault(account.id, 0.0)
352 res[account.id] += invoice.amount_untaxed
353 for id in ids:
354- res[id] = round(res.get(id, 0.0),2)
355+ res[id] = float_round(res.get(id, 0.0),2)
356
357 return res
358
359
360=== modified file 'hr_timesheet_invoice/report/account_analytic_profit.py'
361--- hr_timesheet_invoice/report/account_analytic_profit.py 2012-11-29 22:26:45 +0000
362+++ hr_timesheet_invoice/report/account_analytic_profit.py 2012-12-04 12:19:24 +0000
363@@ -21,6 +21,7 @@
364
365 from report import report_sxw
366 import pooler
367+from tools.float_utils import float_round
368
369 class account_analytic_profit(report_sxw.rml_parse):
370 def __init__(self, cr, uid, name, context):
371@@ -84,7 +85,7 @@
372 price=0.0
373 if id not in res:
374 res[id]={'name': name, 'amount': 0, 'cost':0, 'unit_amount':0,'amount_th':0}
375- xxx = round(price * line.unit_amount * (1-(discount or 0.0)), 2)
376+ xxx = float_round(price * line.unit_amount * (1-(discount or 0.0)), 2)
377 res[id]['amount_th']+=xxx
378 if line.invoice_id:
379 self.cr.execute('select id from account_analytic_line where invoice_id=%s', (line.invoice_id.id,))
380
381=== modified file 'l10n_be_coda/l10n_be_coda.py'
382--- l10n_be_coda/l10n_be_coda.py 2012-11-29 22:26:45 +0000
383+++ l10n_be_coda/l10n_be_coda.py 2012-12-04 12:19:24 +0000
384@@ -23,6 +23,7 @@
385 from osv import osv, fields
386 import decimal_precision as dp
387 from tools.translate import _
388+from tools.float_utils import float_round
389
390 class coda_bank_account(osv.osv):
391 _name= 'coda.bank.account'
392@@ -235,7 +236,7 @@
393 for line in statement.line_ids:
394 res[statement.id] += line.amount
395 for r in res:
396- res[r] = round(res[r], 2)
397+ res[r] = float_round(res[r], 2)
398 return res
399
400 def _get_period(self, cr, uid, context=None):
401
402=== modified file 'l10n_ch/wizard/bvr_import.py'
403--- l10n_ch/wizard/bvr_import.py 2012-11-29 22:26:45 +0000
404+++ l10n_ch/wizard/bvr_import.py 2012-12-04 12:19:24 +0000
405@@ -26,6 +26,7 @@
406 from osv import osv, fields
407 from tools import mod10r
408 import pooler
409+from tools.float_utils import float_round
410
411 def _reconstruct_invoice_ref(cursor, user, reference, context=None):
412 ###
413@@ -102,8 +103,8 @@
414 amount *= -1
415 cost *= -1
416
417- if round(amount - total_amount, 2) >= 0.01 \
418- or round(cost - total_cost, 2) >= 0.01:
419+ if float_round(amount - total_amount, 2) >= 0.01 \
420+ or float_round(cost - total_cost, 2) >= 0.01:
421 raise osv.except_osv(_('Error!'),
422 _('Total record different from the computed.'))
423 if int(line[51:63]) != len(records):
424@@ -162,12 +163,12 @@
425 partner_id = line.partner_id.id
426 move_id = line.move_id.id
427 if record['amount'] >= 0:
428- if round(record['amount'] - line.debit, 2) < 0.01:
429+ if float_round(record['amount'] - line.debit, 2) < 0.01:
430 # line2reconcile = line.id
431 account_id = line.account_id.id
432 break
433 else:
434- if round(line.credit + record['amount'], 2) < 0.01:
435+ if float_round(line.credit + record['amount'], 2) < 0.01:
436 # line2reconcile = line.id
437 account_id = line.account_id.id
438 break
439
440=== modified file 'point_of_sale/point_of_sale.py'
441--- point_of_sale/point_of_sale.py 2012-11-29 22:26:45 +0000
442+++ point_of_sale/point_of_sale.py 2012-12-04 12:19:24 +0000
443@@ -35,6 +35,7 @@
444 from tools.translate import _
445 from decimal import Decimal
446 import decimal_precision as dp
447+from tools.float_utils import float_round
448
449 _logger = logging.getLogger(__name__)
450
451@@ -988,11 +989,11 @@
452 computed_taxes = account_tax_obj.compute_all(cr, uid, taxes, line.price_unit * (100.0-line.discount) / 100.0, line.qty)['taxes']
453
454 for tax in computed_taxes:
455- tax_amount += round(tax['amount'], 2)
456+ tax_amount += float_round(tax['amount'], 2)
457 group_key = (tax['tax_code_id'], tax['base_code_id'], tax['account_collected_id'], tax['id'])
458
459 group_tax.setdefault(group_key, 0)
460- group_tax[group_key] += round(tax['amount'], 2)
461+ group_tax[group_key] += float_round(tax['amount'], 2)
462
463 amount = line.price_subtotal
464
465
466=== modified file 'project/project.py'
467--- project/project.py 2012-11-30 17:11:30 +0000
468+++ project/project.py 2012-12-04 12:19:24 +0000
469@@ -29,6 +29,7 @@
470 from openerp.addons.resource.faces import task as Task
471 from tools.translate import _
472 from openerp import SUPERUSER_ID
473+from tools.float_utils import float_round
474
475 _TASK_STATE = [('draft', 'New'),('open', 'In Progress'),('pending', 'Pending'), ('done', 'Done'), ('cancelled', 'Cancelled')]
476
477@@ -167,7 +168,7 @@
478 # compute progress rates
479 for id in ids:
480 if res[id]['total_hours']:
481- res[id]['progress_rate'] = round(100.0 * res[id]['effective_hours'] / res[id]['total_hours'], 2)
482+ res[id]['progress_rate'] = float_round(100.0 * res[id]['effective_hours'] / res[id]['total_hours'], 2)
483 else:
484 res[id]['progress_rate'] = 0.0
485 return res
486@@ -673,7 +674,7 @@
487 res[task.id]['delay_hours'] = res[task.id]['total_hours'] - task.planned_hours
488 res[task.id]['progress'] = 0.0
489 if (task.remaining_hours + hours.get(task.id, 0.0)):
490- res[task.id]['progress'] = round(min(100.0 * hours.get(task.id, 0.0) / res[task.id]['total_hours'], 99.99),2)
491+ res[task.id]['progress'] = float_round(min(100.0 * hours.get(task.id, 0.0) / res[task.id]['total_hours'], 99.99),2)
492 if task.state in ('done','cancelled'):
493 res[task.id]['progress'] = 100.0
494 return res
495
496=== modified file 'project_long_term/project_long_term.py'
497--- project_long_term/project_long_term.py 2012-11-29 22:26:45 +0000
498+++ project_long_term/project_long_term.py 2012-12-04 12:19:24 +0000
499@@ -23,6 +23,7 @@
500 from tools.translate import _
501 from osv import fields, osv
502 from openerp.addons.resource.faces import task as Task
503+from tools.float_utils import float_round
504
505 class project_phase(osv.osv):
506 _name = "project.phase"
507@@ -96,7 +97,7 @@
508 if not tot:
509 res[phase.id] = 0.0
510 else:
511- res[phase.id] = round(100.0 * done / tot, 2)
512+ res[phase.id] = float_round(100.0 * done / tot, 2)
513 return res
514
515 _columns = {
516
517=== modified file 'resource/faces/task.py'
518--- resource/faces/task.py 2012-11-29 22:26:45 +0000
519+++ resource/faces/task.py 2012-12-04 12:19:24 +0000
520@@ -43,6 +43,8 @@
521 import weakref
522 import opcode
523 import new
524+from tools.float_utils import float_round
525+
526 try:
527 set
528 except NameError:
529@@ -2060,7 +2062,7 @@
530 self._performed_resource_length))
531
532 costs /= (60.0 * self.root.calendar.working_hours_per_day)
533- return round(costs, 2)
534+ return float_round(costs, 2)
535
536 costs.attrib_method = True
537 costs.__call_completion__ = 'costs("|")'
538
539=== modified file 'resource/resource.py'
540--- resource/resource.py 2012-11-29 22:26:45 +0000
541+++ resource/resource.py 2012-12-04 12:19:24 +0000
542@@ -27,6 +27,7 @@
543
544 from itertools import groupby
545 from operator import itemgetter
546+from tools.float_utils import float_round
547
548
549 class resource_calendar(osv.osv):
550@@ -278,7 +279,7 @@
551 split_list = str(time_string).split('.')
552 hour_part = split_list[0]
553 mins_part = split_list[1]
554- round_mins = int(round(float(mins_part) * 60,-2))
555+ round_mins = int(float_round(float(mins_part) * 60,-2))
556 converted_string = hour_part + ':' + str(round_mins)[0:2]
557 return converted_string
558
559
560=== modified file 'sale/sale.py'
561--- sale/sale.py 2012-11-30 17:11:30 +0000
562+++ sale/sale.py 2012-12-04 12:19:24 +0000
563@@ -28,6 +28,7 @@
564 from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP, float_compare
565 import decimal_precision as dp
566 import netsvc
567+from tools.float_utils import float_round
568
569 class sale_shop(osv.osv):
570 _name = "sale.shop"
571@@ -795,7 +796,7 @@
572 uos_id = self._get_line_uom(cr, uid, line, context=context)
573 pu = 0.0
574 if uosqty:
575- pu = round(line.price_unit * line.product_uom_qty / uosqty,
576+ pu = float_round(line.price_unit * line.product_uom_qty / uosqty,
577 self.pool.get('decimal.precision').precision_get(cr, uid, 'Product Price'))
578 fpos = line.order_id.fiscal_position or False
579 account_id = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, account_id)
580
581=== modified file 'sale_margin/sale_margin.py'
582--- sale_margin/sale_margin.py 2012-11-29 22:26:45 +0000
583+++ sale_margin/sale_margin.py 2012-12-04 12:19:24 +0000
584@@ -19,6 +19,7 @@
585 ##############################################################################
586
587 from osv import fields, osv
588+from tools.float_utils import float_round
589
590 class sale_order_line(osv.osv):
591 _inherit = "sale.order.line"
592@@ -45,9 +46,9 @@
593 res[line.id] = 0
594 if line.product_id:
595 if line.purchase_price:
596- res[line.id] = round((line.price_unit*line.product_uos_qty*(100.0-line.discount)/100.0) -(line.purchase_price*line.product_uos_qty), 2)
597+ res[line.id] = float_round((line.price_unit*line.product_uos_qty*(100.0-line.discount)/100.0) -(line.purchase_price*line.product_uos_qty), 2)
598 else:
599- res[line.id] = round((line.price_unit*line.product_uos_qty*(100.0-line.discount)/100.0) -(line.product_id.standard_price*line.product_uos_qty), 2)
600+ res[line.id] = float_round((line.price_unit*line.product_uos_qty*(100.0-line.discount)/100.0) -(line.product_id.standard_price*line.product_uos_qty), 2)
601 return res
602
603 _columns = {
604
605=== modified file 'survey/report/survey_analysis_report.py'
606--- survey/report/survey_analysis_report.py 2011-01-14 00:11:01 +0000
607+++ survey/report/survey_analysis_report.py 2012-12-04 12:19:24 +0000
608@@ -26,6 +26,7 @@
609 import tools
610 import time
611 from report import report_sxw
612+from tools.float_utils import float_round
613
614 class survey_analysis(report_rml):
615 def create(self, cr, uid, ids, datas, context):
616@@ -196,7 +197,7 @@
617 if cal['column_id'] == matrix_ans[mat_col][0]:
618 cal_count = cal['count']
619 if tot_res:
620- percantage = round(float(cal_count)*100 / tot_res,2)
621+ percantage = float_round(float(cal_count)*100 / tot_res,2)
622 if percantage:
623 rml += """<td color="#FFF435"><para style="answer_bold">""" + tools.ustr(percantage) +"% (" + tools.ustr(cal_count) + """)</para></td>"""
624 else:
625@@ -315,7 +316,7 @@
626
627 if tot_res and res_count:
628 rating_weight_sum += int(col_weight[1]) * tot_res
629- tot_per = round((float(tot_res) * 100) / int(res_count), 2)
630+ tot_per = float_round((float(tot_res) * 100) / int(res_count), 2)
631 else:
632 tot_per = 0.0
633 if tot_res:
634@@ -325,7 +326,7 @@
635
636 percantage = 0.00
637 if res_count:
638- percantage = round((float(rating_weight_sum)/res_count), 2)
639+ percantage = float_round((float(rating_weight_sum)/res_count), 2)
640 rml += """<td><para style="answer_right">""" + tools.ustr(percantage) + """</para></td>
641 <td><para style="answer_right">""" + tools.ustr(res_count) + """</para></td></tr>"""
642 rml += """</blockTable>"""
643@@ -366,7 +367,7 @@
644 percantage = 0.00
645
646 if calc and response:
647- percantage = round((float(calc)* 100) / response,2)
648+ percantage = float_round((float(calc)* 100) / response,2)
649 if calc:
650 rml += """<td><para style="answer_bold">""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)</para></td>"""
651 else:
652@@ -396,7 +397,7 @@
653 per = 0.00
654
655 if len(tot_res):
656- per = round((float(total) / len(tot_res)),2)
657+ per = float_round((float(total) / len(tot_res)),2)
658 rml+="""<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
659 <td> <para style="Standard"> </para></td>
660 <td> <para style="answer">""" + tools.ustr(per) +"""</para></td>
661
662=== modified file 'survey/report/survey_browse_response.py'
663--- survey/report/survey_browse_response.py 2011-01-14 00:11:01 +0000
664+++ survey/report/survey_browse_response.py 2012-12-04 12:19:24 +0000
665@@ -25,6 +25,7 @@
666 from tools import to_xml
667 import tools
668 import time
669+from tools.float_utils import float_round
670 from report import report_sxw
671
672 class survey_browse_response(report_rml):
673@@ -318,7 +319,7 @@
674 divide_list = divide_list(answer_choice,_display_ans_in_rows)
675 for lst in divide_list:
676 if que.type == 'multiple_choice_multiple_ans':
677- if len(lst) <> 0 and len(lst) <> int(round(float(len(answer_choice)) / _display_ans_in_rows, 0)):
678+ if len(lst) <> 0 and len(lst) <> int(float_round(float(len(answer_choice)) / _display_ans_in_rows, 0)):
679 lst.append('')
680 if not lst:
681 del divide_list[divide_list.index(lst):]
682@@ -445,7 +446,7 @@
683 tmp = cols_widhts[i]
684 sum += col
685 i += 1
686- cols_widhts.append(round(tmp, 2))
687+ cols_widhts.append(float_round(tmp, 2))
688 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
689 colWidths = colWidths + 'cm'
690 matrix_ans = [(0, ''),]
691
692=== modified file 'survey/report/survey_form.py'
693--- survey/report/survey_form.py 2011-01-14 00:11:01 +0000
694+++ survey/report/survey_form.py 2012-12-04 12:19:24 +0000
695@@ -24,6 +24,7 @@
696 from report.interface import report_rml
697 from tools import to_xml
698 import tools
699+from tools.float_utils import float_round
700
701 class survey_form(report_rml):
702 def create(self, cr, uid, ids, datas, context):
703@@ -204,7 +205,7 @@
704 divide_list = divide_list(answer,_display_ans_in_rows)
705 for lst in divide_list:
706 if que.type == 'multiple_choice_multiple_ans':
707- if len(lst)<>0 and len(lst)<>int(round(float(len(answer))/_display_ans_in_rows,0)):
708+ if len(lst)<>0 and len(lst)<>int(float_round(float(len(answer))/_display_ans_in_rows,0)):
709 lst.append('')
710 if not lst:
711 del divide_list[divide_list.index(lst):]
712@@ -263,7 +264,7 @@
713 tmp = cols_widhts[i]
714 sum += col
715 i += 1
716- cols_widhts.append(round(tmp,2))
717+ cols_widhts.append(float_round(tmp,2))
718 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
719 colWidths = colWidths+'cm'
720 matrix_ans = ['',]
721
722=== modified file 'survey/survey.py'
723--- survey/survey.py 2012-11-29 22:26:45 +0000
724+++ survey/survey.py 2012-12-04 12:19:24 +0000
725@@ -30,6 +30,7 @@
726 from dateutil.relativedelta import relativedelta
727 import copy
728 import os
729+from tools.float_utils import float_round
730
731 class survey_type(osv.osv):
732 _name = 'survey.type'
733@@ -620,7 +621,7 @@
734 avg = 0.0
735 val[rec.id] = {
736 'response': res[1],
737- 'average': round(avg, 2),
738+ 'average': float_round(avg, 2),
739 }
740 return val
741

Subscribers

People subscribed via source and target branches

to all changes: