Skip to content

Commit

Permalink
fixup! fixup! fixup! [ADD] stock_warehouse_calendar_orderpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sebalix authored and SilvioC2C committed Apr 16, 2024
1 parent 28bc86b commit 1ba4d8a
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions stock_warehouse_calendar_orderpoint/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_calendar_orderpoint
40 changes: 40 additions & 0 deletions stock_warehouse_calendar_orderpoint/tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2022 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl)

from odoo.tests.common import SavepointCase


class CommonCalendarOrderpoint(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.product = cls.env.ref("product.product_delivery_02").copy()
cls.seller = cls.env["product.supplierinfo"].create(
{
"name": cls.env.ref("base.res_partner_3").id,
"product_tmpl_id": cls.product.product_tmpl_id.id,
"product_id": cls.product.id,
}
)
cls.wh = cls.env.ref("stock.warehouse0")
cls.orderpoint = cls.env["stock.warehouse.orderpoint"].create(
{
"warehouse_id": cls.wh.id,
"location_id": cls.wh.lot_stock_id.id,
"product_id": cls.product.id,
"product_min_qty": "10",
"product_max_qty": "20",
"product_uom": cls.env.ref("uom.product_uom_unit"),
}
)
# OP calendar to compute lead dates from Wednesday
cls.wh.orderpoint_calendar_id = cls.env.ref(
"stock_warehouse_calendar_orderpoint.resource_calendar_orderpoint_demo"
)
cls.wh.orderpoint_on_workday = True
cls.wh.calendar_id = cls.env.ref("resource.resource_calendar_std")
# 1 day delay for supplier
cls.seller.delay = 1
# Company PO lead time
cls.wh.company_id.po_lead = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2022 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl)

from freezegun import freeze_time

from .common import CommonCalendarOrderpoint


class TestCalendarOrderpoint(CommonCalendarOrderpoint):
"""Lead date of orderpoints are computed from Wednesday."""

def setUp(self):
super().setUp()
# Reset cached value as it could have been computed during initialization
self.op_model = self.env["stock.warehouse.orderpoint"]
self.op_model.invalidate_cache(["lead_days_date"])

@freeze_time("2022-05-30 12:00") # Monday
def test_calendar_orderpoint_monday(self):
# Monday -> Wednesday + 2 days (seller delay + PO lead time) => Friday
self.assertEqual(str(self.orderpoint.lead_days_date), "2022-06-03")

@freeze_time("2022-06-01 12:00") # Wednesday during working hours
def test_calendar_orderpoint_wednesday_during_working_hours(self):
self.op_model.invalidate_cache(["lead_days_date"]) # Recompute field
self.assertEqual(str(self.orderpoint.lead_days_date), "2022-06-03")

@freeze_time("2022-06-01 20:00") # Wednesday outside working hours
def test_calendar_orderpoint_wednesday_outside_working_hours(self):
self.op_model.invalidate_cache(["lead_days_date"]) # Recompute field
self.assertEqual(
str(self.orderpoint.lead_days_date),
"2022-06-06", # Postponed to the next working day
)

@freeze_time("2022-06-01 23:30")
def test_calendar_orderpoint_wednesday_outside_of_all_calendars(self):
# Wednesday outside working hours
# + outside of reordering timeslots (00:00 -> 23:00)
self.op_model.invalidate_cache(["lead_days_date"]) # Recompute field
self.assertEqual(str(self.orderpoint.lead_days_date), "2022-06-10")

@freeze_time("2022-06-02 11:00") # Thursday
def test_calendar_orderpoint_thursday(self):
self.op_model.invalidate_cache(["lead_days_date"])
self.assertEqual(str(self.orderpoint.lead_days_date), "2022-06-10")

@freeze_time("2022-06-09 10:00") # Next Thursday
def test_calendar_orderpoint_next_thursday(self):
self.op_model.invalidate_cache(["lead_days_date"])
self.assertEqual(str(self.orderpoint.lead_days_date), "2022-06-17")

0 comments on commit 1ba4d8a

Please sign in to comment.