diff --git a/stock_production_lot_warranty/README.rst b/stock_production_lot_warranty/README.rst new file mode 100644 index 000000000..7e831f20a --- /dev/null +++ b/stock_production_lot_warranty/README.rst @@ -0,0 +1,126 @@ +=================================== +Warranty Date on Lot/Serial Numbers +=================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d6965242ba21cd047683380ad7586c6f7e079d0d79f794726198d318c6a5fe08 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Frma-lightgray.png?logo=github + :target: https://github.com/OCA/rma/tree/18.0/stock_production_lot_warranty + :alt: OCA/rma +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/rma-18-0/rma-18-0-stock_production_lot_warranty + :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/rma&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Odoo does not provide the warranty information on the serial number of a +product. + +This module allows you to compute the warranty expiration date of a +serialized product based on the warranty duration. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module: + +- Go to Inventory > Configuration > Settings +- Activate the traceability +- Go to Inventory > Products > Products +- Create or select a product and set the warranty +- Go to the Inventory tab in the Logistics section +- Set the warranty duration + +Usage +===== + +To use this module, + +- Go to Inventory > Products > Lot/Serial Numbers +- Create a new serial number and select a product +- The Warranty Expiration Date is automatically computed based on today + + the warranty duration from the select product +- You can overwrite the computed date with your own value. + +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 +------------ + +- Steve Campbell +- Maxime Chambreuil +- Serpent Consulting Services Pvt. Ltd. + +Other credits +------------- + +This module has been financially supported by: + +- Pavlov Media + <`https://www.pavlovmedia.com\\> >`__ +- Open Source Integrators + <`https://www.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. + +.. |maintainer-osi-scampbell| image:: https://github.com/osi-scampbell.png?size=40px + :target: https://github.com/osi-scampbell + :alt: osi-scampbell +.. |maintainer-max3903| image:: https://github.com/max3903.png?size=40px + :target: https://github.com/max3903 + :alt: max3903 + +Current `maintainers `__: + +|maintainer-osi-scampbell| |maintainer-max3903| + +This module is part of the `OCA/rma `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_production_lot_warranty/__init__.py b/stock_production_lot_warranty/__init__.py new file mode 100644 index 000000000..69f7babdf --- /dev/null +++ b/stock_production_lot_warranty/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/stock_production_lot_warranty/__manifest__.py b/stock_production_lot_warranty/__manifest__.py new file mode 100644 index 000000000..ada04ddd4 --- /dev/null +++ b/stock_production_lot_warranty/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2021 Serpent Consulting Services +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Warranty Date on Lot/Serial Numbers", + "summary": "Add warranty date to stock production lot", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "category": "Stock", + "website": "https://github.com/OCA/rma", + "depends": ["product_warranty", "stock"], + "data": ["views/stock_production_lot.xml"], + "installable": True, + "development_status": "Beta", + "maintainers": ["osi-scampbell", "max3903"], +} diff --git a/stock_production_lot_warranty/i18n/pt.po b/stock_production_lot_warranty/i18n/pt.po new file mode 100644 index 000000000..995298183 --- /dev/null +++ b/stock_production_lot_warranty/i18n/pt.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_production_lot_warranty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-03-11 20:45+0000\n" +"Last-Translator: Pedro Castro Silva \n" +"Language-Team: none\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" +"X-Generator: Weblate 4.3.2\n" + +#. module: stock_production_lot_warranty +#: model:ir.model,name:stock_production_lot_warranty.model_stock_production_lot +msgid "Lot/Serial" +msgstr "Lote/Série" + +#. module: stock_production_lot_warranty +#: model:ir.model.fields,field_description:stock_production_lot_warranty.field_stock_production_lot__warranty_exp_date +msgid "Warranty Expiration Date" +msgstr "Data de Expiração da Garantia" diff --git a/stock_production_lot_warranty/i18n/pt_BR.po b/stock_production_lot_warranty/i18n/pt_BR.po new file mode 100644 index 000000000..e10cadd7f --- /dev/null +++ b/stock_production_lot_warranty/i18n/pt_BR.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_production_lot_warranty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-07-22 18:19+0000\n" +"Last-Translator: Fernando Colus \n" +"Language-Team: none\n" +"Language: pt_BR\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 3.10\n" + +#. module: stock_production_lot_warranty +#: model:ir.model,name:stock_production_lot_warranty.model_stock_production_lot +msgid "Lot/Serial" +msgstr "Lote/Serial" + +#. module: stock_production_lot_warranty +#: model:ir.model.fields,field_description:stock_production_lot_warranty.field_stock_production_lot__warranty_exp_date +msgid "Warranty Expiration Date" +msgstr "Data de Término da Garantia" diff --git a/stock_production_lot_warranty/i18n/stock_production_lot_warranty.pot b/stock_production_lot_warranty/i18n/stock_production_lot_warranty.pot new file mode 100644 index 000000000..83f1fa456 --- /dev/null +++ b/stock_production_lot_warranty/i18n/stock_production_lot_warranty.pot @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_production_lot_warranty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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_production_lot_warranty +#: model:ir.model,name:stock_production_lot_warranty.model_stock_production_lot +msgid "Lot/Serial" +msgstr "" + +#. module: stock_production_lot_warranty +#: model:ir.model.fields,field_description:stock_production_lot_warranty.field_stock_production_lot__warranty_exp_date +msgid "Warranty Expiration Date" +msgstr "" diff --git a/stock_production_lot_warranty/models/__init__.py b/stock_production_lot_warranty/models/__init__.py new file mode 100644 index 000000000..d45f1fe83 --- /dev/null +++ b/stock_production_lot_warranty/models/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import stock_production_lot diff --git a/stock_production_lot_warranty/models/stock_production_lot.py b/stock_production_lot_warranty/models/stock_production_lot.py new file mode 100644 index 000000000..2a38eaeec --- /dev/null +++ b/stock_production_lot_warranty/models/stock_production_lot.py @@ -0,0 +1,31 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2021 Serpent Consulting Services +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models + +DELTA_TYPES = ("day", "week", "month", "year") + + +class StockProductionLot(models.Model): + _inherit = "stock.lot" + + warranty_exp_date = fields.Date(string="Warranty Expiration Date") + + def _get_warranty_exp_date(self, start_date=None): + if not start_date: + start_date = fields.Date.context_today(self) + elif hasattr(start_date, "astimezone"): + # Datetime object, convert to date + start_date = fields.Date.context_today(self, timestamp=start_date) + delta_type = self.product_id.product_tmpl_id.warranty_type + duration = self.product_id.product_tmpl_id.warranty + if not duration or delta_type not in DELTA_TYPES: + return False + return start_date + relativedelta(**{f"{delta_type}s": duration}) + + @api.onchange("product_id") + def _onchange_product_id(self): + self.warranty_exp_date = self._get_warranty_exp_date() diff --git a/stock_production_lot_warranty/pyproject.toml b/stock_production_lot_warranty/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/stock_production_lot_warranty/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/stock_production_lot_warranty/readme/CONFIGURE.md b/stock_production_lot_warranty/readme/CONFIGURE.md new file mode 100644 index 000000000..1c67d3ca7 --- /dev/null +++ b/stock_production_lot_warranty/readme/CONFIGURE.md @@ -0,0 +1,8 @@ +To configure this module: + +- Go to Inventory \> Configuration \> Settings +- Activate the traceability +- Go to Inventory \> Products \> Products +- Create or select a product and set the warranty +- Go to the Inventory tab in the Logistics section +- Set the warranty duration diff --git a/stock_production_lot_warranty/readme/CONTRIBUTORS.md b/stock_production_lot_warranty/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..2270e472a --- /dev/null +++ b/stock_production_lot_warranty/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Steve Campbell \ +- Maxime Chambreuil \ +- Serpent Consulting Services Pvt. Ltd. \ diff --git a/stock_production_lot_warranty/readme/CREDITS.md b/stock_production_lot_warranty/readme/CREDITS.md new file mode 100644 index 000000000..066e5e64f --- /dev/null +++ b/stock_production_lot_warranty/readme/CREDITS.md @@ -0,0 +1,4 @@ +This module has been financially supported by: + +- Pavlov Media \ +- Open Source Integrators \ diff --git a/stock_production_lot_warranty/readme/DESCRIPTION.md b/stock_production_lot_warranty/readme/DESCRIPTION.md new file mode 100644 index 000000000..5c5785656 --- /dev/null +++ b/stock_production_lot_warranty/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +Odoo does not provide the warranty information on the serial number of a +product. + +This module allows you to compute the warranty expiration date of a +serialized product based on the warranty duration. diff --git a/stock_production_lot_warranty/readme/USAGE.md b/stock_production_lot_warranty/readme/USAGE.md new file mode 100644 index 000000000..b9c4f1dc2 --- /dev/null +++ b/stock_production_lot_warranty/readme/USAGE.md @@ -0,0 +1,7 @@ +To use this module, + +- Go to Inventory \> Products \> Lot/Serial Numbers +- Create a new serial number and select a product +- The Warranty Expiration Date is automatically computed based on + today + the warranty duration from the select product +- You can overwrite the computed date with your own value. diff --git a/stock_production_lot_warranty/static/description/icon.png b/stock_production_lot_warranty/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_production_lot_warranty/static/description/icon.png differ diff --git a/stock_production_lot_warranty/static/description/index.html b/stock_production_lot_warranty/static/description/index.html new file mode 100644 index 000000000..9677c3048 --- /dev/null +++ b/stock_production_lot_warranty/static/description/index.html @@ -0,0 +1,466 @@ + + + + + +Warranty Date on Lot/Serial Numbers + + + +
+

Warranty Date on Lot/Serial Numbers

+ + +

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

+

Odoo does not provide the warranty information on the serial number of a +product.

+

This module allows you to compute the warranty expiration date of a +serialized product based on the warranty duration.

+

Table of contents

+ +
+

Configuration

+

To configure this module:

+
    +
  • Go to Inventory > Configuration > Settings
  • +
  • Activate the traceability
  • +
  • Go to Inventory > Products > Products
  • +
  • Create or select a product and set the warranty
  • +
  • Go to the Inventory tab in the Logistics section
  • +
  • Set the warranty duration
  • +
+
+
+

Usage

+

To use this module,

+
    +
  • Go to Inventory > Products > Lot/Serial Numbers
  • +
  • Create a new serial number and select a product
  • +
  • The Warranty Expiration Date is automatically computed based on today ++ the warranty duration from the select product
  • +
  • You can overwrite the computed date with your own value.
  • +
+
+
+

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

+ +
+
+

Other credits

+

This module has been financially supported by:

+ +
+
+

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.

+

Current maintainers:

+

osi-scampbell max3903

+

This module is part of the OCA/rma project on GitHub.

+

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

+
+
+
+ + diff --git a/stock_production_lot_warranty/tests/__init__.py b/stock_production_lot_warranty/tests/__init__.py new file mode 100644 index 000000000..01c923daa --- /dev/null +++ b/stock_production_lot_warranty/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2021 Open Source Integrators +# Copyright (C) 2021 Serpent Consulting Services +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import test_product_lot_warranty diff --git a/stock_production_lot_warranty/tests/test_product_lot_warranty.py b/stock_production_lot_warranty/tests/test_product_lot_warranty.py new file mode 100644 index 000000000..e489cf62c --- /dev/null +++ b/stock_production_lot_warranty/tests/test_product_lot_warranty.py @@ -0,0 +1,113 @@ +# Copyright (C) 2021 Open Source Integrators +# Copyright (C) 2021 Serpent Consulting Services +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from datetime import datetime, timedelta + +from psycopg2 import IntegrityError + +from odoo.exceptions import ValidationError +from odoo.tests import common +from odoo.tools import mute_logger + + +class TestProductLotWarranty(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company1 = cls.env["res.company"].create({"name": "Test company1"}) + cls.product1 = cls.env["product.product"].create( + { + "name": "TestProduct", + "warranty_type": "day", + "warranty": 5, + } + ) + + def test_productlot_warranty(self): + production_lot = self.env["stock.lot"].create( + {"product_id": self.product1.id, "company_id": self.company1.id} + ) + production_lot._onchange_product_id() + self.assertEqual( + production_lot.warranty_exp_date, + (datetime.now() + timedelta(days=5)).date(), + ) + + @mute_logger("odoo.sql_db") + def test_productlot_no_product(self): + # stock.lot "product_id" is required=True + # In Odoo 18, trying to create a lot without product should raise an error + error_raised = False + try: + lot = self.env["stock.lot"].create( + { + "product_id": False, + "company_id": self.company1.id, + "name": "test_lot", + } + ) + # Force the constraint check if create doesn't raise immediately + lot.flush_recordset() + except (ValidationError, IntegrityError): + # Expected behavior - constraint violation + error_raised = True + + self.assertTrue( + error_raised, "Creating a lot without product should raise an error" + ) + + @mute_logger("odoo.sql_db") + def test_productlot_no_warranty_type(self): + # product.template "warranty_type" is required=True if warranty is installed + # In Odoo 18, this should raise an error when warranty_type is False/None + error_raised = False + try: + product = self.env["product.product"].create( + { + "name": "TestProduct", + "warranty_type": False, + "warranty": 5, + } + ) + # Force the constraint check if create doesn't raise immediately + product.flush_recordset() + except (ValidationError, IntegrityError): + # Expected behavior - constraint violation + error_raised = True + + self.assertTrue( + error_raised, + "Creating a product without warranty_type should raise an error", + ) + + def test_productlot_no_warranty(self): + product2 = self.env["product.product"].create( + { + "name": "TestProduct", + "warranty_type": "week", + "warranty": 0, + } + ) + production_lot = self.env["stock.lot"].create( + {"product_id": product2.id, "company_id": self.company1.id} + ) + production_lot._onchange_product_id() + self.assertFalse(production_lot.warranty_exp_date) + + def test_get_warranty_exp_date(self): + production_lot = self.env["stock.lot"].create( + {"product_id": self.product1.id, "company_id": self.company1.id} + ) + timestamp = datetime.now() - timedelta(days=3) + self.assertEqual( + production_lot._get_warranty_exp_date(), + (datetime.now() + timedelta(days=5)).date(), + ) + self.assertEqual( + production_lot._get_warranty_exp_date(timestamp), + (datetime.now() + timedelta(days=2)).date(), + ) + self.assertEqual( + production_lot._get_warranty_exp_date(timestamp.date()), + (datetime.now() + timedelta(days=2)).date(), + ) diff --git a/stock_production_lot_warranty/views/stock_production_lot.xml b/stock_production_lot_warranty/views/stock_production_lot.xml new file mode 100644 index 000000000..3aaa2fa3e --- /dev/null +++ b/stock_production_lot_warranty/views/stock_production_lot.xml @@ -0,0 +1,14 @@ + + + + stock.lot + + + + + + + + + +