diff --git a/stock_move_line_expiration_date_required/README.rst b/stock_move_line_expiration_date_required/README.rst new file mode 100644 index 000000000000..ac197eb0d439 --- /dev/null +++ b/stock_move_line_expiration_date_required/README.rst @@ -0,0 +1,102 @@ +======================================== +Stock Move Line Expiration Date Required +======================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:4c9b95e82efe0ef2f2299d5a27bb00f7be5f9834d9a0b42867fea3f124055bfd + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-workflow/tree/18.0/stock_move_line_expiration_date_required + :alt: OCA/stock-logistics-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-workflow-18-0/stock-logistics-workflow-18-0-stock_move_line_expiration_date_required + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module causes Stock Move Lines with products that have been +configured to use an expiration date and have the expiration time set to +0 days after receipt to have their expiration date filled in manually +and not be auto-calculated. + +Expiration date on product that have been configured to use an +expiration date will be a required field. + +If you configure a product to use an expiration date and you do not set +the expiration time (0 days after receipt) then you will be required to +manually enter the expiration date on the stock move line, otherwise, +expiration date will be auto-calculated as usual. + +Pickings with products configured with an expiration date will not be +allowed to be confirmed if any of his stock move lines (related to +products with expiration date) have an empty expiration date. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Go to a warehouse entry that has a product with expiration date +configured to 0 days after receipt and fill in its expiration date +manually. + +Check the expiration date is required now and doesn't let to continue +until you fill it. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Moduon + +Contributors +------------ + +- Eduardo de Miguel (`Moduon `__) +- Emilio Pascual (`Moduon `__) + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/stock-logistics-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_move_line_expiration_date_required/__init__.py b/stock_move_line_expiration_date_required/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/stock_move_line_expiration_date_required/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_move_line_expiration_date_required/__manifest__.py b/stock_move_line_expiration_date_required/__manifest__.py new file mode 100644 index 000000000000..a2e7e70a330d --- /dev/null +++ b/stock_move_line_expiration_date_required/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2024 Moduon Team S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl) +{ + "name": "Stock Move Line Expiration Date Required", + "Summary": "Expiration date is required to enter manually on Move Lines.", + "version": "18.0.1.0.0", + "author": "Moduon, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-workflow", + "category": "Warehouse Management", + "depends": ["product_expiry"], + "data": [ + "views/stock_move_view.xml", + "views/stock_move_line_view.xml", + ], + "installable": True, + "license": "LGPL-3", +} diff --git a/stock_move_line_expiration_date_required/i18n/es.po b/stock_move_line_expiration_date_required/i18n/es.po new file mode 100644 index 000000000000..7026920856e8 --- /dev/null +++ b/stock_move_line_expiration_date_required/i18n/es.po @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_move_line_expiration_date_required +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-02-07 12:53+0000\n" +"PO-Revision-Date: 2024-02-07 13:54+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.4.2\n" + +#. module: stock_move_line_expiration_date_required +#: model:ir.model.fields,field_description:stock_move_line_expiration_date_required.field_stock_move__all_expiry_dates_set +msgid "All Expiry Dates Set" +msgstr "Todas las fechas de expiración establecidas" + +#. module: stock_move_line_expiration_date_required +#: model:ir.model,name:stock_move_line_expiration_date_required.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "Movimientos de Producto (Stock Move Line)" + +#. module: stock_move_line_expiration_date_required +#: model:ir.model,name:stock_move_line_expiration_date_required.model_stock_move +msgid "Stock Move" +msgstr "Movimiento de existencias" + +#. module: stock_move_line_expiration_date_required +#. odoo-python +#: code:addons/stock_move_line_expiration_date_required/models/stock_picking.py:0 +#, python-format +msgid "The following move lines have no expiration date: %s" +msgstr "Las siguientes líneas de movimientos no tienen fecha de caducidad: %s" + +#. module: stock_move_line_expiration_date_required +#: model:ir.model,name:stock_move_line_expiration_date_required.model_stock_picking +msgid "Transfer" +msgstr "Albarán" + +#. module: stock_move_line_expiration_date_required +#: model_terms:ir.ui.view,arch_db:stock_move_line_expiration_date_required.view_stock_move_nosuggest_operations +msgid "" +"You won't be able to confirm the parent picking until all Expiry dates are " +"set" +msgstr "" +"No podrás confirmar el Albarán padre hasta que todas las Fechas de Caducidad " +"estén establecidas" diff --git a/stock_move_line_expiration_date_required/i18n/it.po b/stock_move_line_expiration_date_required/i18n/it.po new file mode 100644 index 000000000000..8934a0f7c9cd --- /dev/null +++ b/stock_move_line_expiration_date_required/i18n/it.po @@ -0,0 +1,63 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_move_line_expiration_date_required +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-02-12 10:36+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: stock_move_line_expiration_date_required +#: model:ir.model.fields,field_description:stock_move_line_expiration_date_required.field_stock_move__all_expiry_dates_set +msgid "All Expiry Dates Set" +msgstr "Tutte le date scadenza impostate" + +#. module: stock_move_line_expiration_date_required +#: model:ir.model,name:stock_move_line_expiration_date_required.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "Movimenti prodotto (riga movimento di magazzino)" + +#. module: stock_move_line_expiration_date_required +#: model:ir.model,name:stock_move_line_expiration_date_required.model_stock_move +msgid "Stock Move" +msgstr "Movimento di magazzino" + +#. module: stock_move_line_expiration_date_required +#. odoo-python +#: code:addons/stock_move_line_expiration_date_required/models/stock_picking.py:0 +#, python-format +msgid "The following move lines have no expiration date: %s" +msgstr "Le seguenti righe di movimento non hanno data di scadenza: %s" + +#. module: stock_move_line_expiration_date_required +#: model:ir.model,name:stock_move_line_expiration_date_required.model_stock_picking +msgid "Transfer" +msgstr "Trasferimento" + +#. module: stock_move_line_expiration_date_required +#: model_terms:ir.ui.view,arch_db:stock_move_line_expiration_date_required.view_stock_move_nosuggest_operations +msgid "" +"You won't be able to confirm the parent picking until all Expiry dates are " +"set" +msgstr "" +"Non sarà possibile confermare il prelievo padre finchè non saranno impostate " +"tutte le data di scadenza" + +#~ msgid "Expiration Date" +#~ msgstr "Data di scadenza" + +#~ msgid "" +#~ "This is the date on which the goods with this Serial Number may become " +#~ "dangerous and must not be consumed." +#~ msgstr "" +#~ "Questa è la data nella quale la merce con questo numero di serie può " +#~ "diventare pericolosa e non deve essere consumata." diff --git a/stock_move_line_expiration_date_required/i18n/stock_move_line_expiration_date_required.pot b/stock_move_line_expiration_date_required/i18n/stock_move_line_expiration_date_required.pot new file mode 100644 index 000000000000..2270a414bced --- /dev/null +++ b/stock_move_line_expiration_date_required/i18n/stock_move_line_expiration_date_required.pot @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_move_line_expiration_date_required +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_move_line_expiration_date_required +#: model:ir.model.fields,field_description:stock_move_line_expiration_date_required.field_stock_move__all_expiry_dates_set +msgid "All Expiry Dates Set" +msgstr "" + +#. module: stock_move_line_expiration_date_required +#: model:ir.model,name:stock_move_line_expiration_date_required.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "" + +#. module: stock_move_line_expiration_date_required +#: model:ir.model,name:stock_move_line_expiration_date_required.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: stock_move_line_expiration_date_required +#. odoo-python +#: code:addons/stock_move_line_expiration_date_required/models/stock_picking.py:0 +#, python-format +msgid "The following move lines have no expiration date: %s" +msgstr "" + +#. module: stock_move_line_expiration_date_required +#: model:ir.model,name:stock_move_line_expiration_date_required.model_stock_picking +msgid "Transfer" +msgstr "" + +#. module: stock_move_line_expiration_date_required +#: model_terms:ir.ui.view,arch_db:stock_move_line_expiration_date_required.view_stock_move_nosuggest_operations +msgid "" +"You won't be able to confirm the parent picking until all Expiry dates are " +"set" +msgstr "" diff --git a/stock_move_line_expiration_date_required/migrations/16.0.1.0.2/post-migration.py b/stock_move_line_expiration_date_required/migrations/16.0.1.0.2/post-migration.py new file mode 100644 index 000000000000..5096ec066361 --- /dev/null +++ b/stock_move_line_expiration_date_required/migrations/16.0.1.0.2/post-migration.py @@ -0,0 +1,14 @@ +# Copyright 2024 Moduon Team S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). +from odoo import SUPERUSER_ID, api, tools + + +def migrate(cr, version): + # Update the `expiration_date` field definition in the `stock_move_line` table + env = api.Environment(cr, SUPERUSER_ID, {}) + sml_model = env["stock.move.line"] + sml_columns = tools.table_columns(env.cr, sml_model._table) + sml_model._fields["expiration_date"].update_db(sml_model, sml_columns) + # Don't need to recompute (flush) fields onto the DB because: + # If the field is required, will have been recomputed. + # If the field is not required, doesn't need to be flushed in the DB. diff --git a/stock_move_line_expiration_date_required/models/__init__.py b/stock_move_line_expiration_date_required/models/__init__.py new file mode 100644 index 000000000000..3b43ff483a1f --- /dev/null +++ b/stock_move_line_expiration_date_required/models/__init__.py @@ -0,0 +1,3 @@ +from . import stock_move_line +from . import stock_move +from . import stock_picking diff --git a/stock_move_line_expiration_date_required/models/stock_move.py b/stock_move_line_expiration_date_required/models/stock_move.py new file mode 100644 index 000000000000..7ca0fb6a06f8 --- /dev/null +++ b/stock_move_line_expiration_date_required/models/stock_move.py @@ -0,0 +1,38 @@ +# Copyright 2024 Moduon Team S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). + +import datetime + +from odoo import fields, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + all_expiry_dates_set = fields.Boolean( + compute="_compute_all_expiry_dates_set", + ) + + def _compute_all_expiry_dates_set(self): + """Check if all move lines have an expiration date set.""" + for record in self: + record.all_expiry_dates_set = not record.use_expiration_date or all( + record.move_line_ids.filtered("quantity").mapped("expiration_date") + ) + + def _generate_serial_move_line_commands(self, lot_names, origin_move_line=None): + """Override to add a default `expiration_date` into the move lines values.""" + move_lines_commands = super()._generate_serial_move_line_commands( + lot_names, origin_move_line=origin_move_line + ) + if not self.product_id.use_expiration_date: + return move_lines_commands + # managed by super() until here + expiration_dtt = False + if self.product_id.expiration_time > 0: + expiration_dtt = fields.Datetime.today() + datetime.timedelta( + days=self.product_id.expiration_time + ) + for move_line_command in move_lines_commands: + move_line_command[2]["expiration_date"] = expiration_dtt + return move_lines_commands diff --git a/stock_move_line_expiration_date_required/models/stock_move_line.py b/stock_move_line_expiration_date_required/models/stock_move_line.py new file mode 100644 index 000000000000..4dc695f1b7bf --- /dev/null +++ b/stock_move_line_expiration_date_required/models/stock_move_line.py @@ -0,0 +1,52 @@ +# Copyright 2024 Moduon Team S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). + +from datetime import timedelta + +from odoo import api, fields, models + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + @api.depends("product_id", "picking_type_use_create_lots", "lot_id.expiration_date") + def _compute_expiration_date(self): + expiration_dtt_move_line_map = {} + for move_line in self: + if move_line.lot_id.expiration_date: + continue + if not move_line.picking_type_use_create_lots: + continue + if not move_line.product_id.use_expiration_date: + continue + if move_line.expiration_date: + continue + # will be managed by super() until here + expiration_dtt = False + if move_line.product_id.expiration_time > 0: + expiration_dtt = fields.Datetime.today() + timedelta( + days=move_line.product_id.expiration_time + ) + expiration_dtt_move_line_map.setdefault(move_line, expiration_dtt) + # super writes the expiration date if it's filled directly from Stock Move + res = super()._compute_expiration_date() + # apply expiration date calculated before super + for move_line in self.filtered(lambda ml: ml in expiration_dtt_move_line_map): + move_line.expiration_date = expiration_dtt_move_line_map[move_line] + return res + + @api.onchange("product_id", "product_uom_id") + def _onchange_product_id(self): + res = super()._onchange_product_id() + if not self.picking_type_use_create_lots: + return res + if not self.product_id.use_expiration_date: + return res + # managed by super() until here + expiration_dtt = False + if self.product_id.expiration_time > 0: + expiration_dtt = fields.Datetime.today() + timedelta( + days=self.product_id.expiration_time + ) + self.expiration_date = expiration_dtt + return res diff --git a/stock_move_line_expiration_date_required/models/stock_picking.py b/stock_move_line_expiration_date_required/models/stock_picking.py new file mode 100644 index 000000000000..7465a01bcad2 --- /dev/null +++ b/stock_move_line_expiration_date_required/models/stock_picking.py @@ -0,0 +1,32 @@ +# Copyright 2024 Moduon Team S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). + + +from odoo import _, exceptions, models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def _sanity_check(self, separate_pickings=True): + """Sanity check for expiration dates.""" + res = super()._sanity_check() + for picking in self: + move_lines = self.env["stock.move.line"].browse() + for move in picking.move_ids: + # For assigned moves + move_lines |= move.move_line_ids + move_lines_wo_expiration_date = move_lines.filtered_domain( + [ + ("use_expiration_date", "=", True), + ("expiration_date", "=", False), + ] + ) + if move_lines_wo_expiration_date: + raise exceptions.UserError( + _( + "The following move lines have no expiration date: %s", + ", ".join(move_lines_wo_expiration_date.mapped("display_name")), + ) + ) + return res diff --git a/stock_move_line_expiration_date_required/pyproject.toml b/stock_move_line_expiration_date_required/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/stock_move_line_expiration_date_required/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/stock_move_line_expiration_date_required/readme/CONTRIBUTORS.md b/stock_move_line_expiration_date_required/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..3526e7763e2b --- /dev/null +++ b/stock_move_line_expiration_date_required/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Eduardo de Miguel ([Moduon](https://www.moduon.team/)) +- Emilio Pascual ([Moduon](https://www.moduon.team/)) diff --git a/stock_move_line_expiration_date_required/readme/DESCRIPTION.md b/stock_move_line_expiration_date_required/readme/DESCRIPTION.md new file mode 100644 index 000000000000..192b4bb08557 --- /dev/null +++ b/stock_move_line_expiration_date_required/readme/DESCRIPTION.md @@ -0,0 +1,16 @@ +This module causes Stock Move Lines with products that have been +configured to use an expiration date and have the expiration time set to +0 days after receipt to have their expiration date filled in manually +and not be auto-calculated. + +Expiration date on product that have been configured to use an +expiration date will be a required field. + +If you configure a product to use an expiration date and you do not set +the expiration time (0 days after receipt) then you will be required to +manually enter the expiration date on the stock move line, otherwise, +expiration date will be auto-calculated as usual. + +Pickings with products configured with an expiration date will not be +allowed to be confirmed if any of his stock move lines (related to +products with expiration date) have an empty expiration date. diff --git a/stock_move_line_expiration_date_required/readme/USAGE.md b/stock_move_line_expiration_date_required/readme/USAGE.md new file mode 100644 index 000000000000..02d11d91a161 --- /dev/null +++ b/stock_move_line_expiration_date_required/readme/USAGE.md @@ -0,0 +1,6 @@ +Go to a warehouse entry that has a product with expiration date +configured to 0 days after receipt and fill in its expiration date +manually. + +Check the expiration date is required now and doesn't let to continue +until you fill it. diff --git a/stock_move_line_expiration_date_required/static/description/icon.png b/stock_move_line_expiration_date_required/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/stock_move_line_expiration_date_required/static/description/icon.png differ diff --git a/stock_move_line_expiration_date_required/static/description/index.html b/stock_move_line_expiration_date_required/static/description/index.html new file mode 100644 index 000000000000..385c385d0c49 --- /dev/null +++ b/stock_move_line_expiration_date_required/static/description/index.html @@ -0,0 +1,445 @@ + + + + + +Stock Move Line Expiration Date Required + + + +
+

Stock Move Line Expiration Date Required

+ + +

Beta License: LGPL-3 OCA/stock-logistics-workflow Translate me on Weblate Try me on Runboat

+

This module causes Stock Move Lines with products that have been +configured to use an expiration date and have the expiration time set to +0 days after receipt to have their expiration date filled in manually +and not be auto-calculated.

+

Expiration date on product that have been configured to use an +expiration date will be a required field.

+

If you configure a product to use an expiration date and you do not set +the expiration time (0 days after receipt) then you will be required to +manually enter the expiration date on the stock move line, otherwise, +expiration date will be auto-calculated as usual.

+

Pickings with products configured with an expiration date will not be +allowed to be confirmed if any of his stock move lines (related to +products with expiration date) have an empty expiration date.

+

Table of contents

+ +
+

Usage

+

Go to a warehouse entry that has a product with expiration date +configured to 0 days after receipt and fill in its expiration date +manually.

+

Check the expiration date is required now and doesn’t let to continue +until you fill it.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Moduon
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/stock-logistics-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_move_line_expiration_date_required/tests/__init__.py b/stock_move_line_expiration_date_required/tests/__init__.py new file mode 100644 index 000000000000..d58ba06a6a9c --- /dev/null +++ b/stock_move_line_expiration_date_required/tests/__init__.py @@ -0,0 +1 @@ +from . import test_expiration_date_required diff --git a/stock_move_line_expiration_date_required/tests/test_expiration_date_required.py b/stock_move_line_expiration_date_required/tests/test_expiration_date_required.py new file mode 100644 index 000000000000..804c958808e8 --- /dev/null +++ b/stock_move_line_expiration_date_required/tests/test_expiration_date_required.py @@ -0,0 +1,120 @@ +# Copyright 2024 Moduon Team S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). + +from odoo.exceptions import UserError +from odoo.tests import Form, common + + +class TestExpirationDateRequired(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.picking_type_in = cls.env.ref("stock.picking_type_in") + cls.picking_type_in.use_create_lots = True + cls.product = cls.env["product.product"].create( + { + "name": "Test Expiration Product", + "type": "consu", + "use_expiration_date": True, + "expiration_time": 0, + "tracking": "lot", + } + ) + cls.partner = cls.env["res.partner"].create({"name": "Test Expiration Partner"}) + picking_form = Form(cls.env["stock.picking"]) + picking_form.partner_id = cls.partner + picking_form.picking_type_id = cls.picking_type_in + with picking_form.move_ids_without_package.new() as line_form: + line_form.product_id = cls.product + line_form.product_uom_qty = 10 + cls.picking = picking_form.save() + + def test_expiration_date_required_and_not_auto_calculated(self): + """Test that the expiration date is required for the stock move line + and it's not auto-calculated""" + self.picking.action_confirm() + move_form = Form( + self.picking.move_ids_without_package, + view="stock.view_stock_move_operations", + ) + with self.assertRaisesRegex( + AssertionError, "'expiration_date' is a required field" + ): + with move_form.move_line_ids.edit(0) as move_line_tree: + move_line_tree.lot_name = "TLE1" + move_line_tree.quantity = 1 + self.assertEqual(move_line_tree.expiration_date, False) + + def test_expiration_date_auto_caulculated(self): + """Test that the expiration date is auto-calculated + if expiration_date is set in the product""" + self.product.expiration_time = 10 + self.picking.action_confirm() + move_form = Form( + self.picking.move_ids_without_package, + view="stock.view_stock_move_operations", + ) + with move_form.move_line_ids.edit(0) as move_line_tree: + move_line_tree.lot_name = "TLE2" + move_line_tree.quantity = 1 + self.assertNotEqual(move_line_tree.expiration_date, False) + move_form.save() + + def test_expiration_date_generate_serials(self): + """Test that the expiration date is not auto-calculated + when generating serial numbers""" + self.product.tracking = "serial" + # Create new picking with product tracking: serial + picking_form = Form(self.env["stock.picking"]) + picking_form.partner_id = self.partner + picking_form.picking_type_id = self.picking_type_in + with picking_form.move_ids_without_package.new() as line_form: + line_form.product_id = self.product + line_form.product_uom_qty = 10 + picking = picking_form.save() + picking.action_confirm() + # Prepare serial generation + move = picking.move_ids_without_package + move.next_serial_count = move.product_uom_qty + picking.move_ids_without_package._generate_serial_numbers("001") + # Check expiration date is empty + for move_line in picking.move_line_ids: + self.assertEqual(move_line.expiration_date, False) + # Ensure picking validation is not allowed + with self.assertRaisesRegex(UserError, "expiration date"): + # Ensure run sanity_check + picking.with_context(skip_sanity_check=False).button_validate() + + def test_lot_no_expiration_date(self): + """Test that lots without expiration dates works properly""" + self.product.use_expiration_date = False + self.picking.action_confirm() + move_form = Form( + self.picking.move_ids_without_package, + view="stock.view_stock_move_operations", + ) + with move_form.move_line_ids.edit(0) as move_line_tree: + move_line_tree.lot_name = "TLE3" + move_line_tree.quantity = 10 + move_form.save() + self.picking.with_context(skip_sanity_check=False).button_validate() + + def test_serials_no_expiration_date(self): + """Test that serials without expiration dates works proplerly""" + self.product.tracking = "serial" + self.product.use_expiration_date = False + # Create new picking with product tracking: serial + picking_form = Form(self.env["stock.picking"]) + picking_form.partner_id = self.partner + picking_form.picking_type_id = self.picking_type_in + with picking_form.move_ids_without_package.new() as line_form: + line_form.product_id = self.product + line_form.product_uom_qty = 10 + picking = picking_form.save() + picking.action_confirm() + # Prepare serial generation + move = picking.move_ids_without_package + move.next_serial_count = move.product_uom_qty + picking.move_ids_without_package._generate_serial_numbers("001") + picking.with_context(skip_sanity_check=False).button_validate() diff --git a/stock_move_line_expiration_date_required/views/stock_move_line_view.xml b/stock_move_line_expiration_date_required/views/stock_move_line_view.xml new file mode 100644 index 000000000000..a92fcb99f586 --- /dev/null +++ b/stock_move_line_expiration_date_required/views/stock_move_line_view.xml @@ -0,0 +1,24 @@ + + + + stock.move.line.inherit.tree + stock.move.line + + + + + not parent.use_expiration_date or parent.picking_code != 'incoming' + + + picking_type_use_existing_lots + + + parent.use_expiration_date and parent.picking_code == 'incoming' + + + + + diff --git a/stock_move_line_expiration_date_required/views/stock_move_view.xml b/stock_move_line_expiration_date_required/views/stock_move_view.xml new file mode 100644 index 000000000000..f8bbd30fc6e9 --- /dev/null +++ b/stock_move_line_expiration_date_required/views/stock_move_view.xml @@ -0,0 +1,20 @@ + + + + stock.move.form + stock.move + + + + + + + + +