Fill inventory is incorrect

Bug #837123 reported by Eric Caudal - www.elico-corp.com
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
Low
OpenERP R&D Addons Team 2

Bug Description

Current fill_inventory method only takes into account incoming moves (location_dest_id=location) for a specific location which is not correct:
            move_ids = move_obj.search(cr, uid, [('location_dest_id','=',location),('state','=','done')], context=context)

moves in and out should be taken into account to reflect the physical stock of the location.

I propose the following changes that solves this issue on my side:

        for location in location_ids:
            datas = {}
            res[location] = {}
            move_ids = move_obj.search(cr, uid, ['|',('location_dest_id','=',location),('location_id','=',location),('state','=','done')], context=context)#EC taking into account incoming and outgoing shipment from/to the location

            for move in move_obj.browse(cr, uid, move_ids, context=context):
                lot_id = move.prodlot_id.id
                prod_id = move.product_id.id
                #EC increase the quantity as the goods are sent to the location
                if move.location_dest_id.id==location:
                    qty = move.product_qty
                #EC decrease the quantity as the goods are sent from the location
                if move.location_id.id==location:
                    qty = -move.product_qty
                #EC strange case where dest location would be identical to origin
                if move.location_id.id==location and move.location_dest_id.id==location:
                    qty = 0

                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}

            if datas:
                flag = True
                res[location] = datas

        if not flag:
            raise osv.except_osv(_('Warning !'), _('No product in this location.'))

        for stock_move in res.values():
            for stock_move_details in stock_move.values():
                if stock_move_details.get('product_qty') != 0:#EC We dont want to pollute the physical inventory will all O values
                    stock_move_details.update({'inventory_id': context['active_ids'][0]})
                    domain = []

                    if fill_inventory.set_stock_zero:
                        stock_move_details.update({'product_qty': 0})

                    for field, value in stock_move_details.items():
                        domain.append((field, '=', value))

                    line_ids = inventory_line_obj.search(cr, uid, domain, context=context)

                    if not line_ids:
                        inventory_line_obj.create(cr, uid, stock_move_details, context=context)

        return {'type': 'ir.actions.act_window_close'}

Related branches

Revision history for this message
Jignesh Rathod(OpenERP) (jir-openerp) wrote :
Revision history for this message
Jignesh Rathod(OpenERP) (jir-openerp) wrote :

Hello ,

I am confirming this issue.
For more reference I have attached a related video.

Changed in openobject-addons:
assignee: nobody → OpenERP R&D Addons Team 2 (openerp-dev-addons2)
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
Rucha (Open ERP) (rpa-openerp) wrote :

Thanks for reporting Eric,
Its fixed in lp:~openerp-dev/openobject-addons/trunk-bug-797772-rpa for the fix of lp:797772,
it will be available in trunk soon.

Changed in openobject-addons:
status: Confirmed → Fix Committed
Revision history for this message
qdp (OpenERP) (qdp) wrote :

fix released in revision 5339 of trunk addons.

Thanks for the contribution

Changed in openobject-addons:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.