Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openerp create() method returning new recordset ID but not updating database

I am developing a webservice in OpenERP 7 that create a new partner on the res_partner table with a POST method. My problem is that the create() method return me the new object ID, but the database is not updated.

Here is my code:

@openerpweb.httprequest
def add_partner(self, req, db, user, password, name, type, street, city, zip, phone, email, function):
    uid = req.session.authenticate(db, user, password)
    osv_pool = pooler.get_pool(db)
    cr = pooler.get_db(db).cursor()

    partner_pool = osv_pool.get('res.partner')
    partner_dict = {
        'name': name,
        'type': type,
        'street': street,
        'city': city,
        'zip': zip,
        'phone': phone,
        'email': email,
        'function': function
    }

    result = partner_pool.create(cr, uid, partner_dict)
    cr.close()
    return str(result)

The method doesn't give me any error, and the request return a 200 code, with the new ID. I can't find why the database is not being updated in this create method

like image 642
Tales Pádua Avatar asked Jan 15 '16 19:01

Tales Pádua


1 Answers

I have found the problem. I needed to commit the changes on the cursor object, so I used cr.commit() and succesfully added the entry on the database.

like image 186
Tales Pádua Avatar answered Oct 15 '22 14:10

Tales Pádua