Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
3533 Visualizações

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
Cancelar
Autor Melhor resposta

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
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
2
fev. 25
7032
1
out. 24
1763
3
jun. 24
9472
1
ago. 19
1593
0
mai. 19
2580