Odoo Help


how to assign value to column through function ??

mihir shah
on 6/18/13, 4:15 AM 2,543 views

_columns = {

    'pro_ta':fields.many2one('product.terrif.no','Tariff No.'),
    '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
    qur = ("""select metal_metal_die_id from metal_metal_die_relation where die_id=%s"""%(prod) ) 
    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???????


ClueLogics Technologies Pvt. Ltd.

--ClueLogics Technologies Pvt. Ltd.--
| 6 5 8
Delhi NCR, India
--ClueLogics Technologies Pvt. Ltd.--

 ClueLogics Technologies Pvt Ltd is a Software product and services provider. We are positioned to deliver robust, rapid and reliable Information Technology solutions that work. What we succeed upon is Technology and Technical Expertise. The industry review of ClueLogics has been commendable for the past years as most of its business comes from repeat orders by highly satisfied clients.

ClueLogics Technologies Pvt. Ltd.
On 6/18/13, 5:39 AM


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:
                   return {'value':vals}

use ORM function instead of database cursor


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

mihir shah
on 6/18/13, 8:23 AM

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

ClueLogics Technologies Pvt. Ltd.
on 6/18/13, 10:46 AM
Dharmesh Rathod
On 6/18/13, 5:26 AM


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

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

Thanks www.acespritech.com

On 6/18/13, 5:00 AM

You can use update query here:

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

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

mihir shah
on 6/18/13, 12:10 PM

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

on 6/19/13, 1:59 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 6/18/13, 4:15 AM
Seen: 2543 times
Last updated: 3/16/15, 8:10 AM