コンテンツへスキップ
メニュー
この質問にフラグが付けられました

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






アバター
破棄
著作者
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.

最善の回答

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.

アバター
破棄
関連投稿 返信 ビュー 活動
3
12月 19
8680
0
7月 15
3886
0
5月 25
853
2
3月 25
376
1
6月 24
1891