diff --git a/sale_margin_security/README.rst b/sale_margin_security/README.rst new file mode 100644 index 000000000..83ccaa1fe --- /dev/null +++ b/sale_margin_security/README.rst @@ -0,0 +1,136 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +==================== +Sale Margin Security +==================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5e042c29af38692b886729dbcb19d7cbac25fbd5ea157584e306d9f5c70cbcb1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |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%2Fmargin--analysis-lightgray.png?logo=github + :target: https://github.com/OCA/margin-analysis/tree/19.0/sale_margin_security + :alt: OCA/margin-analysis +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/margin-analysis-19-0/margin-analysis-19-0-sale_margin_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/margin-analysis&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module lets you limit who can see or edit sale margin data within +sale orders. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +This module was developed because in some companies, salespersons +shouldn't be able to see the product cost or their sale margin. + +Installation +============ + +This module will be auto-installed if these others are installed too: + +- ``product_cost_security`` from + `OCA/product-attribute `__. +- ``sale_margin`` from Odoo CE. + +Configuration +============= + +Follow configuration instructions for module ``product_cost_security``. + +Usage +===== + +Afterwards configuring, the product cost security rules will be applied +to sale orders. Only authorized users will be able to see or edit sale +margin and product cost data from within sale orders. + +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 `__ + + - Sergio Teruel + - David Vidal + - Carlos Roca + - Carlos Lopez + +- `Moduon `__ + + - Rafael Blasco + - Jairo Llopis + +- `Open Source Integrators `__ + + - Daniel Reis + +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-sergio-teruel| image:: https://github.com/sergio-teruel.png?size=40px + :target: https://github.com/sergio-teruel + :alt: sergio-teruel +.. |maintainer-rafaelbn| image:: https://github.com/rafaelbn.png?size=40px + :target: https://github.com/rafaelbn + :alt: rafaelbn +.. |maintainer-yajo| image:: https://github.com/yajo.png?size=40px + :target: https://github.com/yajo + :alt: yajo + +Current `maintainers `__: + +|maintainer-sergio-teruel| |maintainer-rafaelbn| |maintainer-yajo| + +This module is part of the `OCA/margin-analysis `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_margin_security/__init__.py b/sale_margin_security/__init__.py new file mode 100644 index 000000000..bf588bc8b --- /dev/null +++ b/sale_margin_security/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import report diff --git a/sale_margin_security/__manifest__.py b/sale_margin_security/__manifest__.py new file mode 100644 index 000000000..613a8a016 --- /dev/null +++ b/sale_margin_security/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2018 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Sale Margin Security", + "version": "19.0.1.0.0", + "author": "Tecnativa,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/margin-analysis", + "category": "Sales", + "license": "AGPL-3", + "development_status": "Production/Stable", + "maintainers": ["sergio-teruel", "rafaelbn", "yajo"], + "depends": ["sale_margin", "product_cost_security"], + "data": [ + "views/sale_margin_security_view.xml", + ], + "auto_install": True, +} diff --git a/sale_margin_security/i18n/es.po b/sale_margin_security/i18n/es.po new file mode 100644 index 000000000..b2f4a7a10 --- /dev/null +++ b/sale_margin_security/i18n/es.po @@ -0,0 +1,60 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_margin_security +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-29 12:35+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\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" +"X-Generator: Weblate 4.17\n" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__purchase_price +msgid "Cost" +msgstr "Coste" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order__margin +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__margin +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_report__margin +msgid "Margin" +msgstr "Margen" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order__margin_percent +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__margin_percent +msgid "Margin (%)" +msgstr "Margen (%)" + +#. module: sale_margin_security +#: model:ir.model,name:sale_margin_security.model_sale_report +msgid "Sales Analysis Report" +msgstr "Informe de análisis de ventas" + +#. module: sale_margin_security +#: model:ir.model,name:sale_margin_security.model_sale_order +msgid "Sales Order" +msgstr "Orden de Venta" + +#. module: sale_margin_security +#: model:ir.model,name:sale_margin_security.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línea de pedido de venta" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order__user_can_update_cost +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__user_can_update_cost +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_report__user_can_update_cost +msgid "User Can Update Cost" +msgstr "" + +#~ msgid "Show Sale Margin" +#~ msgstr "Mostrar Margen de Venta" diff --git a/sale_margin_security/i18n/it.po b/sale_margin_security/i18n/it.po new file mode 100644 index 000000000..fd0e6f9d8 --- /dev/null +++ b/sale_margin_security/i18n/it.po @@ -0,0 +1,60 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_margin_security +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-04-08 08:37+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: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__purchase_price +msgid "Cost" +msgstr "Costo" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order__margin +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__margin +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_report__margin +msgid "Margin" +msgstr "Margine" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order__margin_percent +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__margin_percent +msgid "Margin (%)" +msgstr "Margine (%)" + +#. module: sale_margin_security +#: model:ir.model,name:sale_margin_security.model_sale_report +msgid "Sales Analysis Report" +msgstr "Resoconto analisi vendite" + +#. module: sale_margin_security +#: model:ir.model,name:sale_margin_security.model_sale_order +msgid "Sales Order" +msgstr "Ordine di vendita" + +#. module: sale_margin_security +#: model:ir.model,name:sale_margin_security.model_sale_order_line +msgid "Sales Order Line" +msgstr "Riga ordine di vendita" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order__user_can_update_cost +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__user_can_update_cost +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_report__user_can_update_cost +msgid "User Can Update Cost" +msgstr "L'utente può aggiornare il costo" + +#~ msgid "Show Sale Margin" +#~ msgstr "Visualizza margine vendita" diff --git a/sale_margin_security/i18n/sale_margin_security.pot b/sale_margin_security/i18n/sale_margin_security.pot new file mode 100644 index 000000000..1c5c7a71f --- /dev/null +++ b/sale_margin_security/i18n/sale_margin_security.pot @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_margin_security +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.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: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__purchase_price +msgid "Cost" +msgstr "" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order__margin +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__margin +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_report__margin +msgid "Margin" +msgstr "" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order__margin_percent +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__margin_percent +msgid "Margin (%)" +msgstr "" + +#. module: sale_margin_security +#: model:ir.model,name:sale_margin_security.model_sale_report +msgid "Sales Analysis Report" +msgstr "" + +#. module: sale_margin_security +#: model:ir.model,name:sale_margin_security.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: sale_margin_security +#: model:ir.model,name:sale_margin_security.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order__user_can_update_cost +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__user_can_update_cost +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_report__user_can_update_cost +msgid "User Can Update Cost" +msgstr "" diff --git a/sale_margin_security/i18n/tr.po b/sale_margin_security/i18n/tr.po new file mode 100644 index 000000000..c12bfd40f --- /dev/null +++ b/sale_margin_security/i18n/tr.po @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_margin_security +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-05-08 14:23+0000\n" +"Last-Translator: Betül Öğmen \n" +"Language-Team: none\n" +"Language: tr\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 5.10.4\n" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__purchase_price +msgid "Cost" +msgstr "Maliyet" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order__margin +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__margin +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_report__margin +msgid "Margin" +msgstr "Marj" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order__margin_percent +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__margin_percent +msgid "Margin (%)" +msgstr "Marj (%)" + +#. module: sale_margin_security +#: model:ir.model,name:sale_margin_security.model_sale_report +msgid "Sales Analysis Report" +msgstr "Satış Analizi Raporu" + +#. module: sale_margin_security +#: model:ir.model,name:sale_margin_security.model_sale_order +msgid "Sales Order" +msgstr "Satış Siparişi" + +#. module: sale_margin_security +#: model:ir.model,name:sale_margin_security.model_sale_order_line +msgid "Sales Order Line" +msgstr "Satış Sipariş Satırı" + +#. module: sale_margin_security +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order__user_can_update_cost +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_order_line__user_can_update_cost +#: model:ir.model.fields,field_description:sale_margin_security.field_sale_report__user_can_update_cost +msgid "User Can Update Cost" +msgstr "Maliyeti Güncelleyebilen Kullanıcı" diff --git a/sale_margin_security/models/__init__.py b/sale_margin_security/models/__init__.py new file mode 100644 index 000000000..6aacb7531 --- /dev/null +++ b/sale_margin_security/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order diff --git a/sale_margin_security/models/sale_order.py b/sale_margin_security/models/sale_order.py new file mode 100644 index 000000000..a81ce704f --- /dev/null +++ b/sale_margin_security/models/sale_order.py @@ -0,0 +1,21 @@ +# Copyright 2023 Carlos Dauden - Tecnativa +# Copyright 2023 Sergio Teruel - Tecnativa +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class SaleOrder(models.Model): + _name = "sale.order" + _inherit = ["sale.order", "product.cost.security.mixin"] + + margin = fields.Monetary(groups="product_cost_security.group_product_cost") + margin_percent = fields.Float(groups="product_cost_security.group_product_cost") + + +class SaleOrderLine(models.Model): + _name = "sale.order.line" + _inherit = ["sale.order.line", "product.cost.security.mixin"] + + margin = fields.Float(groups="product_cost_security.group_product_cost") + margin_percent = fields.Float(groups="product_cost_security.group_product_cost") + purchase_price = fields.Float(groups="product_cost_security.group_product_cost") diff --git a/sale_margin_security/pyproject.toml b/sale_margin_security/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/sale_margin_security/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_margin_security/readme/CONFIGURE.md b/sale_margin_security/readme/CONFIGURE.md new file mode 100644 index 000000000..e5352d011 --- /dev/null +++ b/sale_margin_security/readme/CONFIGURE.md @@ -0,0 +1 @@ +Follow configuration instructions for module `product_cost_security`. diff --git a/sale_margin_security/readme/CONTEXT.md b/sale_margin_security/readme/CONTEXT.md new file mode 100644 index 000000000..1eab533cc --- /dev/null +++ b/sale_margin_security/readme/CONTEXT.md @@ -0,0 +1,2 @@ +This module was developed because in some companies, salespersons +shouldn't be able to see the product cost or their sale margin. diff --git a/sale_margin_security/readme/CONTRIBUTORS.md b/sale_margin_security/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..7c7a2bb85 --- /dev/null +++ b/sale_margin_security/readme/CONTRIBUTORS.md @@ -0,0 +1,10 @@ +- [Tecnativa](https://www.tecnativa.com) + - Sergio Teruel + - David Vidal + - Carlos Roca + - Carlos Lopez +- [Moduon](https://www.moduon.team) + - Rafael Blasco + - Jairo Llopis +- [Open Source Integrators](https://www.opensourceintegrators.com) + - Daniel Reis diff --git a/sale_margin_security/readme/DESCRIPTION.md b/sale_margin_security/readme/DESCRIPTION.md new file mode 100644 index 000000000..a18c8e81c --- /dev/null +++ b/sale_margin_security/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module lets you limit who can see or edit sale margin data within +sale orders. diff --git a/sale_margin_security/readme/INSTALL.md b/sale_margin_security/readme/INSTALL.md new file mode 100644 index 000000000..75be253e8 --- /dev/null +++ b/sale_margin_security/readme/INSTALL.md @@ -0,0 +1,5 @@ +This module will be auto-installed if these others are installed too: + +- `product_cost_security` from + [OCA/product-attribute](https://github.com/OCA/product-attribute). +- `sale_margin` from Odoo CE. diff --git a/sale_margin_security/readme/USAGE.md b/sale_margin_security/readme/USAGE.md new file mode 100644 index 000000000..6a7cde969 --- /dev/null +++ b/sale_margin_security/readme/USAGE.md @@ -0,0 +1,3 @@ +Afterwards configuring, the product cost security rules will be applied +to sale orders. Only authorized users will be able to see or edit sale +margin and product cost data from within sale orders. diff --git a/sale_margin_security/report/__init__.py b/sale_margin_security/report/__init__.py new file mode 100644 index 000000000..cd23411b8 --- /dev/null +++ b/sale_margin_security/report/__init__.py @@ -0,0 +1 @@ +from . import sale_report diff --git a/sale_margin_security/report/sale_report.py b/sale_margin_security/report/sale_report.py new file mode 100644 index 000000000..5aa7ea19b --- /dev/null +++ b/sale_margin_security/report/sale_report.py @@ -0,0 +1,11 @@ +# Copyright 2023 Carlos Dauden - Tecnativa +# Copyright 2023 Sergio Teruel - Tecnativa +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class SaleReport(models.Model): + _name = "sale.report" + _inherit = ["sale.report", "product.cost.security.mixin"] + + margin = fields.Float(groups="product_cost_security.group_product_cost") diff --git a/sale_margin_security/static/description/icon.png b/sale_margin_security/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/sale_margin_security/static/description/icon.png differ diff --git a/sale_margin_security/static/description/index.html b/sale_margin_security/static/description/index.html new file mode 100644 index 000000000..b9d49b6c3 --- /dev/null +++ b/sale_margin_security/static/description/index.html @@ -0,0 +1,475 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Sale Margin Security

+ +

Production/Stable License: AGPL-3 OCA/margin-analysis Translate me on Weblate Try me on Runboat

+

This module lets you limit who can see or edit sale margin data within +sale orders.

+

Table of contents

+ +
+

Use Cases / Context

+

This module was developed because in some companies, salespersons +shouldn’t be able to see the product cost or their sale margin.

+
+
+

Installation

+

This module will be auto-installed if these others are installed too:

+ +
+
+

Configuration

+

Follow configuration instructions for module product_cost_security.

+
+
+

Usage

+

Afterwards configuring, the product cost security rules will be applied +to sale orders. Only authorized users will be able to see or edit sale +margin and product cost data from within sale orders.

+
+
+

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.

+

Current maintainers:

+

sergio-teruel rafaelbn yajo

+

This module is part of the OCA/margin-analysis project on GitHub.

+

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

+
+
+
+
+ + diff --git a/sale_margin_security/tests/__init__.py b/sale_margin_security/tests/__init__.py new file mode 100644 index 000000000..9d446773f --- /dev/null +++ b/sale_margin_security/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_margin diff --git a/sale_margin_security/tests/test_sale_margin.py b/sale_margin_security/tests/test_sale_margin.py new file mode 100644 index 000000000..57a522ad2 --- /dev/null +++ b/sale_margin_security/tests/test_sale_margin.py @@ -0,0 +1,102 @@ +# Copyright 2024 Moduon Team S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) +from odoo.exceptions import AccessError +from odoo.tests import Form +from odoo.tests.common import new_test_user +from odoo.tools import mute_logger + +from odoo.addons.sale.tests.common import SaleCommon + + +class SomethingCase(SaleCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product.standard_price = 10 + cls.salesperson_edit = new_test_user( + cls.env, + name="Salesperson PC Edit", + login="salesperson_edit", + groups=( + "sales_team.group_sale_salesman," + "product_cost_security.group_product_edit_cost" + ), + ) + cls.salesperson_read = new_test_user( + cls.env, + name="Salesperson PC Read", + login="salesperson_read", + groups="sales_team.group_sale_salesman,product_cost_security.group_product_cost", + ) + cls.salesperson_none = new_test_user( + cls.env, + name="Salesperson PC None", + login="salesperson_none", + groups="sales_team.group_sale_salesman", + ) + + def test_rw_margin_access(self): + """Unauthorized users cannot see margin data.""" + self.empty_order.user_id = self.salesperson_edit + so = self.empty_order.with_user(self.salesperson_edit) + with Form(so) as order_f: + # Lines contain margin fields + with order_f.order_line.new() as line_f: + line_f.product_id = self.product + self.assertEqual(line_f.purchase_price, 10) + self.assertEqual(line_f.margin, 10) + self.assertEqual(line_f.margin_percent, 0.5) + # Editor can change purchase price + line_f.purchase_price = 15 + self.assertEqual(line_f.margin, 5) + self.assertEqual(line_f.margin_percent, 0.25) + # View contains margin fields, which are computed and readonly upstream + self.assertEqual(order_f.margin, 5) + self.assertEqual(order_f.margin_percent, 0.25) + # Can read those fields trough the API + so.read(["margin", "margin_percent"]) + so.order_line.read(["purchase_price", "margin", "margin_percent"]) + + def test_ro_margin_access(self): + """Unauthorized users cannot see margin data.""" + self.empty_order.user_id = self.salesperson_read + so = self.empty_order.with_user(self.salesperson_read) + with Form(so) as order_f: + # Lines contain margin fields + with order_f.order_line.new() as line_f: + line_f.product_id = self.product + line_f.product_uom_qty = 1 + self.assertEqual(line_f.purchase_price, 10) + self.assertEqual(line_f.margin, 10) + self.assertEqual(line_f.margin_percent, 0.5) + # Editor cannot change purchase price + with self.assertRaises(AssertionError): + line_f.purchase_price = 10 + # View contains margin fields, which are computed and readonly upstream + self.assertEqual(order_f.margin, 10) + self.assertEqual(order_f.margin_percent, 0.5) + # Can read those fields trough the API + so.read(["margin", "margin_percent"]) + so.order_line.read(["purchase_price", "margin", "margin_percent"]) + + @mute_logger("odoo.models") + def test_no_margin_access(self): + """Unauthorized users cannot see margin data.""" + self.empty_order.user_id = self.salesperson_none + so = self.empty_order.with_user(self.salesperson_none) + with Form(so) as order_f: + # View doesn't contain margin fields + self.assertRaises(AssertionError, hasattr, order_f, "margin") + self.assertRaises(AssertionError, hasattr, order_f, "margin_percent") + # Lines don't contain margin fields + with order_f.order_line.new() as line_f: + line_f.product_id = self.product + self.assertRaises(AssertionError, hasattr, line_f, "purchase_price") + self.assertRaises(AssertionError, hasattr, line_f, "margin") + self.assertRaises(AssertionError, hasattr, line_f, "margin_percent") + # This user cannot read those fields trough the API + self.assertRaises(AccessError, so.read, ["margin"]) + self.assertRaises(AccessError, so.read, ["margin_percent"]) + self.assertRaises(AccessError, so.order_line.read, ["purchase_price"]) + self.assertRaises(AccessError, so.order_line.read, ["margin"]) + self.assertRaises(AccessError, so.order_line.read, ["margin_percent"]) diff --git a/sale_margin_security/views/sale_margin_security_view.xml b/sale_margin_security/views/sale_margin_security_view.xml new file mode 100644 index 000000000..4abf66e90 --- /dev/null +++ b/sale_margin_security/views/sale_margin_security_view.xml @@ -0,0 +1,17 @@ + + + + + sale.order.form + sale.order + + + + product_cost_security.group_product_cost + + + +