diff --git a/stock_restrict_by_planned_consumed_date/__manifest__.py b/stock_restrict_by_planned_consumed_date/__manifest__.py index f2bedb660c7..a4a1470c5e7 100644 --- a/stock_restrict_by_planned_consumed_date/__manifest__.py +++ b/stock_restrict_by_planned_consumed_date/__manifest__.py @@ -1,12 +1,15 @@ -# Copyright 2024 Foodles (https://www.foodles.co) +# Copyright 2024-2025 Foodles (https://www.foodles.co) # @author Pierre Verkest # 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 , Odoo Community Association (OCA)", + "author": "Pierre Verkest , " + "Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-workflow", "category": "Warehouse Management", "depends": [ diff --git a/stock_restrict_by_planned_consumed_date/i18n/fr.po b/stock_restrict_by_planned_consumed_date/i18n/fr.po index 1d3117f2be8..f4c1bba8887 100644 --- a/stock_restrict_by_planned_consumed_date/i18n/fr.po +++ b/stock_restrict_by_planned_consumed_date/i18n/fr.po @@ -4,33 +4,16 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 14.0+e\n" +"Project-Id-Version: Odoo Server 17.0+e\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: \n" "Language-Team: \n" +"Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" -#. module: stock_restrict_by_planned_consumed_date -#: model:ir.model.fields,field_description:stock_restrict_by_planned_consumed_date.field_stock_move__display_name -#: model:ir.model.fields,field_description:stock_restrict_by_planned_consumed_date.field_stock_quant__display_name -msgid "Display Name" -msgstr "Libellé" - -#. module: stock_restrict_by_planned_consumed_date -#: model:ir.model.fields,field_description:stock_restrict_by_planned_consumed_date.field_stock_move__id -#: model:ir.model.fields,field_description:stock_restrict_by_planned_consumed_date.field_stock_quant__id -msgid "ID" -msgstr "" - -#. module: stock_restrict_by_planned_consumed_date -#: model:ir.model.fields,field_description:stock_restrict_by_planned_consumed_date.field_stock_move____last_update -#: model:ir.model.fields,field_description:stock_restrict_by_planned_consumed_date.field_stock_quant____last_update -msgid "Last Modified on" -msgstr "Dernière modification le" - #. module: stock_restrict_by_planned_consumed_date #: model:ir.model,name:stock_restrict_by_planned_consumed_date.model_stock_quant msgid "Quants" diff --git a/stock_restrict_by_planned_consumed_date/i18n/stock_restrict_by_planned_consumed_date.pot b/stock_restrict_by_planned_consumed_date/i18n/stock_restrict_by_planned_consumed_date.pot index 166f454bf27..e6a8c056eb3 100644 --- a/stock_restrict_by_planned_consumed_date/i18n/stock_restrict_by_planned_consumed_date.pot +++ b/stock_restrict_by_planned_consumed_date/i18n/stock_restrict_by_planned_consumed_date.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 14.0+e\n" +"Project-Id-Version: Odoo Server 17.0+e\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: \n" "Language-Team: \n" @@ -13,24 +13,6 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" -#. module: stock_restrict_by_planned_consumed_date -#: model:ir.model.fields,field_description:stock_restrict_by_planned_consumed_date.field_stock_move__display_name -#: model:ir.model.fields,field_description:stock_restrict_by_planned_consumed_date.field_stock_quant__display_name -msgid "Display Name" -msgstr "" - -#. module: stock_restrict_by_planned_consumed_date -#: model:ir.model.fields,field_description:stock_restrict_by_planned_consumed_date.field_stock_move__id -#: model:ir.model.fields,field_description:stock_restrict_by_planned_consumed_date.field_stock_quant__id -msgid "ID" -msgstr "" - -#. module: stock_restrict_by_planned_consumed_date -#: model:ir.model.fields,field_description:stock_restrict_by_planned_consumed_date.field_stock_move____last_update -#: model:ir.model.fields,field_description:stock_restrict_by_planned_consumed_date.field_stock_quant____last_update -msgid "Last Modified on" -msgstr "" - #. module: stock_restrict_by_planned_consumed_date #: model:ir.model,name:stock_restrict_by_planned_consumed_date.model_stock_quant msgid "Quants" diff --git a/stock_restrict_by_planned_consumed_date/models/stock_move.py b/stock_restrict_by_planned_consumed_date/models/stock_move.py index e955a6cd37f..663d2dee913 100644 --- a/stock_restrict_by_planned_consumed_date/models/stock_move.py +++ b/stock_restrict_by_planned_consumed_date/models/stock_move.py @@ -1,4 +1,4 @@ -# Copyright 2024 Foodles (https://www.foodles.co) +# Copyright 2024-2025 Foodles (https://www.foodles.co) # @author Pierre Verkest # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import models diff --git a/stock_restrict_by_planned_consumed_date/models/stock_quant.py b/stock_restrict_by_planned_consumed_date/models/stock_quant.py index d3b507c0b64..ed7b8a56580 100644 --- a/stock_restrict_by_planned_consumed_date/models/stock_quant.py +++ b/stock_restrict_by_planned_consumed_date/models/stock_quant.py @@ -1,4 +1,4 @@ -# Copyright 2024 Foodles (https://www.foodles.co) +# Copyright 2024-2025 Foodles (https://www.foodles.co) # @author Pierre Verkest # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import api, models diff --git a/stock_restrict_by_planned_consumed_date/tests/test_stock_restrict_by_planned_consumed_date.py b/stock_restrict_by_planned_consumed_date/tests/test_stock_restrict_by_planned_consumed_date.py index 86230461aef..5b899aa98cb 100644 --- a/stock_restrict_by_planned_consumed_date/tests/test_stock_restrict_by_planned_consumed_date.py +++ b/stock_restrict_by_planned_consumed_date/tests/test_stock_restrict_by_planned_consumed_date.py @@ -1,13 +1,16 @@ -# Copyright 2024 Foodles (https://www.foodles.co) +# Copyright 2024-2025 Foodles (https://www.foodles.co) # @author Pierre Verkest # 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,7 +29,7 @@ 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", @@ -34,7 +37,7 @@ def setUpClass(cls): "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", @@ -42,14 +45,14 @@ def setUpClass(cls): "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 + 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,7 +139,7 @@ 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 @@ -146,13 +147,13 @@ def _assert_move_line_per_lot_and_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(