From cb7970a350e06ea69dd57b7979ad6b3e472b5892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Tarroja=20Caubet?= Date: Wed, 18 Jan 2023 17:34:20 +0100 Subject: [PATCH] Reschedule planned date for late productions Closes #11494 --- modules/production/CHANGELOG | 1 + modules/production/production.py | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/modules/production/CHANGELOG b/modules/production/CHANGELOG index e4f5382a1b..b3598cec85 100644 --- a/modules/production/CHANGELOG +++ b/modules/production/CHANGELOG @@ -1,3 +1,4 @@ +* Reschedule planned date for late productions Version 6.8.0 - 2023-05-01 -------------------------- diff --git a/modules/production/production.py b/modules/production/production.py index 6f3fd117eb..cf20bf714f 100644 --- a/modules/production/production.py +++ b/modules/production/production.py @@ -35,7 +35,7 @@ class Production(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): }) planned_date = fields.Date('Planned Date', states={ - 'readonly': ~Eval('state').in_(['request', 'draft']), + 'readonly': Eval('state').in_(['cancelled', 'done']), }) effective_date = fields.Date('Effective Date', states={ @@ -795,7 +795,7 @@ class Production(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): cls.assign(to_assign) @classmethod - def _get_reschedule_domain(cls, date): + def _get_reschedule_planned_start_dates_domain(cls, date): context = Transaction().context return [ ('company', '=', context.get('company')), @@ -803,17 +803,35 @@ class Production(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): ('planned_start_date', '<', date), ] + @classmethod + def _get_reschedule_planned_dates_domain(cls, date): + context = Transaction().context + return [ + ('company', '=', context.get('company')), + ('state', '=', 'running'), + ('planned_date', '<', date), + ] + @classmethod def reschedule(cls, date=None): pool = Pool() Date = pool.get('ir.date') if date is None: date = Date.today() - productions = cls.search(cls._get_reschedule_domain(date)) - for production in productions: + + to_reschedule_start_date = cls.search( + cls._get_reschedule_planned_start_dates_domain(date)) + to_reschedule_planned_date = cls.search( + cls._get_reschedule_planned_dates_domain(date)) + + for production in to_reschedule_start_date: production.planned_start_date = date production.on_change_planned_start_date() - cls.save(productions) + + for production in to_reschedule_planned_date: + production.planned_date = date + + cls.save(to_reschedule_start_date + to_reschedule_planned_date) @property @fields.depends('warehouse')