Skip to Content
Menú
This question has been flagged
1 Respondre
3529 Vistes

Guys,

In my class if str(tot_qty[0][0]) == 'none'

self.write(cr, uid, ids, {'cntnt': 'occupied'})

Everything seems to work fine but .... it doesn't

do not write new value accordingly to the if statement. It print out on the screen correctly but not writing value into the field cntnt.

Why ?

<pre>

class stock_location(osv.osv):

    _inherit = 'stock.location'

    _columns = {

        'cntnt': fields.char('Empty')

}

def name_get(self, cr, uid, ids, context=None):

    res = super(stock_location, self).name_get(cr, uid, ids, context=context)

    res1=[]

    product_id = 0

    if context.has_key('prod_id'):

        product_id = context.get('prod_id', 0)

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

            cr.execute("""SELECT sum(qty) from stock_quant where location_id = %s""" % obj.id)

            tot_qty = cr.fetchall()

    if product_id:

            cr.execute("""SELECT sum(qty) from stock_quant where location_id = %s and product_id = %s""" % (obj.id, product_id))

            tot_qty = cr.fetchall()

    if str(tot_qty[0][0]) == 'None':

        self.write(cr, uid, ids, {'cntnt': 'empty'})

        print 'State:',str(tot_qty[0][0]) , ' Empty '

    if str(tot_qty[0][0]) != 'None':

        self.write(cr, uid, ids, {'cntnt': 'occupied'})

        print 'State:',str(tot_qty[0][0]) , ' Ocuppied '

res1.append((obj.id, obj.name + ' ('+str(tot_qty[0][0])+' in Stock)'))

return res1

</pre>

or how can I do it simpler ?


Avatar
Descartar
Autor Best Answer

Problem solved!

<pre>

if str(tot_qty[0][0]) == 'None':

obj.write({'cntnt': 'empty'})

print 'State:',str(tot_qty[0][0]) , ' Empty '

if str(tot_qty[0][0]) != 'None':

obj.write({'cntnt': 'occupied'})

print 'State:',str(tot_qty[0][0]) , ' Ocuppied '

</pre>

Thank you to ... myself :)

Avatar
Descartar
Related Posts Respostes Vistes Activitat
2
de febr. 25
7032
1
d’oct. 24
1763
3
de juny 24
9472
1
d’ag. 19
1593
0
de maig 19
2580