Skip to Content
Menu
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
Related Posts Replies Views Activity
0
Mar 16
1944
1
Dec 22
5280
2
Jun 20
38709
1
Oct 15
4911
3
May 24
13840