From a49b7aa15641319b098bf736c76ebc0d1a6426e0 Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Fri, 27 Mar 2026 08:30:48 +0000 Subject: [PATCH] [ADD] product_expiry_month: Add expiration time in months field This module adds a field to enter product expiration time in months, which automatically converts to days. * Adds expiration_time_months field to product.template * Automatic bidirectional conversion with expiration_time field * Configurable days per year via system parameter * Supports fractional months (e.g., 1.5, 2.75) * Includes translations for fr, es, and pt --- product_expiry_month/README.rst | 92 ++++ product_expiry_month/__init__.py | 4 + product_expiry_month/__manifest__.py | 19 + .../data/system_parameter_data.xml | 7 + product_expiry_month/i18n/es.po | 43 ++ product_expiry_month/i18n/fr.po | 43 ++ .../i18n/product_expiry_month.pot | 40 ++ product_expiry_month/i18n/pt.po | 43 ++ product_expiry_month/models/__init__.py | 4 + .../models/product_template.py | 43 ++ product_expiry_month/pyproject.toml | 3 + product_expiry_month/readme/CONFIGURATION.md | 1 + product_expiry_month/readme/CONTRIBUTORS.md | 1 + product_expiry_month/readme/DESCRIPTION.md | 4 + product_expiry_month/readme/USAGE.md | 7 + .../static/description/index.html | 440 ++++++++++++++++++ product_expiry_month/tests/__init__.py | 4 + .../tests/test_product_expiry_month.py | 56 +++ .../views/product_template_views.xml | 17 + 19 files changed, 871 insertions(+) create mode 100644 product_expiry_month/README.rst create mode 100644 product_expiry_month/__init__.py create mode 100644 product_expiry_month/__manifest__.py create mode 100644 product_expiry_month/data/system_parameter_data.xml create mode 100644 product_expiry_month/i18n/es.po create mode 100644 product_expiry_month/i18n/fr.po create mode 100644 product_expiry_month/i18n/product_expiry_month.pot create mode 100644 product_expiry_month/i18n/pt.po create mode 100644 product_expiry_month/models/__init__.py create mode 100644 product_expiry_month/models/product_template.py create mode 100644 product_expiry_month/pyproject.toml create mode 100644 product_expiry_month/readme/CONFIGURATION.md create mode 100644 product_expiry_month/readme/CONTRIBUTORS.md create mode 100644 product_expiry_month/readme/DESCRIPTION.md create mode 100644 product_expiry_month/readme/USAGE.md create mode 100644 product_expiry_month/static/description/index.html create mode 100644 product_expiry_month/tests/__init__.py create mode 100644 product_expiry_month/tests/test_product_expiry_month.py create mode 100644 product_expiry_month/views/product_template_views.xml diff --git a/product_expiry_month/README.rst b/product_expiry_month/README.rst new file mode 100644 index 00000000000..703745b5b1c --- /dev/null +++ b/product_expiry_month/README.rst @@ -0,0 +1,92 @@ +==================== +Product Expiry Month +==================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:81432ce4bf863a96ce2e0c4bc2599a60b716fccd62853c18c3f41c537c53feeb + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/17.0/product_expiry_month + :alt: OCA/product-attribute +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-attribute-17-0/product-attribute-17-0-product_expiry_month + :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/product-attribute&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a field to enter product expiration time in months, +which automatically converts to days. + +Useful for products with long shelf lives where months are more +intuitive than days. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Open a product template +2. In the Inventory tab, enter expiration time in months +3. The system automatically calculates and sets the days field + +Example: + +- Enter 24 months → Sets 730 days +- Enter 6.5 months → Sets 198 days + +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 +------- + +* Open Source Integrators + +Contributors +------------ + +- Daniel Reis, Open Source Integrators dreis@opensourceintegrators.com + +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/product-attribute `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_expiry_month/__init__.py b/product_expiry_month/__init__.py new file mode 100644 index 00000000000..11ee2076f5d --- /dev/null +++ b/product_expiry_month/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2026 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/product_expiry_month/__manifest__.py b/product_expiry_month/__manifest__.py new file mode 100644 index 00000000000..2687cd59cb3 --- /dev/null +++ b/product_expiry_month/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright (C) 2026 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Product Expiry Month", + "summary": "Add expiration time in months field with automatic conversion to days", + "version": "17.0.1.0.0", + "license": "AGPL-3", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "category": "Product", + "website": "https://github.com/OCA/product-attribute", + "depends": ["product_expiry"], + "data": [ + "data/system_parameter_data.xml", + "views/product_template_views.xml", + ], + "installable": True, + "application": False, +} diff --git a/product_expiry_month/data/system_parameter_data.xml b/product_expiry_month/data/system_parameter_data.xml new file mode 100644 index 00000000000..b11a6a240f4 --- /dev/null +++ b/product_expiry_month/data/system_parameter_data.xml @@ -0,0 +1,7 @@ + + + + product_expiry_month.days_per_year + 365 + + diff --git a/product_expiry_month/i18n/es.po b/product_expiry_month/i18n/es.po new file mode 100644 index 00000000000..e3cb907353a --- /dev/null +++ b/product_expiry_month/i18n/es.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_expiry_month +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-03-27 08:26+0000\n" +"PO-Revision-Date: 2026-03-27 08:26+0000\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: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: product_expiry_month +#: model_terms:ir.ui.view,arch_db:product_expiry_month.view_product_form_expiry_month +msgid " months" +msgstr " meses" + +#. module: product_expiry_month +#: model:ir.model.fields,field_description:product_expiry_month.field_product_product__expiration_time_months +#: model:ir.model.fields,field_description:product_expiry_month.field_product_template__expiration_time_months +msgid "Expiration Time (Months)" +msgstr "Tiempo de caducidad (Meses)" + +#. module: product_expiry_month +#: model:ir.model.fields,help:product_expiry_month.field_product_product__expiration_time_months +#: model:ir.model.fields,help:product_expiry_month.field_product_template__expiration_time_months +msgid "" +"Expiration time in months (can be fractional). Will be converted to days " +"using the system parameter 'product_expiry_month.days_per_year'." +msgstr "" +"Tiempo de caducidad en meses (puede ser fraccionario). Se convertirá a días " +"utilizando el parámetro del sistema 'product_expiry_month.days_per_year'." + +#. module: product_expiry_month +#: model:ir.model,name:product_expiry_month.model_product_template +msgid "Product" +msgstr "Producto" diff --git a/product_expiry_month/i18n/fr.po b/product_expiry_month/i18n/fr.po new file mode 100644 index 00000000000..4db4450b952 --- /dev/null +++ b/product_expiry_month/i18n/fr.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_expiry_month +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-03-27 08:26+0000\n" +"PO-Revision-Date: 2026-03-27 08:26+0000\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: nplurals=2; plural=(n > 1);\n" + +#. module: product_expiry_month +#: model_terms:ir.ui.view,arch_db:product_expiry_month.view_product_form_expiry_month +msgid " months" +msgstr " mois" + +#. module: product_expiry_month +#: model:ir.model.fields,field_description:product_expiry_month.field_product_product__expiration_time_months +#: model:ir.model.fields,field_description:product_expiry_month.field_product_template__expiration_time_months +msgid "Expiration Time (Months)" +msgstr "Délai d'expiration (Mois)" + +#. module: product_expiry_month +#: model:ir.model.fields,help:product_expiry_month.field_product_product__expiration_time_months +#: model:ir.model.fields,help:product_expiry_month.field_product_template__expiration_time_months +msgid "" +"Expiration time in months (can be fractional). Will be converted to days " +"using the system parameter 'product_expiry_month.days_per_year'." +msgstr "" +"Délai d'expiration en mois (peut être fractionnaire). Sera converti en jours " +"en utilisant le paramètre système 'product_expiry_month.days_per_year'." + +#. module: product_expiry_month +#: model:ir.model,name:product_expiry_month.model_product_template +msgid "Product" +msgstr "Article" diff --git a/product_expiry_month/i18n/product_expiry_month.pot b/product_expiry_month/i18n/product_expiry_month.pot new file mode 100644 index 00000000000..efc325c9077 --- /dev/null +++ b/product_expiry_month/i18n/product_expiry_month.pot @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_expiry_month +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-03-27 08:26+0000\n" +"PO-Revision-Date: 2026-03-27 08:26+0000\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: product_expiry_month +#: model_terms:ir.ui.view,arch_db:product_expiry_month.view_product_form_expiry_month +msgid " months" +msgstr "" + +#. module: product_expiry_month +#: model:ir.model.fields,field_description:product_expiry_month.field_product_product__expiration_time_months +#: model:ir.model.fields,field_description:product_expiry_month.field_product_template__expiration_time_months +msgid "Expiration Time (Months)" +msgstr "" + +#. module: product_expiry_month +#: model:ir.model.fields,help:product_expiry_month.field_product_product__expiration_time_months +#: model:ir.model.fields,help:product_expiry_month.field_product_template__expiration_time_months +msgid "" +"Expiration time in months (can be fractional). Will be converted to days " +"using the system parameter 'product_expiry_month.days_per_year'." +msgstr "" + +#. module: product_expiry_month +#: model:ir.model,name:product_expiry_month.model_product_template +msgid "Product" +msgstr "" diff --git a/product_expiry_month/i18n/pt.po b/product_expiry_month/i18n/pt.po new file mode 100644 index 00000000000..8e58116e58f --- /dev/null +++ b/product_expiry_month/i18n/pt.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_expiry_month +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-03-27 08:26+0000\n" +"PO-Revision-Date: 2026-03-27 08:26+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: pt\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" + +#. module: product_expiry_month +#: model_terms:ir.ui.view,arch_db:product_expiry_month.view_product_form_expiry_month +msgid " months" +msgstr " meses" + +#. module: product_expiry_month +#: model:ir.model.fields,field_description:product_expiry_month.field_product_product__expiration_time_months +#: model:ir.model.fields,field_description:product_expiry_month.field_product_template__expiration_time_months +msgid "Expiration Time (Months)" +msgstr "Tempo de Validade (Meses)" + +#. module: product_expiry_month +#: model:ir.model.fields,help:product_expiry_month.field_product_product__expiration_time_months +#: model:ir.model.fields,help:product_expiry_month.field_product_template__expiration_time_months +msgid "" +"Expiration time in months (can be fractional). Will be converted to days " +"using the system parameter 'product_expiry_month.days_per_year'." +msgstr "" +"Tempo de validade em meses (pode ser fracionado). Será convertido em dias " +"usando o parâmetro do sistema 'product_expiry_month.days_per_year'." + +#. module: product_expiry_month +#: model:ir.model,name:product_expiry_month.model_product_template +msgid "Product" +msgstr "Produto" diff --git a/product_expiry_month/models/__init__.py b/product_expiry_month/models/__init__.py new file mode 100644 index 00000000000..09456195a00 --- /dev/null +++ b/product_expiry_month/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2026 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import product_template diff --git a/product_expiry_month/models/product_template.py b/product_expiry_month/models/product_template.py new file mode 100644 index 00000000000..dae53aa8518 --- /dev/null +++ b/product_expiry_month/models/product_template.py @@ -0,0 +1,43 @@ +# Copyright (C) 2026 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + expiration_time_months = fields.Float( + string="Expiration Time (Months)", + compute="_compute_expiration_time_months", + inverse="_inverse_expiration_time_months", + store=True, + help="Expiration time in months (can be fractional). Will be converted " + "to days using the system parameter " + "'product_expiry_month.days_per_year'.", + ) + + @api.depends("expiration_time") + def _compute_expiration_time_months(self): + if self: + days_per_year = float( + self.env["ir.config_parameter"] + .sudo() + .get_param("product_expiry_month.days_per_year", "365") + ) + for template in self: + template.expiration_time_months = ( + template.expiration_time * 12 / days_per_year + ) + + def _inverse_expiration_time_months(self): + if self: + days_per_year = float( + self.env["ir.config_parameter"] + .sudo() + .get_param("product_expiry_month.days_per_year", "365") + ) + for template in self: + template.expiration_time = round( + template.expiration_time_months * days_per_year / 12 + ) diff --git a/product_expiry_month/pyproject.toml b/product_expiry_month/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/product_expiry_month/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/product_expiry_month/readme/CONFIGURATION.md b/product_expiry_month/readme/CONFIGURATION.md new file mode 100644 index 00000000000..393c8faf2e8 --- /dev/null +++ b/product_expiry_month/readme/CONFIGURATION.md @@ -0,0 +1 @@ +Change days per year in System Parameters: `product_expiry_month.days_per_year` diff --git a/product_expiry_month/readme/CONTRIBUTORS.md b/product_expiry_month/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..dbc68547de8 --- /dev/null +++ b/product_expiry_month/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +* Daniel Reis, Open Source Integrators diff --git a/product_expiry_month/readme/DESCRIPTION.md b/product_expiry_month/readme/DESCRIPTION.md new file mode 100644 index 00000000000..20791d91641 --- /dev/null +++ b/product_expiry_month/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +This module adds a field to enter product expiration time in months, +which automatically converts to days. + +Useful for products with long shelf lives where months are more intuitive than days. diff --git a/product_expiry_month/readme/USAGE.md b/product_expiry_month/readme/USAGE.md new file mode 100644 index 00000000000..f46965e921f --- /dev/null +++ b/product_expiry_month/readme/USAGE.md @@ -0,0 +1,7 @@ +1. Open a product template +2. In the Inventory tab, enter expiration time in months +3. The system automatically calculates and sets the days field + +Example: +- Enter 24 months → Sets 730 days +- Enter 6.5 months → Sets 198 days diff --git a/product_expiry_month/static/description/index.html b/product_expiry_month/static/description/index.html new file mode 100644 index 00000000000..974a6c68363 --- /dev/null +++ b/product_expiry_month/static/description/index.html @@ -0,0 +1,440 @@ + + + + + +Product Expiry Month + + + +
+

Product Expiry Month

+ + +

Beta License: AGPL-3 OCA/product-attribute Translate me on Weblate Try me on Runboat

+

This module adds a field to enter product expiration time in months, +which automatically converts to days.

+

Useful for products with long shelf lives where months are more +intuitive than days.

+

Table of contents

+ +
+

Usage

+
    +
  1. Open a product template
  2. +
  3. In the Inventory tab, enter expiration time in months
  4. +
  5. The system automatically calculates and sets the days field
  6. +
+

Example:

+
    +
  • Enter 24 months → Sets 730 days
  • +
  • Enter 6.5 months → Sets 198 days
  • +
+
+
+

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

+
    +
  • Open Source Integrators
  • +
+
+
+

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/product-attribute project on GitHub.

+

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

+
+
+
+ + diff --git a/product_expiry_month/tests/__init__.py b/product_expiry_month/tests/__init__.py new file mode 100644 index 00000000000..8844efa45d5 --- /dev/null +++ b/product_expiry_month/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2026 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_product_expiry_month diff --git a/product_expiry_month/tests/test_product_expiry_month.py b/product_expiry_month/tests/test_product_expiry_month.py new file mode 100644 index 00000000000..cc66a321307 --- /dev/null +++ b/product_expiry_month/tests/test_product_expiry_month.py @@ -0,0 +1,56 @@ +# Copyright (C) 2026 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestProductExpiryMonth(TransactionCase): + def setUp(self): + super().setUp() + # Create a product template with expiration enabled + self.product_template = self.env["product.template"].create( + { + "name": "Test Product", + "use_expiration_date": True, + "tracking": "lot", + } + ) + + def test_expiration_time_months_calculation(self): + """Test that months are correctly converted to days""" + # Test whole months - set months and check days + self.product_template.expiration_time_months = 24 + self.assertEqual(self.product_template.expiration_time, 730) + + # Test fractional months + self.product_template.expiration_time_months = 6.5 + self.assertEqual(self.product_template.expiration_time, 198) + + # Test zero months + self.product_template.expiration_time_months = 0 + self.assertEqual(self.product_template.expiration_time, 0) + + def test_expiration_time_inverse_calculation(self): + """Test that days are correctly converted to months""" + # Test setting days and checking months + self.product_template.expiration_time = 730 + self.assertEqual(round(self.product_template.expiration_time_months, 2), 24.0) + + # Test fractional days + self.product_template.expiration_time = 198 + self.assertEqual(round(self.product_template.expiration_time_months, 2), 6.51) + + # Test zero days + self.product_template.expiration_time = 0 + self.assertEqual(self.product_template.expiration_time_months, 0) + + def test_custom_days_per_year(self): + """Test calculation with custom days per year""" + # Change to leap year + self.env["ir.config_parameter"].sudo().set_param( + "product_expiry_month.days_per_year", "366" + ) + + self.product_template.expiration_time_months = 12 + # 366/12 = 30.5, so 12 months = 366 days + self.assertEqual(self.product_template.expiration_time, 366) diff --git a/product_expiry_month/views/product_template_views.xml b/product_expiry_month/views/product_template_views.xml new file mode 100644 index 00000000000..7c90986ff17 --- /dev/null +++ b/product_expiry_month/views/product_template_views.xml @@ -0,0 +1,17 @@ + + + + product.template.expiry.month.form + product.template + + + + +