Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
3538 Näkymät

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
Hylkää
Tekijä Paras vastaus

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
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
2
helmik. 25
7032
1
lokak. 24
1764
3
kesäk. 24
9473
1
elok. 19
1593
0
toukok. 19
2580