Skip to Content
Menu
This question has been flagged
3 Replies
6487 Views

_columns = {

    'pro_ta':fields.many2one('product.terrif.no','Tariff No.'),
    'die_id':fields.many2one('product.product','Product'),
    'metal_id':fields.many2one('metal.metal','Metal' )
     }



def on_chnage_product(self, cursor, user, field,die_id, context=None):
value = False

    if not die_id:
        return value
prod=die_id
    qur = ("""select metal_metal_die_id from metal_metal_die_relation where die_id=%s"""%(prod) ) 
    cursor.execute(qur)
    r = cursor.fetchone()
value = r[0]

i am fetching data through the query and saving the value in variable (value). now i want to assign the value of this variable to the column metal_id of the same table.

how can i assign it???????

Avatar
Discard
Best Answer

Hi

the best way is

         def on_chnage_product(self, cursor, user, field,die_id, context=None):
                   vals = {}
                   if die_id:
                         metel_id=self.pool.get('metal.metal').search(cursor, user,[('die_id','=',die_id)])
                         if metel_id:
                            metel_id=metel_id[0]
                         vals.update({'metal_id':metel_id})  
                   return {'value':vals}

use ORM function instead of database cursor

Thanks
Sandeep

Avatar
Discard
Author

if i am using this code it is giving me "AttributeError: 'NoneType' object has no attribute 'search' " error

that means no object 'metal.metal` in your database

Best Answer

Hi,

Make variable like : val = {'value': {'metal_id': False}}

val['value']['metal_id'] = XX
return val

Thanks www.acespritech.com

Avatar
Discard
Best Answer

You can use update query here:

cr.execute('update metal_metal_die_relation set metal_id='+str(value)+' where die_id='+str(prod))
Avatar
Discard
Author

hi ,pravitha update query does not work i tried to update fields but it did not updated it

helo mihir, this metal_id is a selection field rit? so the value you are trying to save must be in that selection na?