İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
20921 Görünümler

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!

Avatar
Vazgeç

write() seems to be the one to update a existing record. update() can do the same, and even on psedo-records that are not created yet.

Regards,
Rachel Gomez

Üretici En İyi Yanıt

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


Avatar
Vazgeç
En İyi Yanıt

Since a can't comment on Maarten answer, beware of coding guidelines never-commit-the-transaction

https://doc.odoo.com/contribute/15_guidelines/coding_guidelines_framework/#never-commit-the-transaction

Avatar
Vazgeç

I know its been years, but I think it's important to mention that the code guidelines mention not to commit the transaction *in the code* because the transaction is controlled by Odoo on the request level.
When you are connected via the shell, there is no request and no automatic transaction control; therefore if you want the data to persist, you have to commit manually.

İlgili Gönderiler Cevaplar Görünümler Aktivite
Update Odoo 8 Çözüldü
1
May 16
5199
1
Mar 25
2893
0
Oca 23
1812
0
Kas 22
4146
2
Mar 20
4904