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.

0

How to create or update records via the Odoo interactive shell?

By
Maarten
on 4/23/15, 3:13 AM 1,302 views

I have a local Odoo v8 installed (installed from source, with demo data) and have installed the interactive shell module from:

    https://www.odoo.com/apps/modules/8.0/shell/

Both the local install and the interactive shell module seem to work as they should: I can start the odoo server and use the application through the browser, and I can query the database through the interactive shell. I start both, of course, with the same database argument as such:

./odoo.py -d mmg

and

./odoo.py shell -d mmg

Changes I make through the webinterface are then reflected in the shell environment. If I change, for instance, the administrator's display name, this change is reflected when I later query the model in the shell environment:

>>> self.name
u'New name'

However, creating or updating any records via the interactive shell don't seem to be persisted to the database. Here are the different ways I have tried:

>>> self.name = 'Administrator'

and

>>> u = self.env['res.users'].search([('login', '=', 'admin')])
>>> u.name = 'Administrator'

and from within a function with the @api.one decorator. None of them seem to persist to the database.

What is wrong?

Thanks in advance!

1
Maarten
On 4/24/15, 10:04 AM

Ok. Found it myself in Daniel Reis' book Odoo Development Essentials (great book, btw):

In a shell session, your data manipulation won't be made effective in the database until you use self.env.cr.commit().

You can find (and buy) the book here:

https://play.google.com/store/books/details?id=BXjhBwAAQBAJ


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

1 follower(s)

Stats

Asked: 4/23/15, 3:13 AM
Seen: 1302 times
Last updated: 4/24/15, 10:07 AM