Skip to content

Commit

Permalink
[IMP] mrp_production_date_planned_finished: add extensibility hook
Browse files Browse the repository at this point in the history
  • Loading branch information
LoisRForgeFlow committed Nov 18, 2024
1 parent 9939b79 commit 482351d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions mrp_production_date_planned_finished/models/mrp_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,24 @@
class MrpProduction(models.Model):
_inherit = "mrp.production"

def _get_date_planned_start_using_delays(self):
warehouse = self.picking_type_id.warehouse_id
date_planned_start = self.date_planned_finished
if hasattr(warehouse, "calendar_id") and warehouse.calendar_id:
# See `mrp_warehouse_calendar` module.
delay = self.product_id.produce_delay + self.company_id.manufacturing_lead
date_planned_start = warehouse.calendar_id.plan_days(
-1 * (delay + 1), date_planned_start
)
else:
date_planned_start -= relativedelta(days=self.product_id.produce_delay)
date_planned_start -= relativedelta(days=self.company_id.manufacturing_lead)
return date_planned_start

@api.onchange("date_planned_finished")
def _onchange_date_planned_finished_set_date_planned_start(self):
if self.date_planned_finished and not self.is_planned:
date_planned_start = self.date_planned_finished
date_planned_start -= relativedelta(days=self.product_id.produce_delay)
date_planned_start -= relativedelta(days=self.company_id.manufacturing_lead)
date_planned_start = self._get_date_planned_start_using_delays()
if date_planned_start == self.date_planned_finished:
date_planned_start -= relativedelta(hours=1)
if self.date_planned_start != date_planned_start:
Expand Down

0 comments on commit 482351d

Please sign in to comment.