-
-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] stock_restrict_by_planned_consumed_date: Migration to 17.0
- Loading branch information
1 parent
d91a0a8
commit e152de5
Showing
6 changed files
with
48 additions
and
79 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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
# Copyright 2024 Foodles (https://www.foodles.co) | ||
# Copyright 2024-2025 Foodles (https://www.foodles.co) | ||
# @author Pierre Verkest <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
{ | ||
"name": "Stock restrict by planned consumed date", | ||
"Summary": "Do not reserved stock if expiration time is before planned consumed date.", | ||
"version": "14.0.1.0.0", | ||
"Summary": """ | ||
Do not reserved stock if expiration time is before planned consumed date. | ||
""", | ||
"version": "17.0.1.0.0", | ||
"development_status": "Beta", | ||
"author": "Pierre Verkest <[email protected]>, Odoo Community Association (OCA)", | ||
"author": "Pierre Verkest <[email protected]>, " | ||
"Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/stock-logistics-workflow", | ||
"category": "Warehouse Management", | ||
"depends": [ | ||
|
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
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2024 Foodles (https://www.foodles.co) | ||
# Copyright 2024-2025 Foodles (https://www.foodles.co) | ||
# @author Pierre Verkest <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from odoo import models | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2024 Foodles (https://www.foodles.co) | ||
# Copyright 2024-2025 Foodles (https://www.foodles.co) | ||
# @author Pierre Verkest <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from odoo import api, models | ||
|
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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
# Copyright 2024 Foodles (https://www.foodles.co) | ||
# Copyright 2024-2025 Foodles (https://www.foodles.co) | ||
# @author Pierre Verkest <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from datetime import datetime | ||
|
||
from odoo.tests.common import SavepointCase | ||
from freezegun import freeze_time | ||
|
||
from odoo.tests.common import TransactionCase | ||
|
||
class TestReservationBasedOnPlannedConsumedDate(SavepointCase): | ||
|
||
@freeze_time("2024-01-13") | ||
class TestReservationBasedOnPlannedConsumedDate(TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
|
@@ -26,30 +29,30 @@ def setUpClass(cls): | |
|
||
cls.product.write({"tracking": "lot", "use_expiration_date": True}) | ||
cls.product2.write({"tracking": "lot", "use_expiration_date": False}) | ||
cls.lot1 = cls.env["stock.production.lot"].create( | ||
cls.lot1 = cls.env["stock.lot"].create( | ||
{ | ||
"name": "lot1", | ||
"expiration_date": "2024-01-25", | ||
"product_id": cls.product.id, | ||
"company_id": cls.warehouse.company_id.id, | ||
} | ||
) | ||
cls.lot2 = cls.env["stock.production.lot"].create( | ||
cls.lot2 = cls.env["stock.lot"].create( | ||
{ | ||
"name": "lot2", | ||
"expiration_date": "2024-02-02", | ||
"product_id": cls.product.id, | ||
"company_id": cls.warehouse.company_id.id, | ||
} | ||
) | ||
cls.lot_product2 = cls.env["stock.production.lot"].create( | ||
cls.lot_product2 = cls.env["stock.lot"].create( | ||
{ | ||
"name": "lot product2", | ||
"product_id": cls.product2.id, | ||
"company_id": cls.warehouse.company_id.id, | ||
} | ||
) | ||
cls.product.categ_id.route_ids |= cls.env["stock.location.route"].search( | ||
cls.product.categ_id.route_ids |= cls.env["stock.route"].search( | ||
[("name", "ilike", "deliver in 2")] | ||
) | ||
cls.location_1 = cls.env["stock.location"].create( | ||
|
@@ -59,37 +62,35 @@ def setUpClass(cls): | |
{"name": "loc2", "location_id": cls.warehouse.lot_stock_id.id} | ||
) | ||
|
||
def _update_product_stock(self, qty, lot_id=False, location=None, product=None): | ||
def _update_product_stock(self, quantity, lot=False, location=None, product=None): | ||
if not location: | ||
location = self.warehouse.lot_stock_id | ||
Check warning on line 67 in stock_restrict_by_planned_consumed_date/tests/test_stock_restrict_by_planned_consumed_date.py Codecov / codecov/patchstock_restrict_by_planned_consumed_date/tests/test_stock_restrict_by_planned_consumed_date.py#L67
|
||
location_id = location.id | ||
if not product: | ||
product = self.product | ||
inventory = self.env["stock.inventory"].create( | ||
product_id = product.id if product else self.product.id | ||
lot_id = lot.id | ||
self.env["stock.quant"].search( | ||
[ | ||
("location_id", "=", location_id), | ||
("product_id", "=", product_id), | ||
("lot_id", "=", lot_id), | ||
] | ||
).unlink() | ||
self.env["stock.quant"].create( | ||
{ | ||
"name": "Test Inventory", | ||
"product_ids": [(6, 0, product.ids)], | ||
"state": "confirm", | ||
"line_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"product_qty": qty, | ||
"location_id": location.id | ||
if location | ||
else self.warehouse.lot_stock_id.id, | ||
"product_id": product.id, | ||
"product_uom_id": product.uom_id.id, | ||
"prod_lot_id": lot_id.id, | ||
}, | ||
) | ||
], | ||
"product_id": product_id, | ||
"location_id": location_id, | ||
"quantity": quantity, | ||
"product_uom_id": product.uom_id.id, | ||
"lot_id": lot_id, | ||
} | ||
) | ||
inventory.action_validate() | ||
|
||
def test_procurement_without_expiration_date(self): | ||
self._update_product_stock( | ||
10, | ||
lot_id=self.lot_product2, | ||
lot=self.lot_product2, | ||
product=self.product2, | ||
location=self.location_1, | ||
) | ||
|
@@ -138,21 +139,21 @@ def _assert_move_line_per_lot_and_location( | |
expect_lot, | ||
expect_from_location, | ||
expected_consumed_date, | ||
expect_reserved_qty, | ||
expect_reserved_quantity, | ||
): | ||
concern_move_line = moves.filtered( | ||
lambda mov: mov.lot_id == expect_lot | ||
and mov.location_id == expect_from_location | ||
and mov.move_id.planned_consumed_date == expected_consumed_date | ||
) | ||
self.assertEqual(len(concern_move_line), 1) | ||
self.assertEqual(concern_move_line.product_uom_qty, expect_reserved_qty) | ||
self.assertEqual(concern_move_line.quantity, expect_reserved_quantity) | ||
|
||
def test_procurement_with_2_steps_output(self): | ||
self._update_product_stock(10, lot_id=self.lot1, location=self.location_1) | ||
self._update_product_stock(10, lot_id=self.lot1, location=self.location_2) | ||
self._update_product_stock(5, lot_id=self.lot2, location=self.location_1) | ||
self._update_product_stock(25, lot_id=self.lot2, location=self.location_2) | ||
self._update_product_stock(10, lot=self.lot1, location=self.location_1) | ||
self._update_product_stock(10, lot=self.lot1, location=self.location_2) | ||
self._update_product_stock(5, lot=self.lot2, location=self.location_1) | ||
self._update_product_stock(25, lot=self.lot2, location=self.location_2) | ||
|
||
# create a procurement with two lines of same product with different lots | ||
procurement_group = self.env["procurement.group"].create( | ||
|