diff --git a/pos_product_cost_security/README.rst b/pos_product_cost_security/README.rst new file mode 100644 index 00000000000..238ca89a5b8 --- /dev/null +++ b/pos_product_cost_security/README.rst @@ -0,0 +1,84 @@ +========================= +PoS Product Cost Security +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:c15b3fb7b7abfd380a0bebcec9cb5683ea92ba1f822515e4b7e917a82aca9923 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.0/pos_product_cost_security + :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-18-0/product-attribute-18-0-pos_product_cost_security + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This is a glue module to avoid permission errors when loading data in +the Point of Sale if the user has no ``standard_price`` (cost) field +permissions. + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - David Vidal + +- `SerpentCS `__: + + - Parvez Qureshi + +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/pos_product_cost_security/__init__.py b/pos_product_cost_security/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/pos_product_cost_security/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_product_cost_security/__manifest__.py b/pos_product_cost_security/__manifest__.py new file mode 100644 index 00000000000..46e27f471e6 --- /dev/null +++ b/pos_product_cost_security/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "PoS Product Cost Security", + "summary": "Compatibility between Point of Sale and Product Cost Security", + "version": "18.0.1.0.0", + "category": "Product", + "website": "https://github.com/OCA/product-attribute", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "depends": ["product_cost_security", "point_of_sale"], +} diff --git a/pos_product_cost_security/i18n/it.po b/pos_product_cost_security/i18n/it.po new file mode 100644 index 00000000000..51fd18af4bc --- /dev/null +++ b/pos_product_cost_security/i18n/it.po @@ -0,0 +1,39 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_product_cost_security +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-06-24 14:38+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: pos_product_cost_security +#: model:ir.model,name:pos_product_cost_security.model_pos_session +msgid "Point of Sale Session" +msgstr "Sessione punto vendita" + +#. module: pos_product_cost_security +#: model:ir.model,name:pos_product_cost_security.model_product_product +msgid "Product Variant" +msgstr "Variante prodotto" + +#~ msgid "Display Name" +#~ msgstr "Nome visualizzato" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Ultima modifica il" + +#~ msgid "Product" +#~ msgstr "Prodotto" diff --git a/pos_product_cost_security/i18n/pos_product_cost_security.pot b/pos_product_cost_security/i18n/pos_product_cost_security.pot new file mode 100644 index 00000000000..de5e9c20b5f --- /dev/null +++ b/pos_product_cost_security/i18n/pos_product_cost_security.pot @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_product_cost_security +# +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: pos_product_cost_security +#: model:ir.model,name:pos_product_cost_security.model_pos_session +msgid "Point of Sale Session" +msgstr "" + +#. module: pos_product_cost_security +#: model:ir.model,name:pos_product_cost_security.model_product_product +msgid "Product Variant" +msgstr "" diff --git a/pos_product_cost_security/models/__init__.py b/pos_product_cost_security/models/__init__.py new file mode 100644 index 00000000000..2e59e489950 --- /dev/null +++ b/pos_product_cost_security/models/__init__.py @@ -0,0 +1,2 @@ +from . import pos_load_mixin +from . import product_product diff --git a/pos_product_cost_security/models/pos_load_mixin.py b/pos_product_cost_security/models/pos_load_mixin.py new file mode 100644 index 00000000000..35a374ea277 --- /dev/null +++ b/pos_product_cost_security/models/pos_load_mixin.py @@ -0,0 +1,16 @@ +from odoo import api, models + + +class PosLoadMixin(models.AbstractModel): + _inherit = "pos.load.mixin" + + @api.model + def with_user(self, user): + ctx = dict(self.env.context) + ctx["pos_override_cost_security"] = True + return super().with_user(user).with_context(**ctx) + + def with_env(self, env): + ctx = dict(env.context) + ctx["pos_override_cost_security"] = True + return super().with_env(env(context=ctx)) diff --git a/pos_product_cost_security/models/product_product.py b/pos_product_cost_security/models/product_product.py new file mode 100644 index 00000000000..4236afc1967 --- /dev/null +++ b/pos_product_cost_security/models/product_product.py @@ -0,0 +1,20 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + def check_field_access_rights(self, operation, fields): + override_cost_security = ( + self.env.context.get("pos_override_cost_security") + and self.env.user.has_group("point_of_sale.group_pos_user") + and not self.env.user.has_group("product_cost_security.group_product_cost") + and "standard_price" in fields + ) + if override_cost_security: + return super(ProductProduct, self.sudo()).check_field_access_rights( + operation, fields + ) + return super().check_field_access_rights(operation, fields) diff --git a/pos_product_cost_security/pyproject.toml b/pos_product_cost_security/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/pos_product_cost_security/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/pos_product_cost_security/readme/CONTRIBUTORS.md b/pos_product_cost_security/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..07bbff4f8ca --- /dev/null +++ b/pos_product_cost_security/readme/CONTRIBUTORS.md @@ -0,0 +1,6 @@ +- [Tecnativa](https://www.tecnativa.com): + - David Vidal + +- [SerpentCS](https://www.serpentcs.com): + - Parvez Qureshi \<\> + diff --git a/pos_product_cost_security/readme/DESCRIPTION.md b/pos_product_cost_security/readme/DESCRIPTION.md new file mode 100644 index 00000000000..c974bf7d3ff --- /dev/null +++ b/pos_product_cost_security/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This is a glue module to avoid permission errors when loading data in +the Point of Sale if the user has no `standard_price` (cost) field +permissions. diff --git a/pos_product_cost_security/static/description/icon.png b/pos_product_cost_security/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/pos_product_cost_security/static/description/icon.png differ diff --git a/pos_product_cost_security/static/description/index.html b/pos_product_cost_security/static/description/index.html new file mode 100644 index 00000000000..947c1bcf576 --- /dev/null +++ b/pos_product_cost_security/static/description/index.html @@ -0,0 +1,432 @@ + + + + + +PoS Product Cost Security + + + +
+

PoS Product Cost Security

+ + +

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

+

This is a glue module to avoid permission errors when loading data in +the Point of Sale if the user has no standard_price (cost) field +permissions.

+

Table of contents

+ +
+

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

+
    +
  • Tecnativa
  • +
+
+
+

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/pos_product_cost_security/tests/__init__.py b/pos_product_cost_security/tests/__init__.py new file mode 100644 index 00000000000..63437a3f41b --- /dev/null +++ b/pos_product_cost_security/tests/__init__.py @@ -0,0 +1 @@ +from . import test_pos_product_cost diff --git a/pos_product_cost_security/tests/test_pos_product_cost.py b/pos_product_cost_security/tests/test_pos_product_cost.py new file mode 100644 index 00000000000..f6c9ec8969f --- /dev/null +++ b/pos_product_cost_security/tests/test_pos_product_cost.py @@ -0,0 +1,47 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo.tests import tagged, users + +from odoo.addons.point_of_sale.tests.common import TestPointOfSaleCommon, TestPoSCommon + + +@tagged("post_install", "-at_install") +class TestPosProductCostSecurity(TestPointOfSaleCommon, TestPoSCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.config = cls.basic_config + cls.product = cls.env.ref("product.product_product_3") + + def _read_product(self, context_values, fields=None): + """Read product with given context and fields""" + if fields is None: + fields = ["name", "standard_price"] + return ( + self.env["product.product"] + .with_context(**context_values) + .browse(self.product.id) + .read(fields) + ) + + @users("demo") + def test_pos_session_open_and_override_loader_params(self): + product_data = self._read_product({"pos_override_cost_security": True}) + self.assertIn("standard_price", product_data[0]) + + @users("demo") + def test_read_with_override_context(self): + """User with override should see standard_price""" + product_data = self._read_product({"pos_override_cost_security": True}) + + self.assertIn("name", product_data[0]) + self.assertIn( + "standard_price", + product_data[0], + "Standard price should be visible with override", + ) + self.assertEqual( + product_data[0]["standard_price"], + self.env["product.product"].browse(self.product.id).sudo().standard_price, + "Standard price should match the product cost", + )