简体   繁体   中英

how to set value in relational field in openerp

I have written code to migrate data from sql server 2008 to PostGreSQL using OpenERPLib in Python for OpenERP. I want to set the value of "categ_id" column of type " Many2one " of " crm.opportunity2phonecall " object. Here below is my existing code.

scheduleCall = {
                'name': 'test', 
                'action': ['schedule'], 
                'phone': "123456",
                'user_id': 1, 
                "categ_id": 10,
                'note': mail['body']
            }
    SCHEDULECALL_MODEL.create(scheduleCall)

SCHEDULECALL_MODEL = OECONN.get_model("crm.opportunity2phonecall")

In the above code i have set the hard-coded value "10" for " categ_id " field as per my requirement. When i execute above code, it gives me an error -

TypeError: unhashable type: 'list'

Try assigning a list instead of an integer as follows:

categ_id: [10]

anyway, as Atul said in his comment, update OpenERP with xmlrpc, it is safe and stable, and suppports different versions of OpenERP

Okay, I got the solution.

What i had done is - define one method in python which returns categ_id and set its value in "scheduleCall" dict and surprisingly its work. Here is my code.

scheduleCall = {
            'name': 'test', 
            'action': ['schedule'], 
            'phone': "123456",
            'user_id': 1, 
            "categ_id": get_categid_by_name('Outbound'),
            'note': mail['body']
        }
SCHEDULECALL_MODEL.create(scheduleCall)

SCHEDULECALL_MODEL = OECONN.get_model("crm.opportunity2phonecall")

And here is the method that i had define.

def get_categid_by_name(name):
"""return category id"""
categ_id = False
ids = CATEG_MODEL.search([('name', '=', name)])
categ_id = ids[0]
return categ_id

CATEG_MODEL = OECONN.get_model("crm.case.categ")

Hope it'll help to others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM