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 speed up ORM write() method by disabling workflow?

By
Łukasz
on 4/29/13, 6:25 AM 1,823 views

I've got a problem in updating many resource in one, fast update.

I wrote simple module with workflow.

class wyn_wyn(osv.osv):
    """ Wyn """
    _name = 'wyn.wyn'
    _columns = {
                'title' : fields.char('Title', size=20, required=True),
                'savings' : fields.float('Planned savings', digits=(12,2)),
                'state': fields.selection([('draft', 'New'), ('accepted', 'Accepted'), ('refused', 'Refused')],
                        'Status', readonly=True, track_visibility='onchange')
                }

Then I wrote a wizard, where I want to calculate savings (let's say now set on 123):

def calculate(self, cr, uid, ids, context=None):
           wyn = self.pool.get("wyn.wyn");
           ids = wyn.search(cr, uid, '')
           wyn.write(cr, uid, ids, {'savings' : 123})
           return {'type': 'ir.actions.act_window_close'}

The problem is in write() method. It make one, nice, fast update on "savings" field, but then check every "wyn.wyn" resource about its workflow, one by one, what takes really long time. In the end of the write() method, is called step_workflow(), which works on every resource individually.

select * from wkf_workitem where inst_id=8056
select * from wkf_activity where id=5
select * from wkf_transition where act_from=5
select wkf_id from wkf_instance where id=8056
select state,flow_stop from wkf_workitem w left join wkf_activity a on (a.id=w.act_id) where w.inst_id=8056

How to solve this problem in efficient way? (disable workflow, code it in the other way, ...)

1

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 4/29/13, 1:23 PM

Hi,

instead to use writeand search method in method calculate, use an sql request respectively INSERT and SELECT, this will be more quick.

Bye

That means that ORM should't be use in algorithms that populate more then few resources. I don't think that your solution is right. Look at write() method it takes ids to effectivly work on group of resources but workflow call make it useless

Łukasz
on 4/30/13, 2:21 PM

I had a function which passed to 20 minutes to 1 minute, but why try .... Bye

Cyril Gaspard (GEM)
on 4/30/13, 6:13 PM

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/29/13, 6:25 AM
Seen: 1823 times
Last updated: 3/16/15, 8:10 AM