Odoo Help

1

how to assign value to column through function ??

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

ClueLogics Technologies Pvt. Ltd.

--ClueLogics Technologies Pvt. Ltd.--
6143
| 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

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

ClueLogics Technologies Pvt. Ltd.
on 6/18/13, 10:46 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

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

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.

Register

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)

Stats

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