From e9bb9be4e005f9c8e95e8d6ed9969285196bf689 Mon Sep 17 00:00:00 2001 From: jumeldi74 Date: Tue, 25 Apr 2023 09:42:26 +0700 Subject: [PATCH] [MIG] pos_access_right: Migration to 16.0 - revision [MIG] pos_access_right: Migration to 16.0 - revision 2 [MIG] pos_access_right: Migration to 16.0 - adjusted test unit and add one line information in description. [MIG] pos_access_right: Migration to 16.0 - repair test unit error. [MIG] pos_access_right: Migration to 16.0 - still repair test unit error. [MIG] pos_access_right: Migration to 16.0 - give access right for backspace button in keyboard and button remove in order line to delete order line. --- pos_access_right/README.rst | 8 +++---- pos_access_right/demo/res_groups.xml | 7 ++++++ pos_access_right/i18n/it.po | 2 +- pos_access_right/i18n/pos_access_right.pot | 2 +- pos_access_right/models/pos_config.py | 11 ++++++++++ pos_access_right/models/pos_session.py | 22 +++++++++++++++++++ pos_access_right/readme/DESCRIPTION.rst | 1 + pos_access_right/security/res_groups.xml | 5 +++++ .../static/description/index.html | 4 ++-- .../static/src/js/ActionpadWidget.js | 4 +++- .../static/src/js/NumpadWidget.js | 16 ++++++++++---- .../static/src/js/TicketScreen.js | 9 ++++++-- pos_access_right/static/src/js/models.js | 20 +++++++++++++++++ .../tests/test_pos_access_right.py | 20 +++++++++++++++-- 14 files changed, 114 insertions(+), 17 deletions(-) create mode 100644 pos_access_right/static/src/js/models.js diff --git a/pos_access_right/README.rst b/pos_access_right/README.rst index 4249f05a36..7ac893085e 100644 --- a/pos_access_right/README.rst +++ b/pos_access_right/README.rst @@ -14,16 +14,16 @@ Point of Sale - Extra Access Right :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github - :target: https://github.com/OCA/pos/tree/14.0/pos_access_right + :target: https://github.com/OCA/pos/tree/16.0/pos_access_right :alt: OCA/pos .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png :target: https://translation.odoo-community.org/projects/pos-14-0/pos-14-0-pos_access_right :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/184/14.0 + :target: https://runbot.odoo-community.org/runbot/184/16.0 :alt: Try me on Runbot -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| This module extends Odoo Point Of Sale features, restricting possibility to cashier to make some actions in the Point of Sale. This module will add the following groups to Odoo: @@ -89,6 +89,6 @@ 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/pos `_ project on GitHub. +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_access_right/demo/res_groups.xml b/pos_access_right/demo/res_groups.xml index 54adf5d908..3ca5d577d5 100644 --- a/pos_access_right/demo/res_groups.xml +++ b/pos_access_right/demo/res_groups.xml @@ -41,6 +41,13 @@ /> + + + + \n" diff --git a/pos_access_right/i18n/pos_access_right.pot b/pos_access_right/i18n/pos_access_right.pot index e57f3b79c8..3e15e881e2 100644 --- a/pos_access_right/i18n/pos_access_right.pot +++ b/pos_access_right/i18n/pos_access_right.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 14.0\n" +"Project-Id-Version: Odoo Server 16.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: \n" "Language-Team: \n" diff --git a/pos_access_right/models/pos_config.py b/pos_access_right/models/pos_config.py index 5333591331..faf1d4b891 100644 --- a/pos_access_right/models/pos_config.py +++ b/pos_access_right/models/pos_config.py @@ -44,6 +44,14 @@ class PosConfig(models.Model): " Group to the Point of Sale Frontend.", ) + group_delete_order_line_id = fields.Many2one( + comodel_name="res.groups", + compute="_compute_groups", + string="Point of Sale - Delete Order Line", + help="This field is there to pass the id of the 'PoS - Delete Order Line'" + " Group to the Point of Sale Frontend.", + ) + group_payment_id = fields.Many2one( comodel_name="res.groups", compute="_compute_groups", @@ -68,6 +76,9 @@ def _compute_groups(self): "group_delete_order_id": self.env.ref( "pos_access_right.group_delete_order" ).id, + "group_delete_order_line_id": self.env.ref( + "pos_access_right.group_delete_order_line" + ).id, "group_payment_id": self.env.ref("pos_access_right.group_payment").id, } ) diff --git a/pos_access_right/models/pos_session.py b/pos_access_right/models/pos_session.py index 9afcd4d332..2cc8936877 100644 --- a/pos_access_right/models/pos_session.py +++ b/pos_access_right/models/pos_session.py @@ -4,6 +4,24 @@ class PosSession(models.Model): _inherit = "pos.session" + def _get_pos_ui_res_users(self, params): + user_vals = super()._get_pos_ui_res_users(params) + user_id = user_vals.get("id") + if user_id: + user = self.env["res.users"].browse(user_id) + groups = user.groups_id + config = self.config_id + user_vals.update( + hasGroupPayment=config.group_payment_id in groups, + hasGroupDiscount=config.group_discount_id in groups, + hasGroupNegativeQty=config.group_negative_qty_id in groups, + hasGroupPriceControl=config.group_change_unit_price_id in groups, + hasGroupMultiOrder=config.group_multi_order_id in groups, + hasGroupDeleteOrder=config.group_delete_order_id in groups, + hasGroupDeleteOrderLine=config.group_delete_order_line_id in groups, + ) + return user_vals + def _get_pos_ui_hr_employee(self, params): employees = super()._get_pos_ui_hr_employee(params) for employee in employees: @@ -35,4 +53,8 @@ def _get_pos_ui_hr_employee(self, params): True if config.group_delete_order_id in groups else False ) + employee["hasGroupDeleteOrderLine"] = ( + True if config.group_delete_order_line_id in groups else False + ) + return employees diff --git a/pos_access_right/readme/DESCRIPTION.rst b/pos_access_right/readme/DESCRIPTION.rst index f475ace96b..3574141be2 100644 --- a/pos_access_right/readme/DESCRIPTION.rst +++ b/pos_access_right/readme/DESCRIPTION.rst @@ -5,3 +5,4 @@ This module extends Odoo Point Of Sale features, restricting possibility to cash * **PoS - Change Unit Price**: The cashier can change the unit price of a product in Point Of Sale; * **PoS - Many Orders**: The cashier can many orders at the same time; * **PoS - Delete Order**: The cashier can not delete a full order; +* **PoS - Delete Order Line**: The cashier can not delete an order line; diff --git a/pos_access_right/security/res_groups.xml b/pos_access_right/security/res_groups.xml index 9fc2cc4946..2db4d5ad08 100644 --- a/pos_access_right/security/res_groups.xml +++ b/pos_access_right/security/res_groups.xml @@ -31,6 +31,11 @@ + + Point of Sale - Delete Order Line + + + Point of Sale - Payment diff --git a/pos_access_right/static/description/index.html b/pos_access_right/static/description/index.html index fc97c2eab2..75b7b2aef8 100644 --- a/pos_access_right/static/description/index.html +++ b/pos_access_right/static/description/index.html @@ -367,7 +367,7 @@

Point of Sale - Extra Access Right

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/pos Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/pos Translate me on Weblate Try me on Runbot

This module extends Odoo Point Of Sale features, restricting possibility to cashier to make some actions in the Point of Sale. This module will add the following groups to Odoo:

  • PoS - Negative Quantity: The cashier can sell negative quantity in Point Of Sale (ie, can return products);
  • @@ -430,7 +430,7 @@

    Maintainers

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

    +

    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_access_right/static/src/js/ActionpadWidget.js b/pos_access_right/static/src/js/ActionpadWidget.js index 228ddabf52..c4c056b087 100644 --- a/pos_access_right/static/src/js/ActionpadWidget.js +++ b/pos_access_right/static/src/js/ActionpadWidget.js @@ -7,7 +7,9 @@ odoo.define("pos_access_right.ActionpadWidget", function (require) { const PosActionpadWidget = (ActionpadWidget) => class extends ActionpadWidget { get hasPaymentControlRights() { - return this.env.pos.get_cashier().hasGroupPayment; + if (this.env.pos.config.module_pos_hr) + return this.env.pos.get_cashier().hasGroupPayment; + return this.env.pos.user.hasGroupPayment; } }; diff --git a/pos_access_right/static/src/js/NumpadWidget.js b/pos_access_right/static/src/js/NumpadWidget.js index 3721fe2282..d476d30bb9 100644 --- a/pos_access_right/static/src/js/NumpadWidget.js +++ b/pos_access_right/static/src/js/NumpadWidget.js @@ -9,23 +9,31 @@ odoo.define("pos_access_right.NumpadWidget", function (require) { get hasManualDiscount() { const res = super.hasManualDiscount; if (res) { - return this.env.pos.get_cashier().hasGroupDiscount; + if (this.env.pos.config.module_pos_hr) + return this.env.pos.get_cashier().hasGroupDiscount; + return this.env.pos.user.hasGroupDiscount; } return res; } get hasMinusControlRights() { - return this.env.pos.get_cashier().hasGroupNegativeQty; + if (this.env.pos.config.module_pos_hr) + return this.env.pos.get_cashier().hasGroupNegativeQty; + return this.env.pos.user.hasGroupNegativeQty; } get hasPriceControlRights() { const res = super.hasPriceControlRights; if (res) { - return this.env.pos.get_cashier().hasGroupPriceControl; + if (this.env.pos.config.module_pos_hr) + return this.env.pos.get_cashier().hasGroupPriceControl; + return this.env.pos.user.hasGroupPriceControl; } return res; } get hasDeleteOrderLineRights() { - return this.env.pos.get_cashier().hasGroupDeleteOrder; + if (this.env.pos.config.module_pos_hr) + return this.env.pos.get_cashier().hasGroupDeleteOrderLine; + return this.env.pos.user.hasGroupDeleteOrderLine; } }; diff --git a/pos_access_right/static/src/js/TicketScreen.js b/pos_access_right/static/src/js/TicketScreen.js index a9c82b37c5..d0415abe7c 100644 --- a/pos_access_right/static/src/js/TicketScreen.js +++ b/pos_access_right/static/src/js/TicketScreen.js @@ -7,11 +7,16 @@ odoo.define("pos_access_right.TicketScreen", function (require) { const PosTicketScreen = (TicketScreen) => class extends TicketScreen { get hasNewOrdersControlRights() { - return this.env.pos.get_cashier().hasGroupMultiOrder; + if (this.env.pos.config.module_pos_hr) + return this.env.pos.get_cashier().hasGroupMultiOrder; + return this.env.pos.user.hasGroupMultiOrder; } async _onDeleteOrder({detail: order}) { - if (this.env.pos.get_cashier().hasGroupDeleteOrder) { + if ( + this.env.pos.get_cashier().hasGroupDeleteOrder && + this.env.pos.user.hasGroupDeleteOrder + ) { return super._onDeleteOrder({detail: order}); } return false; diff --git a/pos_access_right/static/src/js/models.js b/pos_access_right/static/src/js/models.js new file mode 100644 index 0000000000..c8b7735dee --- /dev/null +++ b/pos_access_right/static/src/js/models.js @@ -0,0 +1,20 @@ +odoo.define("pos_access_right.models", function (require) { + "use strict"; + + const Registries = require("point_of_sale.Registries"); + var {Order} = require("point_of_sale.models"); + + const PosAccessRightOrder = (Order) => + class PosAccessRightOrder extends Order { + remove_orderline(line) { + if ( + this.pos.get_cashier().hasGroupDeleteOrderLine && + this.pos.user.hasGroupDeleteOrderLine + ) { + return super.remove_orderline(line); + } + return false; + } + }; + Registries.Model.extend(Order, PosAccessRightOrder); +}); diff --git a/pos_access_right/tests/test_pos_access_right.py b/pos_access_right/tests/test_pos_access_right.py index 86f87b1aa3..4219c82cfb 100644 --- a/pos_access_right/tests/test_pos_access_right.py +++ b/pos_access_right/tests/test_pos_access_right.py @@ -1,7 +1,9 @@ -from odoo.tests.common import SavepointCase +from odoo.tests import TransactionCase, tagged +from odoo.addons.pos_hr.tests.test_frontend import TestPosHrHttpCommon -class TestUserRestriction(SavepointCase): + +class TestUserRestriction(TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() @@ -50,5 +52,19 @@ def test_access_pos(self): self.group_delete_order, self.pos_config_main.group_delete_order_id ) + self.group_delete_order_line = self.env.ref( + "pos_access_right.group_delete_order_line" + ) + self.assertEqual( + self.group_delete_order_line, + self.pos_config_main.group_delete_order_line_id, + ) + self.group_payment = self.env.ref("pos_access_right.group_payment") self.assertEqual(self.group_payment, self.pos_config_main.group_payment_id) + + +@tagged("post_install", "-at_install") +class TestPosAccessRightHttpCommonUi(TestPosHrHttpCommon): + def test_01_load_employee(self): + self.main_pos_config.open_ui()