← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~numerigraphe-team/ocb-addons/7.0-fill_inventory_zero_qty into lp:ocb-addons

 

Loïc Bellier - Numérigraphe has proposed merging lp:~numerigraphe-team/ocb-addons/7.0-fill_inventory_zero_qty into lp:ocb-addons.

Requested reviews:
  Lionel Sausin - Numérigraphe (lionel-sausin): co-author
  Laetitia Gangloff (Acsone) (laetitia-gangloff)
  OpenERP Community Backports (ocb)
Related bugs:
  Bug #1229646 in OpenERP Community Backports (Addons): "Wizard "Fill inventory" does not respect the UoM's precision at the end of the computation"
  https://bugs.launchpad.net/ocb-addons/+bug/1229646

For more details, see:
https://code.launchpad.net/~numerigraphe-team/ocb-addons/7.0-fill_inventory_zero_qty/+merge/223929

In v7.0, when a Physical inventory is filled with the wizard, the quantity of products is computed by summing all the stock moves, but it's not rounded to the correct precision.
This can lead to tiny differences when validating the inventory.

Our previous patch work with v6.0, but not with v7.0 because _compute_qty_obj function has been refactored.
This is the patch for v7.0.
-- 
https://code.launchpad.net/~numerigraphe-team/ocb-addons/7.0-fill_inventory_zero_qty/+merge/223929
Your team OpenERP Community Backports is requested to review the proposed merge of lp:~numerigraphe-team/ocb-addons/7.0-fill_inventory_zero_qty into lp:ocb-addons.
=== modified file 'stock/stock.py'
--- stock/stock.py	2014-06-18 14:06:14 +0000
+++ stock/stock.py	2014-07-02 08:53:30 +0000
@@ -2922,7 +2922,7 @@
         # to perform the correct inventory corrections we need analyze stock location by
         # location, never recursively, so we use a special context
         product_context = dict(context, compute_child=False)
-
+        uom_obj = self.pool['product.uom']
         location_obj = self.pool.get('stock.location')
         for inv in self.browse(cr, uid, ids, context=context):
             move_ids = []
@@ -2931,6 +2931,8 @@
                 product_context.update(uom=line.product_uom.id, to_date=inv.date, date=inv.date, prodlot_id=line.prod_lot_id.id)
                 amount = location_obj._product_get(cr, uid, line.location_id.id, [pid], product_context)[pid]
                 change = line.product_qty - amount
+                if abs(change) < uom_obj.browse(cr, uid, line.product_uom.id).rounding:
+                    continue
                 lot_id = line.prod_lot_id.id
                 if change:
                     location_id = line.product_id.property_stock_inventory.id

=== modified file 'stock/wizard/stock_fill_inventory.py'
--- stock/wizard/stock_fill_inventory.py	2014-06-20 14:27:46 +0000
+++ stock/wizard/stock_fill_inventory.py	2014-07-02 08:53:30 +0000
@@ -22,6 +22,7 @@
 from openerp.osv import fields, osv, orm
 from openerp.tools.translate import _
 from openerp.tools import mute_logger
+from product._common import rounding
 
 class stock_fill_inventory(osv.osv_memory):
     _name = "stock.fill.inventory"
@@ -116,20 +117,16 @@
                     lot_id = move.prodlot_id.id
                     prod_id = move.product_id.id
                     if move.location_dest_id.id != move.location_id.id:
-                        if move.location_dest_id.id == location:
-                            qty = uom_obj._compute_qty_obj(cr, uid, move.product_uom,move.product_qty, move.product_id.uom_id, context=local_context)
-                        else:
-                            qty = -uom_obj._compute_qty_obj(cr, uid, move.product_uom,move.product_qty, move.product_id.uom_id, context=local_context)
+                        qty = move.product_qty
+                        if move.product_uom.id != move.product_id.uom_id.id:
+                            qty = uom_obj._compute_qty_obj(cr, uid, move.product_uom, qty, move.product_id.uom_id, context=local_context)
+                        if move.location_dest_id.id != location:
+                            qty = -qty
 
 
                         if datas.get((prod_id, lot_id)):
                             qty += datas[(prod_id, lot_id)]['product_qty']
 
-                        # Floating point sum could introduce tiny rounding errors :
-                        #     Use the UoM API for the rounding (same UoM in & out).
-                        qty = uom_obj._compute_qty_obj(cr, uid,
-                                                       move.product_id.uom_id, qty,
-                                                       move.product_id.uom_id)
                         datas[(prod_id, lot_id)] = {'product_id': prod_id, 'location_id': location, 'product_qty': qty, 'product_uom': move.product_id.uom_id.id, 'prod_lot_id': lot_id}
 
             if datas:
@@ -141,6 +138,9 @@
 
         for stock_move in res.values():
             for stock_move_details in stock_move.values():
+                # remove product with qty < to product uom rounding (rouding error computation)
+                if abs(stock_move_details['product_qty']) < uom_obj.browse(cr, uid, stock_move_details['product_uom']).rounding:
+                    continue
                 stock_move_details.update({'inventory_id': context['active_ids'][0]})
                 domain = []
                 for field, value in stock_move_details.items():
@@ -155,6 +155,9 @@
                 line_ids = inventory_line_obj.search(cr, uid, domain, context=context)
 
                 if not line_ids:
+                    # Floating point sum could introduce some tiny rounding errors.
+                    line_uom = uom_obj.browse(cr, uid, [stock_move_details['product_uom']])[0]
+                    stock_move_details['product_qty'] = rounding(stock_move_details['product_qty'], line_uom.rounding)
                     inventory_line_obj.create(cr, uid, stock_move_details, context=context)
 
         return {'type': 'ir.actions.act_window_close'}


References