From d1774b92882077b409e7ae2096b738f93a8f7353 Mon Sep 17 00:00:00 2001 From: geomer198 Date: Sat, 1 Apr 2023 23:21:13 +0300 Subject: [PATCH] [MIG] pos_access_right: Migration to 16.0 --- pos_access_right/README.rst | 8 ++-- pos_access_right/__manifest__.py | 12 ++++-- pos_access_right/i18n/it.po | 2 +- pos_access_right/i18n/pos_access_right.pot | 2 +- pos_access_right/models/__init__.py | 1 + pos_access_right/models/pos_session.py | 22 ++++++++++ .../static/description/index.html | 4 +- .../static/src/js/ActionpadWidget.js | 2 +- .../static/src/js/NumpadWidget.js | 15 ++----- .../static/src/js/TicketScreen.js | 7 +--- pos_access_right/static/src/js/models.js | 40 ------------------- .../tests/test_pos_access_right.py | 4 +- pos_access_right/views/templates.xml | 23 ----------- 13 files changed, 47 insertions(+), 95 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/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/__manifest__.py b/pos_access_right/__manifest__.py index 32a6416214..6927a2ec8d 100644 --- a/pos_access_right/__manifest__.py +++ b/pos_access_right/__manifest__.py @@ -11,13 +11,17 @@ "website": "https://github.com/OCA/pos", "license": "AGPL-3", "depends": ["point_of_sale"], + "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/i18n/it.po b/pos_access_right/i18n/it.po index a2e2ccf5e2..633b8d225c 100644 --- a/pos_access_right/i18n/it.po +++ b/pos_access_right/i18n/it.po @@ -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" "PO-Revision-Date: 2023-03-09 22:22+0000\n" "Last-Translator: mymage \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/__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..fb06eb6350 --- /dev/null +++ b/pos_access_right/models/pos_session.py @@ -0,0 +1,22 @@ +from odoo import models + + +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, + ) + return user_vals 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..08d0914e31 100644 --- a/pos_access_right/static/src/js/ActionpadWidget.js +++ b/pos_access_right/static/src/js/ActionpadWidget.js @@ -7,7 +7,7 @@ odoo.define("pos_access_right.ActionpadWidget", function (require) { const PosActionpadWidget = (ActionpadWidget) => class extends ActionpadWidget { get hasPaymentControlRights() { - 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 73d67d87c9..931bce5e28 100644 --- a/pos_access_right/static/src/js/NumpadWidget.js +++ b/pos_access_right/static/src/js/NumpadWidget.js @@ -9,26 +9,17 @@ 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.user.hasGroupDiscount; } return res; } get hasMinusControlRights() { - if (this.env.pos.get_cashier().hasGroupNegativeQty) { - return true; - } - return false; + return this.env.pos.user.hasGroupNegativeQty; } get hasPriceControlRights() { const res = super.hasPriceControlRights; if (res) { - if (this.env.pos.get_cashier().hasGroupPriceControl) { - return true; - } - return false; + return this.env.pos.user.hasGroupPriceControl; } return res; } diff --git a/pos_access_right/static/src/js/TicketScreen.js b/pos_access_right/static/src/js/TicketScreen.js index bf3c73e2c7..68e364987c 100644 --- a/pos_access_right/static/src/js/TicketScreen.js +++ b/pos_access_right/static/src/js/TicketScreen.js @@ -7,14 +7,11 @@ 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.user.hasGroupMultiOrder; } async deleteOrder(order) { - if (this.env.pos.get_cashier().hasGroupDeleteOrder) { + if (this.env.pos.user.hasGroupDeleteOrder) { return super.deleteOrder(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/tests/test_pos_access_right.py b/pos_access_right/tests/test_pos_access_right.py index 86f87b1aa3..21450a65f9 100644 --- a/pos_access_right/tests/test_pos_access_right.py +++ b/pos_access_right/tests/test_pos_access_right.py @@ -1,7 +1,7 @@ -from odoo.tests.common import SavepointCase +from odoo.tests import TransactionCase -class TestUserRestriction(SavepointCase): +class TestUserRestriction(TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() 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 @@ - -