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.

4

How can I speedup account.account creation?

By
Alexandre Fayolle - Camptocamp
on 3/26/13, 4:42 AM 2,401 views

I need to speed up an installation script which creates a large number of account.account records using the public ORM API. I do this by calling (through erppeek) model('account.account').create for each record, and each account creation takes up to 8 seconds on my not too slow laptop.

I'm not sure where the time is spent. Maybe in the parent_left/parent_right computation.

7

Alexandre Fayolle - Camptocamp

--Alexandre Fayolle - Camptocamp--
1109
| 5 6 8
Le Bourget-du-Lac, France
--Alexandre Fayolle - Camptocamp--

Alexandre has been working on Odoo at Camptocamp since 2012 as a project manager and technical lead. He is an active actor in the Odoo Community (github projects, mailing lists, IRC...), and wants to build a better ecosystem for Odoo developers. He is a member of the Odoo Community Association board and an active contributor to the OCA projects.

Alexandre Fayolle - Camptocamp
On 3/26/13, 5:10 AM

I dug a bit in the code of create() in orm.py, and found an interesting value to pass in context:

AccountAccount.create(values, context={'defer_parent_store_computation': True})

This seems to defer the computation of parent_left and parent_right until later (and each account creation now only takes ~40ms. Unfortunately, I can't seem to be able to call _parent_store_compute via erppeek because it is not a public method...

So a solution is to use erppeek.get_pool(dbname) to get a Registry instance, tell that instance that the model needs reparenting and call do_parent_store:

registry = erppeek.get_pool('db_name')
registry._init_parent['account.account'] = True
cr = registry.db.cursor()
registry.do_parent_store(cr)
cr.commit()
cr.close()

speedup: 3h20 -> 30s :-)

Camptocamp France SAS, Alexandre Fayolle - Camptocamp
on 3/26/13, 5:28 AM

Thx for the info! The import of accounts its a slow process

Juanjo Algaz
on 10/23/13, 8:48 AM

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: 3/26/13, 4:42 AM
Seen: 2401 times
Last updated: 1/22/16, 11:46 AM