diff --git a/pos_user_restriction/README.rst b/pos_user_restriction/README.rst new file mode 100644 index 0000000000..b66f329a07 --- /dev/null +++ b/pos_user_restriction/README.rst @@ -0,0 +1,106 @@ +============================== +Point of Sale - Restrict users +============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:a649088e7d710b708f47d708db73c717872871b9fbc7087a4031803b91f046c8 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github + :target: https://github.com/OCA/pos/tree/17.0/pos_user_restriction + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-17-0/pos-17-0-pos_user_restriction + :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/pos&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Restrict some users to only access their assigned points of sale. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +With a POS Manager, open a point of sale configration (pos.config) and +set "Assigned users" field. + +Then, assign "User: Assigned POS Only" group to users who should be able +to access to their assigned points of sale only. + +Allowed Employees Then assign "Authorized Employees" employee the same +user "Assigned POS Only" Use employee credentials to log in to the PoS +session and switch cashier. + +Known issues / Roadmap +====================== + +This module alone is not compatible with pos_cache; you need to install +a bridge module like +https://github.com/OCA/pos/tree/12.0/pos_cache_user_restriction for it +to work. + +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 +------- + +* TAKOBI + +Contributors +------------ + +- Lorenzo Battistini (https://takobi.online) +- Helly kapatel + +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-eLBati| image:: https://github.com/eLBati.png?size=40px + :target: https://github.com/eLBati + :alt: eLBati + +Current `maintainer `__: + +|maintainer-eLBati| + +This module is part of the `OCA/pos `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_user_restriction/__init__.py b/pos_user_restriction/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_user_restriction/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_user_restriction/__manifest__.py b/pos_user_restriction/__manifest__.py new file mode 100644 index 0000000000..101f537223 --- /dev/null +++ b/pos_user_restriction/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2020 Lorenzo Battistini @ TAKOBI +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). +{ + "name": "Point of Sale - Restrict users", + "summary": "Restrict some users to see and use only certain points of sale", + "version": "17.0.1.0.0", + "development_status": "Beta", + "category": "Point of Sale", + "website": "https://github.com/OCA/pos", + "author": "TAKOBI, Odoo Community Association (OCA)", + "maintainers": ["eLBati"], + "license": "LGPL-3", + "application": False, + "installable": True, + "depends": [ + "point_of_sale", + ], + "data": [ + "security/pos_security.xml", + "security/ir.model.access.csv", + "views/pos_config_views.xml", + "views/point_of_sale_views.xml", + ], +} diff --git a/pos_user_restriction/i18n/es.po b/pos_user_restriction/i18n/es.po new file mode 100644 index 0000000000..7c9f5b5957 --- /dev/null +++ b/pos_user_restriction/i18n/es.po @@ -0,0 +1,87 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_user_restriction +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-15 20:36+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: pos_user_restriction +#: model:ir.model.fields,field_description:pos_user_restriction.field_pos_config__assigned_user_ids +msgid "Assigned users" +msgstr "Usuarios asignados" + +#. module: pos_user_restriction +#: model:ir.model,name:pos_user_restriction.model_pos_config +msgid "Point of Sale Configuration" +msgstr "Configuración del punto de venta" + +#. module: pos_user_restriction +#: model:ir.model,name:pos_user_restriction.model_pos_session +msgid "Point of Sale Session" +msgstr "Sesión del Punto de Venta" + +#. module: pos_user_restriction +#: model:ir.model.fields,field_description:pos_user_restriction.field_pos_config__group_pos_user_id +msgid "Point of Sale User Group" +msgstr "Grupo de Usuarios de Puntos de Venta" + +#. module: pos_user_restriction +#: model_terms:ir.ui.view,arch_db:pos_user_restriction.pos_config_view_form_users +msgid "" +"Restrict some users to only access their assigned points of sale. In order " +"to apply the restriction, the user needs the 'User: Assigned POS Only' group" +msgstr "" +"Restrinja a algunos usuarios para que solo accedan a sus puntos de venta " +"asignados. Para aplicar la restricción, el usuario necesita el grupo " +"'Usuario: PdV asignado solo'" + +#. module: pos_user_restriction +#: model:ir.model.fields,help:pos_user_restriction.field_pos_config__assigned_user_ids +msgid "" +"Restrict some users to only access their assigned points of sale.In order to " +"apply the restriction, the user needs the 'User: Assigned POS Only' group" +msgstr "" +"Restringir a algunos usuarios el acceso únicamente a los puntos de venta que " +"tienen asignados. Para aplicar la restricción, el usuario necesita el grupo " +"\"Usuario: Sólo puntos de venta asignados\"" + +#. module: pos_user_restriction +#: model:res.groups,comment:pos_user_restriction.group_assigned_points_of_sale_user +msgid "The user will have access to her assigned points of sale." +msgstr "El usuario tendrá acceso a sus puntos de venta asignados." + +#. module: pos_user_restriction +#: model:ir.model.fields,help:pos_user_restriction.field_pos_config__group_pos_user_id +msgid "" +"This field is there to passthe id of the pos user group to the point of sale " +"client." +msgstr "" +"Este campo sirve para pasar el id del grupo de usuarios pos al cliente del " +"punto de venta." + +#. module: pos_user_restriction +#: model:res.groups,name:pos_user_restriction.group_assigned_points_of_sale_user +msgid "User: Assigned POS Only" +msgstr "Usuario: Solo PdV asignado" + +#. module: pos_user_restriction +#: model:ir.model,name:pos_user_restriction.model_res_users +#: model_terms:ir.ui.view,arch_db:pos_user_restriction.pos_config_view_form_users +msgid "Users" +msgstr "Usuarios" + +#. module: pos_user_restriction +#: model_terms:ir.ui.view,arch_db:pos_user_restriction.pos_config_view_form_users +msgid "Users assigned to this point of sale" +msgstr "Usuarios asignados a este punto de venta" diff --git a/pos_user_restriction/i18n/it.po b/pos_user_restriction/i18n/it.po new file mode 100644 index 0000000000..fcc8cf1a4e --- /dev/null +++ b/pos_user_restriction/i18n/it.po @@ -0,0 +1,88 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_user_restriction +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-07-07 04:49+0000\n" +"PO-Revision-Date: 2023-10-13 15:36+0000\n" +"Last-Translator: mymage \n" +"Language-Team: \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_user_restriction +#: model:ir.model.fields,field_description:pos_user_restriction.field_pos_config__assigned_user_ids +msgid "Assigned users" +msgstr "Utenti assegnati" + +#. module: pos_user_restriction +#: model:ir.model,name:pos_user_restriction.model_pos_config +msgid "Point of Sale Configuration" +msgstr "Configurazione punto vendita" + +#. module: pos_user_restriction +#: model:ir.model,name:pos_user_restriction.model_pos_session +msgid "Point of Sale Session" +msgstr "Sessione punto vendita" + +#. module: pos_user_restriction +#: model:ir.model.fields,field_description:pos_user_restriction.field_pos_config__group_pos_user_id +msgid "Point of Sale User Group" +msgstr "Gruppo utente punto vendita" + +#. module: pos_user_restriction +#: model_terms:ir.ui.view,arch_db:pos_user_restriction.pos_config_view_form_users +msgid "" +"Restrict some users to only access their assigned points of sale. In order " +"to apply the restriction, the user needs the 'User: Assigned POS Only' group" +msgstr "" +"Limitare alcuni utenti ad accedere solamente ai loro punti vendita " +"assegnati. Per applicare la restrizione, l'utente necessita il gruppo " +"'Utente: solamente POS assegnati'" + +#. module: pos_user_restriction +#: model:ir.model.fields,help:pos_user_restriction.field_pos_config__assigned_user_ids +msgid "" +"Restrict some users to only access their assigned points of sale.In order to " +"apply the restriction, the user needs the 'User: Assigned POS Only' group" +msgstr "" +"Limitare alcuni utenti ad accedere solamente ai loro punti vendita " +"assegnati. Per applicare la restrizione, l'utente necessita il gruppo " +"'Utente: solamente POS assegnati'" + +#. module: pos_user_restriction +#: model:res.groups,comment:pos_user_restriction.group_assigned_points_of_sale_user +msgid "The user will have access to her assigned points of sale." +msgstr "L'utente avrà accesso ai propri punti vendita assegnati." + +#. module: pos_user_restriction +#: model:ir.model.fields,help:pos_user_restriction.field_pos_config__group_pos_user_id +msgid "" +"This field is there to passthe id of the pos user group to the point of sale " +"client." +msgstr "" +"Questo campo serve a trasferire l'ID del gruppo utente POS al client punto " +"vendita." + +#. module: pos_user_restriction +#: model:res.groups,name:pos_user_restriction.group_assigned_points_of_sale_user +msgid "User: Assigned POS Only" +msgstr "Utente: solamente POS assegnati" + +#. module: pos_user_restriction +#: model:ir.model,name:pos_user_restriction.model_res_users +#: model_terms:ir.ui.view,arch_db:pos_user_restriction.pos_config_view_form_users +msgid "Users" +msgstr "Utenti" + +#. module: pos_user_restriction +#: model_terms:ir.ui.view,arch_db:pos_user_restriction.pos_config_view_form_users +msgid "Users assigned to this point of sale" +msgstr "Utenti assegnati a questo punto vendita" diff --git a/pos_user_restriction/i18n/pos_user_restriction.pot b/pos_user_restriction/i18n/pos_user_restriction.pot new file mode 100644 index 0000000000..e0816e0cc3 --- /dev/null +++ b/pos_user_restriction/i18n/pos_user_restriction.pot @@ -0,0 +1,76 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_user_restriction +# +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: pos_user_restriction +#: model:ir.model.fields,field_description:pos_user_restriction.field_pos_config__assigned_user_ids +msgid "Assigned users" +msgstr "" + +#. module: pos_user_restriction +#: model:ir.model,name:pos_user_restriction.model_pos_config +msgid "Point of Sale Configuration" +msgstr "" + +#. module: pos_user_restriction +#: model:ir.model,name:pos_user_restriction.model_pos_session +msgid "Point of Sale Session" +msgstr "" + +#. module: pos_user_restriction +#: model:ir.model.fields,field_description:pos_user_restriction.field_pos_config__group_pos_user_id +msgid "Point of Sale User Group" +msgstr "" + +#. module: pos_user_restriction +#: model_terms:ir.ui.view,arch_db:pos_user_restriction.pos_config_view_form_users +msgid "" +"Restrict some users to only access their assigned points of sale. In order " +"to apply the restriction, the user needs the 'User: Assigned POS Only' group" +msgstr "" + +#. module: pos_user_restriction +#: model:ir.model.fields,help:pos_user_restriction.field_pos_config__assigned_user_ids +msgid "" +"Restrict some users to only access their assigned points of sale.In order to" +" apply the restriction, the user needs the 'User: Assigned POS Only' group" +msgstr "" + +#. module: pos_user_restriction +#: model:res.groups,comment:pos_user_restriction.group_assigned_points_of_sale_user +msgid "The user will have access to her assigned points of sale." +msgstr "" + +#. module: pos_user_restriction +#: model:ir.model.fields,help:pos_user_restriction.field_pos_config__group_pos_user_id +msgid "" +"This field is there to passthe id of the pos user group to the point of sale" +" client." +msgstr "" + +#. module: pos_user_restriction +#: model:res.groups,name:pos_user_restriction.group_assigned_points_of_sale_user +msgid "User: Assigned POS Only" +msgstr "" + +#. module: pos_user_restriction +#: model:ir.model,name:pos_user_restriction.model_res_users +#: model_terms:ir.ui.view,arch_db:pos_user_restriction.pos_config_view_form_users +msgid "Users" +msgstr "" + +#. module: pos_user_restriction +#: model_terms:ir.ui.view,arch_db:pos_user_restriction.pos_config_view_form_users +msgid "Users assigned to this point of sale" +msgstr "" diff --git a/pos_user_restriction/models/__init__.py b/pos_user_restriction/models/__init__.py new file mode 100644 index 0000000000..3a04de7fa4 --- /dev/null +++ b/pos_user_restriction/models/__init__.py @@ -0,0 +1,3 @@ +from . import pos_config +from . import pos_session +from . import res_users diff --git a/pos_user_restriction/models/pos_config.py b/pos_user_restriction/models/pos_config.py new file mode 100644 index 0000000000..cbc86a36a9 --- /dev/null +++ b/pos_user_restriction/models/pos_config.py @@ -0,0 +1,29 @@ +from odoo import api, fields, models + + +class PosConfig(models.Model): + _inherit = "pos.config" + + assigned_user_ids = fields.Many2many( + "res.users", + string="Assigned users", + help="Restrict some users to only access their assigned points of sale." + "In order to apply the restriction, the user needs the " + "'User: Assigned POS Only' group", + ) + group_pos_user_id = fields.Many2one( + "res.groups", + compute="_compute_group_pos_user_id", + string="Point of Sale User Group", + help="This field is there to pass" + "the id of the pos user group to the point of sale client.", + store=True, + ) + + @api.depends("assigned_user_ids") + def _compute_group_pos_user_id(self): + for config in self: + config.group_pos_user_id = self.env.ref( + "pos_user_restriction.group_assigned_points_of_sale_user", + "point_of_sale.group_pos_user", + ) diff --git a/pos_user_restriction/models/pos_session.py b/pos_user_restriction/models/pos_session.py new file mode 100644 index 0000000000..c07e262efe --- /dev/null +++ b/pos_user_restriction/models/pos_session.py @@ -0,0 +1,12 @@ +from odoo import models + + +class PosSession(models.Model): + _inherit = "pos.session" + + def get_closing_control_data(self): + if self.env.user.has_group( + "pos_user_restriction.group_assigned_points_of_sale_user" + ): + self = self.with_context(bypass_pos_user=True) + return super().get_closing_control_data() diff --git a/pos_user_restriction/models/res_users.py b/pos_user_restriction/models/res_users.py new file mode 100644 index 0000000000..c99cba43b9 --- /dev/null +++ b/pos_user_restriction/models/res_users.py @@ -0,0 +1,15 @@ +from odoo import api, models + + +class ResUsers(models.Model): + _inherit = "res.users" + + @api.model + def has_group(self, group_ext_id): + if group_ext_id == "point_of_sale.group_pos_user" and self.env.context.get( + "bypass_pos_user" + ): + return True + else: + res = super().has_group(group_ext_id) + return res diff --git a/pos_user_restriction/pyproject.toml b/pos_user_restriction/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/pos_user_restriction/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/pos_user_restriction/readme/CONFIGURE.md b/pos_user_restriction/readme/CONFIGURE.md new file mode 100644 index 0000000000..f9ccb96051 --- /dev/null +++ b/pos_user_restriction/readme/CONFIGURE.md @@ -0,0 +1,9 @@ +With a POS Manager, open a point of sale configration (pos.config) and +set "Assigned users" field. + +Then, assign "User: Assigned POS Only" group to users who should be able +to access to their assigned points of sale only. + +Allowed Employees Then assign "Authorized Employees" employee the same +user "Assigned POS Only" Use employee credentials to log in to the PoS +session and switch cashier. diff --git a/pos_user_restriction/readme/CONTRIBUTORS.md b/pos_user_restriction/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..e892e591bc --- /dev/null +++ b/pos_user_restriction/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Lorenzo Battistini () +- Helly kapatel \<\> diff --git a/pos_user_restriction/readme/DESCRIPTION.md b/pos_user_restriction/readme/DESCRIPTION.md new file mode 100644 index 0000000000..c675657603 --- /dev/null +++ b/pos_user_restriction/readme/DESCRIPTION.md @@ -0,0 +1 @@ +Restrict some users to only access their assigned points of sale. diff --git a/pos_user_restriction/readme/ROADMAP.md b/pos_user_restriction/readme/ROADMAP.md new file mode 100644 index 0000000000..aad6d0aa82 --- /dev/null +++ b/pos_user_restriction/readme/ROADMAP.md @@ -0,0 +1,4 @@ +This module alone is not compatible with pos_cache; you need to install +a bridge module like + for it +to work. diff --git a/pos_user_restriction/security/ir.model.access.csv b/pos_user_restriction/security/ir.model.access.csv new file mode 100644 index 0000000000..8c26159c7d --- /dev/null +++ b/pos_user_restriction/security/ir.model.access.csv @@ -0,0 +1,31 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_pos_order,pos.order,point_of_sale.model_pos_order,group_assigned_points_of_sale_user,1,1,1,1 +access_pos_order_line,pos.order.line,point_of_sale.model_pos_order_line,group_assigned_points_of_sale_user,1,1,1,1 +access_pos_pack_operation_lot,pos.pack.operation.lot,point_of_sale.model_pos_pack_operation_lot,group_assigned_points_of_sale_user,1,1,1,1 +access_stock_picking_pos_user,stock.picking pos_user,stock.model_stock_picking,group_assigned_points_of_sale_user,1,1,1,1 +access_stock_warehouse_pos_user,stock.warehouse pos_user,stock.model_stock_warehouse,group_assigned_points_of_sale_user,1,0,0,0 +access_stock_move_pos_user,stock.move pos_user,stock.model_stock_move,group_assigned_points_of_sale_user,1,1,1,1 +access_report_pos_order,report.pos.order,point_of_sale.model_report_pos_order,group_assigned_points_of_sale_user,1,1,1,1 +access_account_journal_pos_user,account.journal pos_user,account.model_account_journal,group_assigned_points_of_sale_user,1,0,0,0 +access_account_payment_method_pos_user,account.payment.method pos_user,account.model_account_payment_method,group_assigned_points_of_sale_user,1,0,0,0 +access_account_bank_statement,account.bank.statement,account.model_account_bank_statement,group_assigned_points_of_sale_user,1,1,1,0 +access_account_bank_statement_line,account.bank.statement.line,account.model_account_bank_statement_line,group_assigned_points_of_sale_user,1,1,1,0 +access_product_product,product.product,product.model_product_product,group_assigned_points_of_sale_user,1,0,0,0 +access_product_template_pos_user,product.template pos user,product.model_product_template,group_assigned_points_of_sale_user,1,0,0,0 +access_product_product_supplierinfo_user,product.supplierinfo user,product.model_product_supplierinfo,group_assigned_points_of_sale_user,1,0,0,0 +access_product_product_packaging_user,product.packaging user,product.model_product_packaging,group_assigned_points_of_sale_user,1,0,0,0 +access_product_pricelist_user,product.pricelist user,product.model_product_pricelist,group_assigned_points_of_sale_user,1,0,0,0 +access_pos_session_user,pos.session user,point_of_sale.model_pos_session,group_assigned_points_of_sale_user,1,1,1,0 +access_pos_config_user,pos.config user,point_of_sale.model_pos_config,group_assigned_points_of_sale_user,1,1,0,0 +access_product_category_pos_user,pos.category user,point_of_sale.model_pos_category,group_assigned_points_of_sale_user,1,0,0,0 +access_barcode_nomenclature_pos_user,barcode.nomenclature.pos.user,barcodes.model_barcode_nomenclature,group_assigned_points_of_sale_user,1,0,0,0 +access_barcode_rule_pos_user,barcode.rule.pos.user,barcodes.model_barcode_rule,group_assigned_points_of_sale_user,1,0,0,0 +access_account_cash_rounding_pos_user,account.cash.rounding.pos.user,account.model_account_cash_rounding,group_assigned_points_of_sale_user,1,0,0,0 +access_pos_payment_method_user,pos.payment.method user,point_of_sale.model_pos_payment_method,group_assigned_points_of_sale_user,1,0,0,0 +access_decimal_precision_user,decimal.precision,base.model_decimal_precision,group_assigned_points_of_sale_user,1,0,0,0 +access_pos_payment_user,pos.payment user,point_of_sale.model_pos_payment,group_assigned_points_of_sale_user,1,1,1,1 +access_pos_bill_user,pos.bill,point_of_sale.model_pos_bill,group_assigned_points_of_sale_user,1,1,1,1 +access_pos_close_session_wizard,access.pos.close.session.wizard,point_of_sale.model_pos_close_session_wizard,group_assigned_points_of_sale_user,1,1,1,0 +access_pos_printer,pos.printer.user,point_of_sale.model_pos_printer,group_assigned_points_of_sale_user,1,0,0,0 +access_pos_combo_user,pos.combo user,point_of_sale.model_pos_combo,group_assigned_points_of_sale_user,1,0,0,0 +access_pos_combo_line_user,pos.combo.line user,point_of_sale.model_pos_combo_line,group_assigned_points_of_sale_user,1,0,0,0 diff --git a/pos_user_restriction/security/pos_security.xml b/pos_user_restriction/security/pos_security.xml new file mode 100644 index 0000000000..52386d2ec0 --- /dev/null +++ b/pos_user_restriction/security/pos_security.xml @@ -0,0 +1,64 @@ + + + + User: Assigned POS Only + + The user will have access to her assigned points of sale. + + + + + + + + + Assigned points of sale + + ['|',('assigned_user_ids','in',user.id),('assigned_user_ids','=',False),('company_id', 'in', company_ids)] + + + + Assigned POS sessions + + ['|',('config_id.assigned_user_ids','in',user.id),('config_id.assigned_user_ids','=',False),('company_id', 'in', company_ids)] + + + + Assigned POS orders + + ['|',('session_id.config_id.assigned_user_ids','in',user.id),('session_id.config_id.assigned_user_ids','=',False),('company_id', 'in', company_ids)] + + + + + All points of sale + + [(1,'=',1)] + + + + All POS sessions + + [(1,'=',1)] + + + + All POS orders + + [(1,'=',1)] + + + + + diff --git a/pos_user_restriction/static/description/icon.png b/pos_user_restriction/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/pos_user_restriction/static/description/icon.png differ diff --git a/pos_user_restriction/static/description/index.html b/pos_user_restriction/static/description/index.html new file mode 100644 index 0000000000..a1af01d8b9 --- /dev/null +++ b/pos_user_restriction/static/description/index.html @@ -0,0 +1,445 @@ + + + + + +Point of Sale - Restrict users + + + +
+

Point of Sale - Restrict users

+ + +

Beta License: LGPL-3 OCA/pos Translate me on Weblate Try me on Runboat

+

Restrict some users to only access their assigned points of sale.

+

Table of contents

+ +
+

Configuration

+

With a POS Manager, open a point of sale configration (pos.config) and +set “Assigned users” field.

+

Then, assign “User: Assigned POS Only” group to users who should be able +to access to their assigned points of sale only.

+

Allowed Employees Then assign “Authorized Employees” employee the same +user “Assigned POS Only” Use employee credentials to log in to the PoS +session and switch cashier.

+
+
+

Known issues / Roadmap

+

This module alone is not compatible with pos_cache; you need to install +a bridge module like +https://github.com/OCA/pos/tree/12.0/pos_cache_user_restriction for it +to work.

+
+
+

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

+
    +
  • TAKOBI
  • +
+
+
+

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:

+

eLBati

+

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

+

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

+
+
+
+ + diff --git a/pos_user_restriction/tests/__init__.py b/pos_user_restriction/tests/__init__.py new file mode 100644 index 0000000000..8936d63bbe --- /dev/null +++ b/pos_user_restriction/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_pos_user_restriction +from . import test_hacks diff --git a/pos_user_restriction/tests/test_hacks.py b/pos_user_restriction/tests/test_hacks.py new file mode 100644 index 0000000000..17865d7487 --- /dev/null +++ b/pos_user_restriction/tests/test_hacks.py @@ -0,0 +1,44 @@ +from odoo.tests import tagged + +from odoo.addons.point_of_sale.tests.common import TestPoSCommon + + +@tagged("post_install", "-at_install") +class TestHacks(TestPoSCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + tracking_disable=True, + no_reset_password=True, + ) + ) + cls.pos_user_assigned_pos = cls.env["res.users"].create( + { + "login": "pos_user_assigned_pos", + "name": "pos_user_assigned_pos", + "groups_id": [ + ( + 6, + 0, + [ + cls.env.ref( + "pos_user_restriction.group_assigned_points_of_sale_user" + ).id + ], + ) + ], + } + ) + + def test_get_closing_control_data(self): + restricted_user = self.pos_user_assigned_pos + self.config = self._create_basic_config() + self.config.assigned_user_ids = [(6, 0, [restricted_user.id])] + + session = self.open_new_session() + + # make sure it does raise AccessError + session.with_user(restricted_user).get_closing_control_data() diff --git a/pos_user_restriction/tests/test_pos_user_restriction.py b/pos_user_restriction/tests/test_pos_user_restriction.py new file mode 100644 index 0000000000..2d7764de51 --- /dev/null +++ b/pos_user_restriction/tests/test_pos_user_restriction.py @@ -0,0 +1,87 @@ +from odoo.tests.common import TransactionCase + + +class TestUserRestriction(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + tracking_disable=True, + no_reset_password=True, + ) + ) + cls.pos_user = cls.env["res.users"].create( + { + "login": "pos_user", + "name": "pos_user", + "groups_id": [(6, 0, [cls.env.ref("point_of_sale.group_pos_user").id])], + } + ) + cls.pos_user_assigned_pos = cls.env["res.users"].create( + { + "login": "pos_user_assigned_pos", + "name": "pos_user_assigned_pos", + "groups_id": [ + ( + 6, + 0, + [ + cls.env.ref( + "pos_user_restriction.group_assigned_points_of_sale_user" + ).id + ], + ) + ], + } + ) + cls.pos_config_main = cls.env.ref("point_of_sale.pos_config_main") + cls.pos_config_model = cls.env["pos.config"] + + def test_access_pos(self): + # assigned_user_ids is not set: both users can read + pos_configs = self.pos_config_model.with_user(self.pos_user.id).search( + [ + ( + "id", + "=", + self.pos_config_main.id, + ) # for tests to pass if pos_restaurant is installed + ] + ) + self.assertTrue(pos_configs) + pos_configs = self.pos_config_model.with_user( + self.pos_user_assigned_pos.id + ).search([("id", "=", self.pos_config_main.id)]) + self.assertTrue(pos_configs) + + self.pos_config_main.assigned_user_ids = [ + (6, 0, [self.pos_user_assigned_pos.id]) + ] + # assigned_user_ids is set with pos_user_assigned_pos: both users can read + pos_configs = self.pos_config_model.with_user(self.pos_user.id).search( + [("id", "=", self.pos_config_main.id)] + ) + self.assertTrue(pos_configs) + pos_configs = self.pos_config_model.with_user( + self.pos_user_assigned_pos.id + ).search([("id", "=", self.pos_config_main.id)]) + self.assertTrue(pos_configs) + self.pos_config_main.assigned_user_ids = [(6, 0, [self.pos_user.id])] + # assigned_user_ids is set with pos_user: only pos_user can read + pos_configs = self.pos_config_model.with_user(self.pos_user.id).search( + [("id", "=", self.pos_config_main.id)] + ) + self.assertTrue(pos_configs) + pos_configs = self.pos_config_model.with_user( + self.pos_user_assigned_pos.id + ).search([("id", "=", self.pos_config_main.id)]) + self.assertFalse(pos_configs) + + self.assigned_group = self.env.ref( + "pos_user_restriction.group_assigned_points_of_sale_user" + ) + self.assertEqual(self.assigned_group, self.pos_config_main.group_pos_user_id) + + self.assertFalse(pos_configs) diff --git a/pos_user_restriction/views/point_of_sale_views.xml b/pos_user_restriction/views/point_of_sale_views.xml new file mode 100644 index 0000000000..dbc6001cc3 --- /dev/null +++ b/pos_user_restriction/views/point_of_sale_views.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/pos_user_restriction/views/pos_config_views.xml b/pos_user_restriction/views/pos_config_views.xml new file mode 100644 index 0000000000..5aa6077efb --- /dev/null +++ b/pos_user_restriction/views/pos_config_views.xml @@ -0,0 +1,41 @@ + + + + pos_config_view_form_users + pos.config + + + +

Users

+
+
+
+
+ Users assigned to this point of sale +
+
+
+
+
+
+
+
+
+
+
+