diff --git a/uom_qty_unique/README.rst b/uom_qty_unique/README.rst new file mode 100644 index 00000000000..7e28e79d9b5 --- /dev/null +++ b/uom_qty_unique/README.rst @@ -0,0 +1,108 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +============== +Uom Qty Unique +============== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:8fd16fdb3ce4847cf748fa065201313305051633632bc0499bf67e3a3ac04a89 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/uom_qty_unique + :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-19-0/product-attribute-19-0-uom_qty_unique + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to constraint users to have only one unit of measure +per category and per quantity. + +Indeed, this has been triggered by the fact users maybe identfied the +wrong category or need a new one to put their particular unit of +measure. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +- Create a unit of measure with a duplicate quantity factor and category +- An error should be raised. + +Changelog +========= + +14.0.1.0.0 (2022-09-30) +----------------------- + +- [ADD] uom_qty_unique + +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 +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Denis Roussel +- Raphaël Vicini + +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-rousseldenis| image:: https://github.com/rousseldenis.png?size=40px + :target: https://github.com/rousseldenis + :alt: rousseldenis + +Current `maintainer `__: + +|maintainer-rousseldenis| + +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/uom_qty_unique/__init__.py b/uom_qty_unique/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/uom_qty_unique/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/uom_qty_unique/__manifest__.py b/uom_qty_unique/__manifest__.py new file mode 100644 index 00000000000..d63b883a15a --- /dev/null +++ b/uom_qty_unique/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Uom Qty Unique", + "summary": """ + This constrains unit of measure per quantity and per category""", + "version": "19.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "maintainers": ["rousseldenis"], + "website": "https://github.com/OCA/product-attribute", + "depends": [ + "uom", + ], +} diff --git a/uom_qty_unique/models/__init__.py b/uom_qty_unique/models/__init__.py new file mode 100644 index 00000000000..7753e8e764e --- /dev/null +++ b/uom_qty_unique/models/__init__.py @@ -0,0 +1 @@ +from . import uom_uom diff --git a/uom_qty_unique/models/uom_uom.py b/uom_qty_unique/models/uom_uom.py new file mode 100644 index 00000000000..3dc9d806eb8 --- /dev/null +++ b/uom_qty_unique/models/uom_uom.py @@ -0,0 +1,13 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class UomUom(models.Model): + _inherit = "uom.uom" + + _uom_qty_category_unique = models.Constraint( + "EXCLUDE (factor WITH =, relative_uom_id WITH =) WHERE (active=True)", + "Only one active unit of measure per factor and per category should be active.", + ) diff --git a/uom_qty_unique/pyproject.toml b/uom_qty_unique/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/uom_qty_unique/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/uom_qty_unique/readme/CONTRIBUTORS.md b/uom_qty_unique/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..3031e399c75 --- /dev/null +++ b/uom_qty_unique/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Denis Roussel \ +- Raphaël Vicini \ diff --git a/uom_qty_unique/readme/DESCRIPTION.md b/uom_qty_unique/readme/DESCRIPTION.md new file mode 100644 index 00000000000..39a059cd927 --- /dev/null +++ b/uom_qty_unique/readme/DESCRIPTION.md @@ -0,0 +1,6 @@ +This module allows to constraint users to have only one unit of measure +per category and per quantity. + +Indeed, this has been triggered by the fact users maybe identfied the +wrong category or need a new one to put their particular unit of +measure. diff --git a/uom_qty_unique/readme/HISTORY.md b/uom_qty_unique/readme/HISTORY.md new file mode 100644 index 00000000000..c9a43abe761 --- /dev/null +++ b/uom_qty_unique/readme/HISTORY.md @@ -0,0 +1,3 @@ +## 14.0.1.0.0 (2022-09-30) + +- \[ADD\] uom_qty_unique diff --git a/uom_qty_unique/readme/USAGE.md b/uom_qty_unique/readme/USAGE.md new file mode 100644 index 00000000000..4638c9db894 --- /dev/null +++ b/uom_qty_unique/readme/USAGE.md @@ -0,0 +1,2 @@ +- Create a unit of measure with a duplicate quantity factor and category +- An error should be raised. diff --git a/uom_qty_unique/static/description/icon.png b/uom_qty_unique/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/uom_qty_unique/static/description/icon.png differ diff --git a/uom_qty_unique/static/description/index.html b/uom_qty_unique/static/description/index.html new file mode 100644 index 00000000000..72fbe5bc6ba --- /dev/null +++ b/uom_qty_unique/static/description/index.html @@ -0,0 +1,457 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Uom Qty Unique

+ +

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

+

This module allows to constraint users to have only one unit of measure +per category and per quantity.

+

Indeed, this has been triggered by the fact users maybe identfied the +wrong category or need a new one to put their particular unit of +measure.

+

Table of contents

+ +
+

Usage

+
    +
  • Create a unit of measure with a duplicate quantity factor and category
  • +
  • An error should be raised.
  • +
+
+
+

Changelog

+
+

14.0.1.0.0 (2022-09-30)

+
    +
  • [ADD] uom_qty_unique
  • +
+
+
+
+

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

+
    +
  • ACSONE SA/NV
  • +
+
+
+

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.

+

Current maintainer:

+

rousseldenis

+

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/uom_qty_unique/tests/__init__.py b/uom_qty_unique/tests/__init__.py new file mode 100644 index 00000000000..28d7d0d6768 --- /dev/null +++ b/uom_qty_unique/tests/__init__.py @@ -0,0 +1 @@ +from . import test_uom_qty diff --git a/uom_qty_unique/tests/test_uom_qty.py b/uom_qty_unique/tests/test_uom_qty.py new file mode 100644 index 00000000000..e912a6ff750 --- /dev/null +++ b/uom_qty_unique/tests/test_uom_qty.py @@ -0,0 +1,39 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from psycopg2 import IntegrityError + +from odoo.tests.common import TransactionCase +from odoo.tools.misc import mute_logger + + +class TestUomQtyUnique(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.unit = cls.env.ref("uom.product_uom_unit") + cls.uom_dozen = cls.env.ref("uom.product_uom_dozen") + cls.uom_dozen.active = True + + @mute_logger("odoo.sql_db") + def test_uom_qty_unique(self): + # Create a duplicate unit of measure + with self.assertRaises(IntegrityError): + self.env["uom.uom"].create( + { + "name": "Dozen", + "relative_factor": 12.0, + "relative_uom_id": self.unit.id, + } + ) + + def test_uom_qty_unique_archived(self): + # Archive the dozen unit of measure + self.uom_dozen.active = False + self.env["uom.uom"].create( + { + "name": "Dozen", + "relative_factor": 12.0, + "relative_uom_id": self.unit.id, + } + )