Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
3858 Visualizzazioni

Hi everyone,
Currently I have 60k account.move.line records in my system, and i have to set a value of compute field so while the compute runs it takes lot of time to set the value in field for 60k records...
Please advise me how can I optimize that.
This is on priority ,  I have pasted the method below to make my question more clear
Thanks in Advance


Compute Method:

line_obj = self.env['account.move.line']
for rec in self:
if rec.account_id:
query = """SELECT sum(balance) from account_move_line where account_id = %s and create_date < %s and date <= %s and id != %s """
self.env.cr.execute(query, (rec.account_id.id, rec.create_date, rec.date, rec.id))
running_balance = self.env.cr.fetchone()[0] or 0.0
if rec.debit:
running_balance += rec.debit
if rec.credit:
running_balance -= rec.credit
rec.running_balance = running_balance
else:
rec.running_balance = 0.00






Avatar
Abbandona
Autore
I have already stored that value as I need that field in some report.
I know that it will obviously take take...I just wanted a efficient way that it can reduce somewhat time.

On Mon, Oct 18, 2021, 11:26 PM Devendra Kavthekar <dkatodoo@gmail.com> wrote:

A new answer on How can I improve Performance of Compute method in Account Move Line has been posted. Click here to access the post :

See post

Sent by Odoo S.A. using Odoo.

Risposta migliore

You can do this in batch of 10k records or minimum amount of records possible that can allow the commit to happen.

Not sure about the purpose - but it will take more time of course if the query is performed on large dataset.

By the way, it seems you need to:

Do:

date <= %s and id == %s """

Instead of:

date <= %s and id != %s """
?


As a side note, may be you already know:

Dont write compute methods at all, best way if possible. Use create/write or other methods instead.

And if you must write compute method - make it stored when possible.

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
3
dic 19
8679
0
lug 15
3886
0
mag 25
853
2
mar 25
376
1
giu 24
1891