mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
Use SQL in post_init_hook to avoid potential Memory error
Co-authored-by: Iván Todorovich <ivan.todorovich@gmail.com>
This commit is contained in:
committed by
Antoni Marroig Campomar
parent
821909547c
commit
78478af933
@@ -1,11 +1,19 @@
|
||||
# Copyright 2022 Camptocamp SA
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
from odoo import SUPERUSER_ID, api, tools
|
||||
|
||||
|
||||
def post_init_hook(cr, registry):
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
all_workorders = env["mrp.workorder"].search([], order="production_id ASC, id ASC")
|
||||
for _, workorders in tools.groupby(all_workorders, lambda w: w.production_id):
|
||||
for seq, wo in enumerate(workorders, 1):
|
||||
wo.sequence = seq
|
||||
cr.execute(
|
||||
"""
|
||||
UPDATE mrp_workorder
|
||||
SET sequence = n.sequence
|
||||
FROM (
|
||||
SELECT
|
||||
id,
|
||||
ROW_NUMBER() OVER (PARTITION BY production_id) AS sequence
|
||||
FROM mrp_workorder
|
||||
ORDER BY production_id, id
|
||||
) AS n
|
||||
WHERE mrp_workorder.id = n.id
|
||||
"""
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user