Skip to content

Commit

Permalink
[MIG] stock_restrict_by_planned_consumed_date: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandregaldeano committed Feb 3, 2025
1 parent d91a0a8 commit e152de5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 79 deletions.
11 changes: 7 additions & 4 deletions stock_restrict_by_planned_consumed_date/__manifest__.py
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": [
Expand Down
21 changes: 2 additions & 19 deletions stock_restrict_by_planned_consumed_date/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
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
Expand Down
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
Expand Down
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()
Expand All @@ -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(
Expand All @@ -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

View check run for this annotation

Codecov / codecov/patch

stock_restrict_by_planned_consumed_date/tests/test_stock_restrict_by_planned_consumed_date.py#L67

Added line #L67 was not covered by tests
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,
)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e152de5

Please sign in to comment.