2015-04-10 11:27 GMT+02:00 TPH <truckparts-hamb...@gmx.de>:

> Am Mittwoch, 8. April 2015 16:20:25 UTC+2 schrieb raimonesteve:
>
>> 2015-04-08 15:27 GMT+02:00 TPH <truckpart...@gmx.de>:
>> > 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.
>

I'm not sure if it works from proteus. I will explain you how to get it
"inside" Tryton and maybe you can do it the same with proteus:
get the quantity field of locations, supplying the product id by context:

with Transaction.context(products=[product.id]):
    locations = Location.search([('type', '=', 'storage')])
    for location in locations:
        print location.quantity  # quantity of product in this location


-- 
Guillem Barba
http://www.guillem.alcarrer.net

Reply via email to