Merge lp:~dieck/openobject-addons/openobject-addons-6.0-872242 into lp:openobject-addons/6.0

Proposed by Marco Dieckhoff
Status: Needs review
Proposed branch: lp:~dieck/openobject-addons/openobject-addons-6.0-872242
Merge into: lp:openobject-addons/6.0
Diff against target: 55 lines (+17/-2)
1 file modified
stock/wizard/stock_partial_picking.py (+17/-2)
To merge this branch: bzr merge lp:~dieck/openobject-addons/openobject-addons-6.0-872242
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+78954@code.launchpad.net

Description of the change

[FIX] Picking validation has rounding errors with uom computation by adding a meaningful error message note

To post a comment you must log in.

Unmerged revisions

4867. By Bremskerl

[FIX] Picking validation has rounding errors with uom computation by adding a meaningful error message note

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'stock/wizard/stock_partial_picking.py'
2--- stock/wizard/stock_partial_picking.py 2011-10-03 14:13:57 +0000
3+++ stock/wizard/stock_partial_picking.py 2011-10-11 12:20:34 +0000
4@@ -24,6 +24,8 @@
5 from tools.translate import _
6 import time
7 import decimal_precision as dp
8+from decimal import Decimal
9+
10
11 class stock_partial_picking(osv.osv_memory):
12 _name = "stock.partial.picking"
13@@ -133,6 +135,12 @@
14 })
15 return move_memory
16
17+ def _get_decimal_count(self, n):
18+ # convert string representation to decimal and do modulo 1
19+ d = Decimal(str(n)) % 1
20+ # return length of string representation (0.xyz) minus 2 (0.)
21+ return len(str(d)) - 2
22+
23 def do_partial(self, cr, uid, ids, context=None):
24 """ Makes partial moves and pickings done.
25 @param self: The object pointer.
26@@ -165,20 +173,27 @@
27 calc_qty = uom_obj._compute_qty(cr, uid, move.product_uom.id, \
28 move.quantity, move.move_id.product_uom.id)
29
30+ # look for problems that may arise from UoM rounding precision
31+ # compare decimals of calc_qty and move.move_id.product_qty
32+ uom_rounding_note = ""
33+ if (self._get_decimal_count(calc_qty) != self._get_decimal_count(move.quantity)):
34+ uom_rounding_note = "\n" + _("Please note that there may be rounding issues due to the Unit of Measurement rounding precision. (UoM computed quantity is %s %s)") % (calc_qty, move.move_id.product_uom.name)
35+
36+
37 #Adding a check whether any move line contains exceeding qty to original moveline
38 if calc_qty > move.move_id.product_qty:
39 precision = '%0.' + str(dp.get_precision('Product UoM')(cr)[1] or 0) + 'f'
40 raise osv.except_osv(_('Processing Error'),
41 _('Processing quantity %s %s for %s is larger than the available quantity %s %s !')\
42 % (precision % move.quantity, move.product_uom.name, move.product_id.name,\
43- precision % move.move_id.product_qty, move.move_id.product_uom.name))
44+ precision % move.move_id.product_qty, move.move_id.product_uom.name) + uom_rounding_note)
45
46 #Adding a check whether any move line contains qty less than zero
47 if calc_qty < 0:
48 precision = '%0.' + str(dp.get_precision('Product UoM')(cr)[1] or 0) + 'f'
49 raise osv.except_osv(_('Processing Error'), \
50 _('Can not process quantity %s for Product %s !') \
51- % (precision % move.quantity, move.product_id.name))
52+ % (precision % move.quantity, move.product_id.name) + uom_rounding_note)
53
54 partial_datas['move%s' % (move.move_id.id)] = {
55 'product_id': move.product_id.id,