forked from OCA/stock-logistics-warehouse
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fixup! fixup! [ADD] stock_warehouse_calendar_orderpoint
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_calendar_orderpoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
51 changes: 51 additions & 0 deletions
51
stock_warehouse_calendar_orderpoint/tests/test_calendar_orderpoint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |