Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to get product quantity in particular stock location ?

By
Zahin
on 11/8/13, 7:22 AM 6,387 views

By the code,

How may I get product quantity in particular stock location ?

I have two different warehouse & internal stock location for each warehouse, Now I want to get product quantity from particular stock location. How ???

right code with example.

0
tim diamond
On 11/11/13, 5:04 PM

Below I've written a function that could be helpful for you:

def get_quantity_at_location(self,cr,uid,lid,p):
    ls = ['stock_real','stock_virtual','stock_real_value','stock_virtual_value']
    move_avail = self.pool.get('stock.location')._product_value(cr,uid,[lid],ls,0,{'product_id':p})
    return move_avail[lid]['stock_real']

Basically, you are using the function _product_value() from the 'stock.location' class, and taking the 'stock_real' of the return statement.

Hope this helps!

-Tim

Thanks it also good solution, I will test it.

Zahin
on 11/12/13, 1:42 AM

Tested, Working Perfectly.

Zahin
on 11/13/13, 6:13 AM
2

Anil R. Kesariya

--Anil R. Kesariya--
4321
| 6 5 8
Gandhinagar, India
--Anil R. Kesariya--
ERP Consultant

Key Skill
-
Technical & Functional Expert
Anil R. Kesariya
On 11/12/13, 8:17 AM

Hello Zahin,

This method will return the quantity on hand on the location which is passed on method for passed product as argument on method.

def quantity_by_loc(self, product_id, location_id, context)

     #if you can't access context from method as argument than you can define here.
     product_obj = self.pool.get('product.product')
     qty = 0.0
     if context is None:
         context={}
     context.update({
        'states': ['done'],
        'what': ('in', 'out'),
        'location':location_id,
    })

    avail_product_details = product_obj.get_product_available(cr, uid, product_id, context=context)
    if avail_product_defails.values():
        qty = avail_product_defails.values()[0]
    return qty

I hope this will helps you.

Best Regards, Anil (SerpentCS)

Hello SerpentCS, your this code is buggy, its seems issue in your code. Please correct here.

Zahin
on 9/2/15, 9:39 AM
0
Prajul P T
On 11/12/13, 3:46 AM

There is a function in product.product called get_product_available. You can get the stock value in location by passing the location id in context. So you can modify your code as:

def product_qty_by_location(self, cr, uid, product_id, warehouse_stock_location, context=None):
    if context is None:
        context = {}
    product_pool = self.pool.get('product.product')
    context.update({'states': ('done',), 'what': ('in', 'out'), 'location': warehouse_stock_location})
    result = product_pool.get_product_available(cr, uid, [product_id], context=context)
    qty = result.get(product_id, 0.00)
    return qty

You can also get the stock level of product based on warehouse by passing warehouse_id insted of location_id as:

context.update({'states': ('done',), 'what': ('in', 'out'), 'warehouse': <warehouse_id>})

context is frozendict, hence cannot be modified. I think it has become more complex in odoo 8

OdooTec, Hesham ELMAHDY
on 5/22/15, 6:22 PM
0

Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
896
| 5 3 7
Gîza, Egypt
--Tarek Mohamed Ibrahim--

I am an old VFP developer on ERP

I have moved to 2p since Nov-2014 and started developing with Python on Odoo.

https://www.linkedin.com/profile/public-profile-settings?trk=prof-edit-edit-public_profile

tibrahim@2p.com.sa

Tarek Mohamed Ibrahim
On 5/13/15, 2:37 AM


Hi

I think one can also use the select statement

select sum(product_qty) from report_stock_inventory where product_id = p1 and location_id = w1 and state = 'done'

where p1 is the product id , w1 is the location id, this gives you the actual stock

if you needed the unallocated stock only you can drop the "state='done'" from the where clause

0
Zahin
On 11/12/13, 1:38 AM

I also get one alternate solution.

    def product_qty_by_location(self, cr, uid, product_id, warehouse_stock_location, context=None):
        sql = """select ((select sum(product_qty) from stock_move where product_id = %s and state in ('done') and location_dest_id = %s group by product_id) - (select sum(product_qty) from stock_move where product_id = %s and state in ('done') and location_id = %s group by product_id) ) as total;""" % (product_id, warehouse_stock_location, product_id, warehouse_stock_location)
        cr.execute(sql)
        return cr.fetchall()[0][0]

This gives me exact qty on hand by location. It fulfill my requirement.

0

How would one use these functions in the following context:

    def _get_raw_qty(self, cr, uid, ids, field_name, args, context=None):
        
        res = {}
        lid = 13
        
        for record in self.browse(cr, uid, ids,context=context):
        
            pid = record.product_id
            lid = 13


            qty = self.product_qty_by_location(cr, uid, pid, lid) # I need to get the qty in a specific location per record.
            
            res[record.id] = 3.0
        return res

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/8/13, 7:22 AM
Seen: 6387 times
Last updated: 5/13/15, 2:37 AM