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.

1

how to assign value to column through function ??

By
mihir shah
on 6/18/13, 4:15 AM 1,652 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???????

2

Sandeep

--Sandeep--
6083
| 6 5 8
Delhi, India
--Sandeep--
Python OpenERP Developer http://in.linkedin.com/pub/sandeep-rana/3b/a16/786/
Sandeep
On 6/18/13, 5:39 AM

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

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

Sandeep
on 6/18/13, 10:46 AM
1
Pravitha
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?

Pravitha
on 6/19/13, 1:59 AM
1
Dharmesh Rathod
On 6/18/13, 5:26 AM

Hi,

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

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

Thanks www.acespritech.com

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

0 follower(s)

Stats

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