Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
3531 Visualizzazioni

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
Abbandona
Autore Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
feb 25
7032
1
ott 24
1763
3
giu 24
9472
1
ago 19
1593
0
mag 19
2580