Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Won't write new value

By
Dr Obx
on 11/23/15, 9:29 AM 401 views

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 ?


0
Dr Obx
On 11/23/15, 9:40 AM

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 :)

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/23/15, 9:29 AM
Seen: 401 times
Last updated: 12/17/15, 8:49 AM