Ensure workorder sequence is applied on new workorders

Test sequence is applied for multiple operations
Rewrite _reset_work_order_sequence in a more pythonic way
Change _order of mrp.workorder to use sequence
Set sequence on existing workorders after module install
This commit is contained in:
Akim Juillerat
2022-12-20 18:55:31 +01:00
committed by Antoni Marroig Campomar
parent 06c1b96d5f
commit 821909547c
7 changed files with 152 additions and 12 deletions

View File

@@ -0,0 +1,11 @@
# 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