This question has been flagged

Guys,

If possible please help me to with this script which should calculate lowest, highest and average from stock_quant.product_qty in specified location(which in this case is 'production'):

It check every record within the period selected(st_date to en_date) and create a list of product_qty's. As a next i would like to split it to months/weeks and calculate quants for each month/week including lowest, highest and average not just count all products_qty in production.

.....

for obj in self.browse(cr, uid, ids):

cr.execute(""" select product_id,sum(qty) from stock_quant where in_date ::date>=to_date('%s', 'YYYY-MM-DD') and

in_date ::date<= to_date('%s', 'YYYY-MM-DD') and location_id =%s group by product_id;""" %(obj.st_date,obj.en_date, obj.location_id.id))

tot_qty = cr.fetchall()

if tot_qty:

for rec in tot_qty:

a = a + 1

total += rec[1]

lsrv = min(str,rec[1])# lowest is not a problem it apparently works :)

hsrv = max(str,rec[1)]# this one, because it's a list it won't - don't know how to - gives me an error 'type error ...'

asrv = (total / a)

mwosres = (rec[1]/7 * 52)

res.append((0, 0, {'product_id': rec[0],'product_qty':rec[1],'lsr':lsrv,'hsr':hsrv,'asr':asrv,'mwos':mwosres}))

print '= R E S U L T S =========================================================='

print 'RESULT:', res

print 'MWoS: ', mwosres

print 'LSR: ', lsrv

print 'HSR: ', hsrv

print 'ASR: ', asrv

print 'TOTAL: ', total

ab = obj.write({'product':res})

print 'TorF: ',ab

print '========================================================================'

......

I'll add one more column (weeks) to display weeks within selected period of time.


Avatar
Discard