From 68c109d721d0f4d3d8b7bec6408f884e8c8d4840 Mon Sep 17 00:00:00 2001 From: MarcBForgeFlow Date: Thu, 3 Nov 2022 10:33:53 +0100 Subject: [PATCH] [16.0] [MIG] stock_receipt_lot_info --- stock_receipt_lot_info/__manifest__.py | 2 +- .../migrations/15.0.1.0.0/pre-migration.py | 18 ---- .../model/stock_move_line.py | 4 +- .../readme/CONTRIBUTORS.rst | 1 + stock_receipt_lot_info/tests/__init__.py | 1 + .../tests/test_receipt_lot_info.py | 87 +++++++++++++++++++ 6 files changed, 92 insertions(+), 21 deletions(-) delete mode 100644 stock_receipt_lot_info/migrations/15.0.1.0.0/pre-migration.py create mode 100644 stock_receipt_lot_info/tests/__init__.py create mode 100644 stock_receipt_lot_info/tests/test_receipt_lot_info.py diff --git a/stock_receipt_lot_info/__manifest__.py b/stock_receipt_lot_info/__manifest__.py index 015c4ea751c7..bbf6bf38e8d3 100644 --- a/stock_receipt_lot_info/__manifest__.py +++ b/stock_receipt_lot_info/__manifest__.py @@ -6,7 +6,7 @@ "summary": "Be able to introduce more info on lot/serial " "number while processing a receipt.", "author": "ForgeFlow, Odoo Community Association (OCA)", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "category": "Warehouse Management", "website": "https://github.com/OCA/stock-logistics-workflow", "license": "LGPL-3", diff --git a/stock_receipt_lot_info/migrations/15.0.1.0.0/pre-migration.py b/stock_receipt_lot_info/migrations/15.0.1.0.0/pre-migration.py deleted file mode 100644 index ed76bfd8eed2..000000000000 --- a/stock_receipt_lot_info/migrations/15.0.1.0.0/pre-migration.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2022 ForgeFlow, S.L. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). - -from openupgradelib import openupgrade # pylint: disable=W7936 - -_field_renames = [ - ("stock.move.line", "stock_move_line", "lot_life_date", "lot_expiration_date"), -] - - -@openupgrade.migrate() -def migrate(env, version): - cr = env.cr - for field in _field_renames: - if openupgrade.table_exists(cr, field[1]) and openupgrade.column_exists( - cr, field[1], field[2] - ): - openupgrade.rename_fields(env, [field]) diff --git a/stock_receipt_lot_info/model/stock_move_line.py b/stock_receipt_lot_info/model/stock_move_line.py index 29c7abc089ba..f196bc6d7c8b 100644 --- a/stock_receipt_lot_info/model/stock_move_line.py +++ b/stock_receipt_lot_info/model/stock_move_line.py @@ -12,8 +12,8 @@ class StockMoveLine(models.Model): lot_removal_date = fields.Datetime(string="Lot/Serial Removal Date") lot_alert_date = fields.Datetime(string="Lot/Serial Alert Date") - def _prepare_new_lot_vals(self): - vals = super()._prepare_new_lot_vals() + def _get_value_production_lot(self): + vals = super()._get_value_production_lot() creation_lot_fields = [ "expiration_date", "use_date", diff --git a/stock_receipt_lot_info/readme/CONTRIBUTORS.rst b/stock_receipt_lot_info/readme/CONTRIBUTORS.rst index 6987e7abeb34..5b512cd3e611 100644 --- a/stock_receipt_lot_info/readme/CONTRIBUTORS.rst +++ b/stock_receipt_lot_info/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * Forgeflow (https://www.forgeflow.com) * Lois Rilo + * Marc Belmonte diff --git a/stock_receipt_lot_info/tests/__init__.py b/stock_receipt_lot_info/tests/__init__.py new file mode 100644 index 000000000000..f00ae1e4dfad --- /dev/null +++ b/stock_receipt_lot_info/tests/__init__.py @@ -0,0 +1 @@ +from . import test_receipt_lot_info diff --git a/stock_receipt_lot_info/tests/test_receipt_lot_info.py b/stock_receipt_lot_info/tests/test_receipt_lot_info.py new file mode 100644 index 000000000000..23c242022b9f --- /dev/null +++ b/stock_receipt_lot_info/tests/test_receipt_lot_info.py @@ -0,0 +1,87 @@ +# Copyright 2022 ForgeFlow, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from datetime import timedelta + +from odoo.fields import Datetime +from odoo.tests.common import TransactionCase + + +class ReceiptLotInfo(TransactionCase): + @classmethod + def setUpClass(cls): + super(ReceiptLotInfo, cls).setUpClass() + group_stock_multi_locations = cls.env.ref("stock.group_stock_multi_locations") + cls.env.user.write({"groups_id": [(4, group_stock_multi_locations.id, 0)]}) + cls.stock_location = cls.env.ref("stock.stock_location_stock") + cls.customer_location = cls.env.ref("stock.stock_location_customers") + cls.supplier_location = cls.env.ref("stock.stock_location_suppliers") + cls.uom_unit = cls.env.ref("uom.product_uom_unit") + cls.uom_dozen = cls.env.ref("uom.product_uom_dozen") + cls.product = cls.env["product.product"] + cls.product_lot = cls.product.create( + { + "name": "Product A", + "type": "product", + "tracking": "lot", + "categ_id": cls.env.ref("product.product_category_all").id, + } + ) + + cls.lot1 = cls.env['stock.lot'].create({ + 'name': 'lot_1', + 'product_id': cls.product_lot.id, + 'company_id': cls.env.company.id, + } + ) + + def test_in_1(self): + """This tests adds info about dates in move lines and check if + its set correctly. + """ + + receipt_type = self.env.ref("stock.picking_type_in") + picking = self.env["stock.picking"].create( + { + "location_id": self.supplier_location.id, + "location_dest_id": self.stock_location.id, + "picking_type_id": receipt_type.id, + } + ) + move1 = self.env["stock.move"].create( + { + "name": "test_lot_info_1", + "location_id": self.supplier_location.id, + "location_dest_id": self.stock_location.id, + "product_id": self.product_lot.id, + "product_uom": self.uom_unit.id, + "product_uom_qty": 1.0, + "picking_id": picking.id, + "picking_type_id": receipt_type.id, + } + ) + picking.action_confirm() + move_line1 = move1.move_line_ids[0] + move_line1.write( + { + "qty_done": 1, + "lot_name": "lot1", + "lot_expiration_date": Datetime.now() + timedelta(days=15), + "lot_use_date": Datetime.now() + timedelta(days=5), + "lot_removal_date": Datetime.now() + timedelta(days=20), + "lot_alert_date": Datetime.now() + timedelta(days=10), + } + ) + picking.button_validate() + self.assertEqual(move1.state, "done") + + self.assertEqual( + move_line1.lot_expiration_date, Datetime.now() + timedelta(days=15) + ) + self.assertEqual(move_line1.lot_use_date, Datetime.now() + timedelta(days=5)) + self.assertEqual( + move_line1.lot_removal_date, Datetime.now() + timedelta(days=20) + ) + self.assertEqual( + move_line1.lot_alert_date, Datetime.now() + timedelta(days=10) + )