This question has been flagged
1 Reply
6893 Views

Hi

how to add quantity of  stock for all locations in  any product to view tree 

Thanks

 

Avatar
Discard
Best Answer

Oussama, when you say 'add' is to include it in the tree view or to increase the quantity?  If you need to include the quantity field (there are 2 quantity fields) you just need to include it in the product's tree view.  The fields name are qty_available and virtual_available.  The virtual_available includes all potential (not completed) movements while qty_available includes only completed movements.  If you didn't specify anything else you get the total (in - out) movement into all locations that are attached to Warehouses' Stock location including their children.  In principle this is the stock that the company holds.  Any location that are considered company's stock should be within the Warehouse's Stock location structure.

 

If you want to increase the quantity, you need to do it through export-import of stock.move.  Each product and location pairs are increased using one stock.move record.

Avatar
Discard
Author

Thanks john, My question is how to include quantity of product for all location (for example i have location "A" with qty_available 30 and lacation "B" with qty_available 50 , I want to display in the view tree of model product.product the qty_available for location "A" and qty_available for location "B" for each product. thanks a lot

Oussama, what I can think on top of my head is to create a function field which returns the data that you want. Unfortunately I don't think it can be made into a tabulized layout (cross-tab query if you understand it). A very simple implementation is a function field of type text that will return the name of locations with qty_available and the qty_available. I would imagine that this would need quite a bit of processing power and time, though.

Thanks John
I created this function but it not working
def get_stock_locations(self, cr, uid, ids, field_names=None, arg=None, context=None):
        res={}
        if not ids: return result
        location_obj = self.pool.get('stock.location')
        count = location_obj.search(cr, uid, [('usage', '=', 'internal'),('company_id', '=', 'sousse1')], context=context)
        for id in count:
            for record in location_obj.browse(cr, uid, id, context=context):
                res[record.a] = {'sousse1' : 0.0}
                res[record.a]['sousse1'] =  record.stock_real
        return res
'sousse1': fields.function(get_stock_locations, type='float', string='Sousse1'),
Thanks a lots

2014-11-03 12:11 GMT+01:00 John Doe <niecw@mail.odoo.com>:

Oussama, what I can think on top of my head is to create a function field which returns the data that you want. Unfortunately I don't think it can be made into a tabulized layout (cross-tab query if you understand it). A very simple implementation is a function field of type text that will return the name of locations with qty_available and the qty_available. I would imagine that this would need quite a bit of processing power and time, though.

--
John Doe
Sent by Odoo Inc. using Odoo about Forum Post False

You need to elaborate what do you mean by not working. The code that you have crafted will show the monetary value (not quantity) of the stock in the last internal location in company_id that is equal to 'sousse1'. Now, do you have company which ID is 'sousse1' (I doubt it because company_ids are integer)? Do you have any location which belong to that company? Do you have any product in that location?

Hi Jhon
Yes i have a company name is 'sousse1' (company_id is a field many2one) and i have a location in this company .
Thanks

2014-11-04 17:00 GMT+01:00 John Doe <niecw@mail.odoo.com>:

You need to elaborate what do you mean by not working. The code that you have crafted will show the monetary value (not quantity) of the stock in the last internal location in company_id that is equal to 'sousse1'. Now, do you have company which ID is 'sousse1' (I doubt it because company_ids are integer)? Do you have any location which belong to that company? Do you have any product in that location?

--
John Doe
Sent by Odoo Inc. using Odoo about Forum Post False

It's a bit unusual to search by a specific company. In a single-company situation, it does not matter if you filter by company or not. In a multi-company situation, filtering by a specific company instead of the company the user is currently in may lead into cross-company data inconsistency (a transaction that is made with data from various companies). It is more usual to filter by the company the user is currently logged into. To do so, you can use the following domain: [('usage', '=', 'internal'),('company_id', 'child_of', user.company_id.id)]. But, again your code will show the monetary value (not quantity) of the stock in the last internal location in the company that the user is logged into. If you want to show the total of the monetary value in all locations, you need to aggregate record.stock_real. So use res[record.a] += record.stock_real. Put the res[record.a] = {'sousse1' : 0.0} outside the for loop but assign a 0.0 instead. If you want to show the quantity per location, as I've mentioned before you need to text field instead of float. Then you can construct a string with the location's name and value. If you want to show the quantity instead of monetary value, use product.product's qty_available. You need to browse the product several times with different context. Read the get_product_available method in stock/product.py to understand the working of qty_available. (get_product_available is the method called to calculate qty_available).

Hi Jhon

In my situation i have  a multi company and i want to display only the quantity stock of company "sousse1"



Thanks


2014-11-05 1:46 GMT+01:00 John Doe <niecw@mail.odoo.com>:

It's a bit unusual to search by a specific company. In a single-company situation, it does not matter if you filter by company or not. In a multi-company situation, filtering by a specific company instead of the company the user is currently in may lead into cross-company data inconsistency (a transaction that is made with data from various companies). It is more usual to filter by the company the user is currently logged into. To do so, you can use the following domain: [('usage', '=', 'internal'),('company_id', 'child_of', user.company_id.id)]. But, again your code will show the monetary value (not quantity) of the stock in the last internal location in the company that the user is logged into. If you want to show the total of the monetary value in all locations, you need to aggregate record.stock_real. So use res[record.a] += record.stock_real. Put the res[record.a] = {'sousse1' : 0.0} outside the for loop but assign a 0.0 instead. If you want to show the quantity per location, as I've mentioned before you need to text field instead of float. Then you can construct a string with the location's name and value. If you want to show the quantity instead of monetary value, use product.product's qty_available. You need to browse the product several times with different context. Read the get_product_available method in stock/product.py to understand the working of qty_available. (get_product_available is the method called to calculate qty_available).

--
John Doe
Sent by Odoo Inc. using Odoo about Forum Post False

Then you can try to use ['company_id.name', '=', 'sousse1'] instead. There are 2 catches. Catch No. 1, it will search by Company's name, so if the Company's name changed, the filter will fail. It is better to use XML ID, however the implementation will be quite different. Catch No. 2, if the user logs into a company that does not have access to 'sousse1', then the view may not be displayed at all due to permission error.

First in my situation the company can not changed the name because it is a static setting  ,second i want to display the quantity of stock only for admin user .
Thanks a lots.

2014-11-07 7:18 GMT+01:00 John Doe <niecw@mail.odoo.com>:

Then you can try to use ['company_id.name', '=', 'sousse1'] instead. There are 2 catches. Catch No. 1, it will search by Company's name, so if the Company's name changed, the filter will fail. It is better to use XML ID, however the implementation will be quite different. Catch No. 2, if the user logs into a company that does not have access to 'sousse1', then the view may not be displayed at all due to permission error.

--
John Doe
Sent by Odoo Inc. using Odoo about Forum Post False

Well those would be good restrictions to have. If you want to display the quantity only to admin, you can create a group (with proper XMLID) and make that field visible only to that group. And make sure that only admin belongs to that group. Note that although admin may have access to all company, at any point in time the admin user need to log in to a company. If the company admin user logs into does not have access to sousse1 company, the user still may get an error.

Hi Jhon
I don't have a problem with the permission of user, my question is how to display the quantity of  stock in  company "sousse1"  for  the tree view of the product,
So i use a simple code to get the quantity from the model stock.location.but it not worked.


class product_product(osv.osv):
    _inherit = 'product.product'

def get_stock_location(self, cr, uid, ids, name, args, context=None):
        result = {}
        if not ids: return result       
        location_obj = self.pool.get('stock.location')
        count = location_obj.search(cr, uid, [('usage', '=', 'internal'),('company_id.name','=','sousse1')], context=context)   
        result={'stock_real':0}
        for record in location_obj.browse(cr,uid,count):   
            result[record.id]['stock_real']= record.stock_real    
        return result

_columns={'sousse1' : fields.function(get_stock_location, type='float', method=True, string='sousse1')}
Thanks.

2014-11-07 11:38 GMT+01:00 John Doe <niecw@mail.odoo.com>:

Well those would be good restrictions to have. If you want to display the quantity only to admin, you can create a group (with proper XMLID) and make that field visible only to that group. And make sure that only admin belongs to that group. Note that although admin may have access to all company, at any point in time the admin user need to log in to a company. If the company admin user logs into does not have access to sousse1 company, the user still may get an error.

--
John Doe
Sent by Odoo Inc. using Odoo about Forum Post False

Sorry Oussama, if you cannot elaborate further than "it not worked", I'm afraid I can't help you further.

Thank you very mush Jhon for your help.

2014-11-08 3:54 GMT+01:00 John Doe <niecw@mail.odoo.com>:

Sorry Oussama, if you cannot elaborate further than "it not worked", I'm afraid I can't help you further.

--
John Doe
Sent by Odoo Inc. using Odoo about Forum Post False