[MIG] mrp_warehouse_calendar: Migration to 17.0

This commit is contained in:
JasminSForgeFlow
2024-03-12 11:51:32 +05:30
parent b9eb9e6ec5
commit 085c217d7b
4 changed files with 33 additions and 29 deletions

View File

@@ -4,7 +4,7 @@
{
"name": "MRP Warehouse Calendar",
"summary": "Considers the warehouse calendars in manufacturing",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"license": "LGPL-3",
"website": "https://github.com/OCA/manufacture",
"author": "ForgeFlow, Odoo Community Association (OCA)",

View File

@@ -7,25 +7,31 @@ from odoo import api, models
class MrpProduction(models.Model):
_inherit = "mrp.production"
@api.depends("company_id", "date_planned_start", "is_planned", "product_id")
def _compute_date_planned_finished(self):
res = super(MrpProduction, self)._compute_date_planned_finished()
productions = self.filtered(lambda p: p.date_planned_start and not p.is_planned)
@api.depends(
"company_id",
"date_start",
"is_planned",
"product_id",
"workorder_ids.duration_expected",
)
def _compute_date_finished(self):
res = super()._compute_date_finished()
productions = self.filtered(lambda p: p.date_start and not p.is_planned)
for production in productions:
warehouse = self.picking_type_id.warehouse_id
if warehouse.calendar_id:
if production.product_id.produce_delay:
production.date_planned_finished = warehouse.calendar_id.plan_days(
+1 * production.product_id.produce_delay + 1,
production.date_planned_start,
if production.bom_id.produce_delay:
production.date_finished = warehouse.calendar_id.plan_days(
+1 * production.bom_id.produce_delay + 1,
production.date_start,
)
if production.company_id.manufacturing_lead:
production.date_planned_finished = warehouse.calendar_id.plan_days(
production.date_finished = warehouse.calendar_id.plan_days(
+1 * production.company_id.manufacturing_lead + 1,
production.date_planned_finished,
production.date_finished,
)
production.move_finished_ids = [
(1, m.id, {"date": production.date_planned_finished})
(1, m.id, {"date": production.date_finished})
for m in production.move_finished_ids
]
return res
@@ -33,11 +39,11 @@ class MrpProduction(models.Model):
@api.returns("self", lambda value: value.id)
def copy(self, default=None):
mo = super().copy(default=default)
dt_planned = mo.date_planned_start
dt_planned = mo.date_start
warehouse = mo.picking_type_id.warehouse_id
if warehouse.calendar_id and mo.product_id.produce_delay:
if warehouse.calendar_id and mo.bom_id.produce_delay:
date_expected = warehouse.calendar_id.plan_days(
+1 * self.product_id.produce_delay + 1, dt_planned
+1 * self.bom_id.produce_delay + 1, dt_planned
)
mo.date_planned_finished = date_expected
mo.date_finished = date_expected
return mo

View File

@@ -7,17 +7,15 @@ from odoo import fields, models
class StockRule(models.Model):
_inherit = "stock.rule"
def _get_date_planned(self, product_id, company_id, values):
date_planned = super()._get_date_planned(product_id, company_id, values)
def _get_date_planned(self, bom_id, values):
date_planned = super()._get_date_planned(bom_id, values)
picking_type = self.picking_type_id or values["warehouse_id"].manu_type_id
# We force the date planned to be at the beginning of the day.
# So no work intervals are found in planned date.
dt_planned = fields.Datetime.to_datetime(values["date_planned"]).replace(hour=0)
warehouse = picking_type.warehouse_id
if warehouse.calendar_id and product_id.produce_delay:
lead_days = (
values["company_id"].manufacturing_lead + product_id.produce_delay
)
if warehouse.calendar_id and bom_id.produce_delay:
lead_days = values["company_id"].manufacturing_lead + bom_id.produce_delay
date_expected = warehouse.calendar_id.plan_days(-1 * lead_days, dt_planned)
date_planned = date_expected
return date_planned

View File

@@ -7,7 +7,7 @@ from odoo.tests.common import TransactionCase
class TestMrpWarehouseCalendar(TransactionCase):
def setUp(self):
super(TestMrpWarehouseCalendar, self).setUp()
super().setUp()
self.move_obj = self.env["stock.move"]
self.pg_obj = self.env["procurement.group"]
@@ -28,7 +28,6 @@ class TestMrpWarehouseCalendar(TransactionCase):
"name": "test product",
"default_code": "PRD",
"type": "product",
"produce_delay": 1,
}
)
self.product_2 = self.env["product.product"].create(
@@ -41,6 +40,7 @@ class TestMrpWarehouseCalendar(TransactionCase):
"product_uom_id": self.product.uom_id.id,
"product_qty": 1.0,
"type": "normal",
"produce_delay": 1,
}
)
self.env["mrp.bom.line"].create(
@@ -73,7 +73,7 @@ class TestMrpWarehouseCalendar(TransactionCase):
mo = self.env["mrp.production"].search(
[("product_id", "=", self.product.id)], limit=1
)
date_plan_start = fields.Date.to_date(mo.date_planned_start)
date_plan_start = fields.Date.to_date(mo.date_start)
# Friday 4th Jan 2097
friday = fields.Date.to_date("2097-01-04 09:00:00")
@@ -105,7 +105,7 @@ class TestMrpWarehouseCalendar(TransactionCase):
mo = self.env["mrp.production"].search(
[("product_id", "=", self.product.id)], limit=1
)
date_plan_start = fields.Date.to_date(mo.date_planned_start)
date_plan_start = fields.Date.to_date(mo.date_start)
# Friday 4th Jan 2097
friday = fields.Date.to_date("2097-01-04 09:00:00")
@@ -122,8 +122,8 @@ class TestMrpWarehouseCalendar(TransactionCase):
]._get_default_picking_type_id(self.company.id),
}
)
mo.date_planned_start = "2097-01-04 09:00:00"
mo._compute_date_planned_finished()
date_plan_finished = fields.Date.to_date(mo.date_planned_finished)
mo.date_start = "2097-01-04 09:00:00"
mo._compute_date_finished()
date_plan_finished = fields.Date.to_date(mo.date_finished)
monday = fields.Date.to_date("2097-01-07 09:00:00")
self.assertEqual(date_plan_finished, monday)