Am Mittwoch, 8. April 2015 16:20:25 UTC+2 schrieb raimonesteve:
>
> 2015-04-08 15:27 GMT+02:00 TPH <[email protected] <javascript:>>: 
> > Hello, 
> > 
> > I try to get the stock and the locations of a product but can't get it 
> work. 
> > 
> > 
> > 
> > 
> > #!/usr/bin/env python 
> > #-*- coding: utf-8 -*- 
> > 
> > 
> > import datetime 
> > from proteus import config, Model, Wizard 
> > from con_data import * 
> > config = config.set_xmlrpc(url) 
> > 
> > 
> > Product = Model.get('product.product') 
> > Location = Model.get('stock.location') 
> > Inventory = Model.get('stock.inventory') 
> > 
> > locations = Location.find([('type', '=', 'storage'), ('parent.name', 
> '=' 
> > ,'Main Storage')]) 
> > locations = [l.id for l in locations] 
> > 
> > config.context['language'] = 'de_DE' 
> > config._context['locations'] = locations 
> > #config.context['stock_date_end'] = datetime.date(2015, 4, 7) 
>
> if not add date in context, will be calculate a forecast qty 
>
> > def check_stock(product_code): 
> >     (product,) = Product.find([('code', '=', product_code)]) 
> >     print "product code:", product.code 
> >     print "product name:", product.name 
> >     print "product quantity:", product.quantity 
> >     bylocation  = Wizard('product.by_location', [product]) 
>
> It's not necessary call wizard if you like know quantity. You could 
> call directly quantity field from product (or template) 
>
> http://hg.tryton.org/modules/stock/file/06a6bee29336/product.py#l74 
>

Reading the stock of a product was not the problem and worked in my script 
above. I am searching for an solution to get stock and the warehouse 
location of that stock. Sometimes product also is on multiple locations.

>
> >     bylocation.execute("by_location") 
> > 
> > check_stock("PRODUCTCODE") 
> > 
> > 
> > 
> > 
> >     assert state in self.states 
> > AssertionError 
> > 
> > 
> > 
> > I have never used state and have no clue how to use it. Would be nice to 
> get 
> > some help. 
> > I have the correct stock but cant find the storage name. 
> > 
> > Thanks 
>

Reply via email to