diff --git a/sale_order_restrict_copy_archived_product/README.rst b/sale_order_restrict_copy_archived_product/README.rst new file mode 100644 index 00000000000..914e300280a --- /dev/null +++ b/sale_order_restrict_copy_archived_product/README.rst @@ -0,0 +1,92 @@ +========================================= +Sale Order Restrict Copy Archived Product +========================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3cd98b90be3a1178cbf048b6ccf9544903d22571d9ceca4251d9a23cfee66b9e + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/15.0/sale_order_restrict_copy_archived_product + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-sale_order_restrict_copy_archived_product + :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/sale-workflow&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to restrict duplication of sales order if they +have archived products. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +1. Go to Sales / Orders +2. Select a Sale with archived products, or archive a product of a sale. +3. Click to the Action -> Duplicate button of the Sale Order form. A + validation error message will be displayed showing the archived + products. + +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 +------- + +* Sygel + +Contributors +------------ + +- `Sygel `__: + + - Alberto Martínez + - Valentin Vinagre + - Harald Panten + +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/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_order_restrict_copy_archived_product/__init__.py b/sale_order_restrict_copy_archived_product/__init__.py new file mode 100644 index 00000000000..31660d6a965 --- /dev/null +++ b/sale_order_restrict_copy_archived_product/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/sale_order_restrict_copy_archived_product/__manifest__.py b/sale_order_restrict_copy_archived_product/__manifest__.py new file mode 100644 index 00000000000..3fc605b82b4 --- /dev/null +++ b/sale_order_restrict_copy_archived_product/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2025 Alberto Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Sale Order Restrict Copy Archived Product", + "summary": "Restrict dulpication of sales order if they have archived products", + "version": "15.0.1.0.0", + "category": "Sales", + "website": "https://github.com/OCA/sale-workflow", + "author": "Sygel, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "sale", + ], +} diff --git a/sale_order_restrict_copy_archived_product/models/__init__.py b/sale_order_restrict_copy_archived_product/models/__init__.py new file mode 100644 index 00000000000..cbd69320b05 --- /dev/null +++ b/sale_order_restrict_copy_archived_product/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import sale_order diff --git a/sale_order_restrict_copy_archived_product/models/sale_order.py b/sale_order_restrict_copy_archived_product/models/sale_order.py new file mode 100644 index 00000000000..e54f70efd1d --- /dev/null +++ b/sale_order_restrict_copy_archived_product/models/sale_order.py @@ -0,0 +1,20 @@ +# Copyright 2025 Alberto Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, exceptions, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def copy(self, default=None): + archived_products = self.mapped("order_line.product_id").filtered( + lambda p: not p.active + ) + if archived_products: + raise exceptions.ValidationError( + _("You can't duplicate sale orders with archived products: {}").format( + ", ".join(archived_products.mapped("name")) + ) + ) + return super().copy(default) diff --git a/sale_order_restrict_copy_archived_product/readme/CONTRIBUTORS.md b/sale_order_restrict_copy_archived_product/readme/CONTRIBUTORS.md new file mode 100755 index 00000000000..f566245042c --- /dev/null +++ b/sale_order_restrict_copy_archived_product/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- [Sygel](https://www.sygel.es): + - Alberto Martínez + - Valentin Vinagre + - Harald Panten diff --git a/sale_order_restrict_copy_archived_product/readme/DESCRIPTION.md b/sale_order_restrict_copy_archived_product/readme/DESCRIPTION.md new file mode 100755 index 00000000000..2628106c2ad --- /dev/null +++ b/sale_order_restrict_copy_archived_product/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows you to restrict duplication of sales order if they have archived products. diff --git a/sale_order_restrict_copy_archived_product/readme/USAGE.md b/sale_order_restrict_copy_archived_product/readme/USAGE.md new file mode 100755 index 00000000000..c57b8c1ec32 --- /dev/null +++ b/sale_order_restrict_copy_archived_product/readme/USAGE.md @@ -0,0 +1,5 @@ +To use this module, you need to: + +1. Go to Sales / Orders +2. Select a Sale with archived products, or archive a product of a sale. +3. Click to the Action -> Duplicate button of the Sale Order form. A validation error message will be displayed showing the archived products. diff --git a/sale_order_restrict_copy_archived_product/static/description/icon.png b/sale_order_restrict_copy_archived_product/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_order_restrict_copy_archived_product/static/description/icon.png differ diff --git a/sale_order_restrict_copy_archived_product/static/description/icon.svg b/sale_order_restrict_copy_archived_product/static/description/icon.svg new file mode 100644 index 00000000000..a7a26d0932a --- /dev/null +++ b/sale_order_restrict_copy_archived_product/static/description/icon.svg @@ -0,0 +1,79 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/sale_order_restrict_copy_archived_product/static/description/index.html b/sale_order_restrict_copy_archived_product/static/description/index.html new file mode 100644 index 00000000000..1ea0bf90502 --- /dev/null +++ b/sale_order_restrict_copy_archived_product/static/description/index.html @@ -0,0 +1,441 @@ + + + + + +Sale Order Restrict Copy Archived Product + + + +
+

Sale Order Restrict Copy Archived Product

+ + +

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

+

This module allows you to restrict duplication of sales order if they +have archived products.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Sales / Orders
  2. +
  3. Select a Sale with archived products, or archive a product of a sale.
  4. +
  5. Click to the Action -> Duplicate button of the Sale Order form. A +validation error message will be displayed showing the archived +products.
  6. +
+
+
+

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

+
    +
  • Sygel
  • +
+
+
+

Contributors

+
    +
  • Sygel:
      +
    • Alberto Martínez
    • +
    • Valentin Vinagre
    • +
    • Harald Panten
    • +
    +
  • +
+
+
+

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/sale-workflow project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_order_restrict_copy_archived_product/tests/__init__.py b/sale_order_restrict_copy_archived_product/tests/__init__.py new file mode 100644 index 00000000000..1ac9e01cb01 --- /dev/null +++ b/sale_order_restrict_copy_archived_product/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_sale_order_restrict_copy_archived_product diff --git a/sale_order_restrict_copy_archived_product/tests/test_sale_order_restrict_copy_archived_product.py b/sale_order_restrict_copy_archived_product/tests/test_sale_order_restrict_copy_archived_product.py new file mode 100644 index 00000000000..6c73672510b --- /dev/null +++ b/sale_order_restrict_copy_archived_product/tests/test_sale_order_restrict_copy_archived_product.py @@ -0,0 +1,57 @@ +# Copyright 2025 Alberto Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import exceptions +from odoo.tests.common import TransactionCase + + +class TestSaleOrderRestrictCopyArchivedProduct(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create({"name": "Test Partner"}) + cls.product = cls.env["product.product"].create({"name": "Product"}) + cls.product_archived = cls.env["product.product"].create( + { + "name": "Product Archived", + "active": False, + } + ) + + def test_restriction(self): + sale = self.env["sale.order"].create( + { + "partner_id": self.partner.id, + "order_line": [ + ( + 0, + 0, + { + "product_id": self.product_archived.id, + "product_uom_qty": 1, + }, + ) + ], + } + ) + with self.assertRaises(exceptions.ValidationError): + sale.copy() + + def test_no_restriction(self): + sale = self.env["sale.order"].create( + { + "partner_id": self.partner.id, + "order_line": [ + ( + 0, + 0, + { + "product_id": self.product.id, + "product_uom_qty": 1, + }, + ) + ], + } + ) + sale2 = sale.copy() + self.assertTrue(sale2) diff --git a/setup/sale_order_restrict_copy_archived_product/odoo/addons/sale_order_restrict_copy_archived_product b/setup/sale_order_restrict_copy_archived_product/odoo/addons/sale_order_restrict_copy_archived_product new file mode 120000 index 00000000000..9ea85f1f3a7 --- /dev/null +++ b/setup/sale_order_restrict_copy_archived_product/odoo/addons/sale_order_restrict_copy_archived_product @@ -0,0 +1 @@ +../../../../sale_order_restrict_copy_archived_product \ No newline at end of file diff --git a/setup/sale_order_restrict_copy_archived_product/setup.py b/setup/sale_order_restrict_copy_archived_product/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/sale_order_restrict_copy_archived_product/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)