Rucha (Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-bug-797772-rpa into 
lp:openobject-addons.

Requested reviews:
  qdp (OpenERP) (qdp)
Related bugs:
  Bug #797772 in OpenERP Addons: "fill inventory wizard computes wrong 
quantities"
  https://bugs.launchpad.net/openobject-addons/+bug/797772
  Bug #837123 in OpenERP Addons: "Fill inventory is incorrect"
  https://bugs.launchpad.net/openobject-addons/+bug/837123

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-797772-rpa/+merge/74046

Fixed computation of qty in fill inventory wizard according to proper lot and 
considering outgoing moves
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-797772-rpa/+merge/74046
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-797772-rpa.
=== modified file 'stock/wizard/stock_fill_inventory.py'
--- stock/wizard/stock_fill_inventory.py	2011-05-02 18:46:43 +0000
+++ stock/wizard/stock_fill_inventory.py	2011-09-05 06:57:29 +0000
@@ -91,17 +91,25 @@
         for location in location_ids:
             datas = {}
             res[location] = {}
-            move_ids = move_obj.search(cr, uid, [('location_dest_id','=',location),('state','=','done')], context=context)
-
-            for move in move_obj.browse(cr, uid, move_ids, context=context):
-                lot_id = move.prodlot_id.id
-                prod_id = move.product_id.id
-                qty = move.product_qty
-
-                if datas.get((prod_id, lot_id)):
-                    qty += datas[(prod_id, lot_id)]['product_qty']
-
-                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}
+            # Find product qty in location
+            cr.execute("""select product_id, sum(qty) as product_qty, prod_lot_id, product_uom, location_id
+                            from 
+                            (select m.product_id, sum(m.product_qty / u.factor) as qty, m.prodlot_id as prod_lot_id, product_uom,
+                                min(m.location_dest_id) as location_id
+                                from stock_move m
+                                join product_uom u on (m.product_uom=u.id)
+                                where m.location_dest_id=%s 
+                                group by m.product_id, m.prodlot_id, product_uom
+                            union
+                            select m.product_id, -sum(m.product_qty / u.factor) as qty, m.prodlot_id as prod_lot_id, product_uom,
+                                min(m.location_id) as location_id
+                                from stock_move m
+                                join product_uom u on (m.product_uom=u.id)
+                                where m.location_id=%s 
+                                group by m.product_id, m.prodlot_id, product_uom)
+                            as mytest
+                            group by product_id, prod_lot_id, product_uom, location_id""", (location, location, ))
+            datas = cr.dictfetchall()
 
             if datas:
                 flag = True
@@ -111,7 +119,9 @@
             raise osv.except_osv(_('Warning !'), _('No product in this location.'))
 
         for stock_move in res.values():
-            for stock_move_details in stock_move.values():
+            for stock_move_details in stock_move:
+                if stock_move_details['product_qty'] <= 0:
+                    continue
                 stock_move_details.update({'inventory_id': context['active_ids'][0]})
                 domain = []
 

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to