From 1bb1fbce2da06f16586e5279407541c517a5943c Mon Sep 17 00:00:00 2001 From: jumeldi74 Date: Mon, 24 Apr 2023 22:37:53 +0700 Subject: [PATCH] [MIG] pos_access_right: Migration to 16.0 --- pos_access_right/__manifest__.py | 16 +++++--- pos_access_right/models/__init__.py | 1 + pos_access_right/models/pos_session.py | 38 ++++++++++++++++++ pos_access_right/readme/CONTRIBUTORS.rst | 1 + .../static/src/js/NumpadWidget.js | 19 ++++----- .../static/src/js/TicketScreen.js | 9 ++--- pos_access_right/static/src/js/models.js | 40 ------------------- .../static/src/xml/NumpadWidget.xml | 12 ++++++ pos_access_right/views/templates.xml | 23 ----------- 9 files changed, 72 insertions(+), 87 deletions(-) create mode 100644 pos_access_right/models/pos_session.py delete mode 100644 pos_access_right/static/src/js/models.js delete mode 100644 pos_access_right/views/templates.xml diff --git a/pos_access_right/__manifest__.py b/pos_access_right/__manifest__.py index 51f00a42a6..384b5e6d85 100644 --- a/pos_access_right/__manifest__.py +++ b/pos_access_right/__manifest__.py @@ -4,20 +4,24 @@ { "name": "Point of Sale - Extra Access Right", - "version": "14.0.1.0.2", + "version": "16.0.1.0.0", "category": "Point Of Sale", "summary": "Point of Sale - Extra Access Right for certain actions", "author": "La Louve, GRAP, Odoo Community Association (OCA)", "website": "https://github.com/OCA/pos", "license": "AGPL-3", - "depends": ["point_of_sale"], + "depends": ["pos_hr"], + "demo": ["demo/res_groups.xml"], "data": [ "security/res_groups.xml", - "views/templates.xml", - ], - "demo": [ - "demo/res_groups.xml", ], + "assets": { + "point_of_sale.assets": [ + "pos_access_right/static/src/css/*", + "pos_access_right/static/src/js/*.js", + "pos_access_right/static/src/xml/*.xml", + ] + }, "qweb": [ "static/src/xml/*.xml", ], diff --git a/pos_access_right/models/__init__.py b/pos_access_right/models/__init__.py index db8634ade1..20c47743d3 100644 --- a/pos_access_right/models/__init__.py +++ b/pos_access_right/models/__init__.py @@ -1 +1,2 @@ from . import pos_config +from . import pos_session diff --git a/pos_access_right/models/pos_session.py b/pos_access_right/models/pos_session.py new file mode 100644 index 0000000000..9afcd4d332 --- /dev/null +++ b/pos_access_right/models/pos_session.py @@ -0,0 +1,38 @@ +from odoo import models + + +class PosSession(models.Model): + _inherit = "pos.session" + + def _get_pos_ui_hr_employee(self, params): + employees = super()._get_pos_ui_hr_employee(params) + for employee in employees: + user = self.env["res.users"].browse(employee["user_id"]) + if user: + groups = user.groups_id + config = self.config_id + employee["hasGroupPayment"] = ( + True if config.group_payment_id in groups else False + ) + + employee["hasGroupDiscount"] = ( + True if config.group_discount_id in groups else False + ) + + employee["hasGroupNegativeQty"] = ( + True if config.group_negative_qty_id in groups else False + ) + + employee["hasGroupPriceControl"] = ( + True if config.group_change_unit_price_id in groups else False + ) + + employee["hasGroupMultiOrder"] = ( + True if config.group_multi_order_id in groups else False + ) + + employee["hasGroupDeleteOrder"] = ( + True if config.group_delete_order_id in groups else False + ) + + return employees diff --git a/pos_access_right/readme/CONTRIBUTORS.rst b/pos_access_right/readme/CONTRIBUTORS.rst index 66987d8373..452a4d13d5 100644 --- a/pos_access_right/readme/CONTRIBUTORS.rst +++ b/pos_access_right/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * Sylvain LE GAL * Ammmar Officewala * Helly kapatel +* Jumeldi diff --git a/pos_access_right/static/src/js/NumpadWidget.js b/pos_access_right/static/src/js/NumpadWidget.js index 73d67d87c9..3721fe2282 100644 --- a/pos_access_right/static/src/js/NumpadWidget.js +++ b/pos_access_right/static/src/js/NumpadWidget.js @@ -9,29 +9,24 @@ odoo.define("pos_access_right.NumpadWidget", function (require) { get hasManualDiscount() { const res = super.hasManualDiscount; if (res) { - if (this.env.pos.get_cashier().hasGroupDiscount) { - return true; - } - return false; + return this.env.pos.get_cashier().hasGroupDiscount; } return res; } get hasMinusControlRights() { - if (this.env.pos.get_cashier().hasGroupNegativeQty) { - return true; - } - return false; + return this.env.pos.get_cashier().hasGroupNegativeQty; } get hasPriceControlRights() { const res = super.hasPriceControlRights; if (res) { - if (this.env.pos.get_cashier().hasGroupPriceControl) { - return true; - } - return false; + return this.env.pos.get_cashier().hasGroupPriceControl; } return res; } + + get hasDeleteOrderLineRights() { + return this.env.pos.get_cashier().hasGroupDeleteOrder; + } }; Registries.Component.extend(NumpadWidget, PosNumpadWidget); diff --git a/pos_access_right/static/src/js/TicketScreen.js b/pos_access_right/static/src/js/TicketScreen.js index bf3c73e2c7..a9c82b37c5 100644 --- a/pos_access_right/static/src/js/TicketScreen.js +++ b/pos_access_right/static/src/js/TicketScreen.js @@ -7,15 +7,12 @@ odoo.define("pos_access_right.TicketScreen", function (require) { const PosTicketScreen = (TicketScreen) => class extends TicketScreen { get hasNewOrdersControlRights() { - if (this.env.pos.get_cashier().hasGroupMultiOrder) { - return true; - } - return false; + return this.env.pos.get_cashier().hasGroupMultiOrder; } - async deleteOrder(order) { + async _onDeleteOrder({detail: order}) { if (this.env.pos.get_cashier().hasGroupDeleteOrder) { - return super.deleteOrder(order); + 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 deleted file mode 100644 index 1c7958fec9..0000000000 --- a/pos_access_right/static/src/js/models.js +++ /dev/null @@ -1,40 +0,0 @@ -odoo.define("pos_access_right.models", function (require) { - "use strict"; - - var models = require("point_of_sale.models"); - var posmodel_super = models.PosModel.prototype; - - models.PosModel = models.PosModel.extend({ - get_cashier: function () { - const pos_cashier = posmodel_super.get_cashier.apply(this); - const cashier = this.env.pos.users.find( - (user) => user.id === pos_cashier.user_id[0] - ); - pos_cashier.hasGroupPayment = - cashier && - cashier.groups_id.includes(this.env.pos.config.group_payment_id[0]); - pos_cashier.hasGroupDiscount = - cashier && - cashier.groups_id.includes(this.env.pos.config.group_discount_id[0]); - pos_cashier.hasGroupNegativeQty = - cashier && - cashier.groups_id.includes( - this.env.pos.config.group_negative_qty_id[0] - ); - pos_cashier.hasGroupPriceControl = - cashier && - cashier.groups_id.includes( - this.env.pos.config.group_change_unit_price_id[0] - ); - pos_cashier.hasGroupMultiOrder = - cashier && - cashier.groups_id.includes(this.env.pos.config.group_multi_order_id[0]); - pos_cashier.hasGroupDeleteOrder = - cashier && - cashier.groups_id.includes( - this.env.pos.config.group_delete_order_id[0] - ); - return pos_cashier; - }, - }); -}); diff --git a/pos_access_right/static/src/xml/NumpadWidget.xml b/pos_access_right/static/src/xml/NumpadWidget.xml index faf5411df9..bbc3896eca 100644 --- a/pos_access_right/static/src/xml/NumpadWidget.xml +++ b/pos_access_right/static/src/xml/NumpadWidget.xml @@ -16,6 +16,18 @@ >{'disabled-mode': !hasMinusControlRights} !hasMinusControlRights + + + {'disabled-mode': !hasDeleteOrderLineRights} + !hasDeleteOrderLineRights + + + diff --git a/pos_access_right/views/templates.xml b/pos_access_right/views/templates.xml deleted file mode 100644 index 000b34a01e..0000000000 --- a/pos_access_right/views/templates.xml +++ /dev/null @@ -1,23 +0,0 @@ - -