diff --git a/pos_access_right/README.rst b/pos_access_right/README.rst index b7daa576..9fdea9e2 100644 --- a/pos_access_right/README.rst +++ b/pos_access_right/README.rst @@ -73,6 +73,7 @@ Contributors ~~~~~~~~~~~~ * Sylvain LE GAL +* Ammar Officewla Maintainers ~~~~~~~~~~~ diff --git a/pos_access_right/__manifest__.py b/pos_access_right/__manifest__.py index 154a5f69..fe04b4e0 100644 --- a/pos_access_right/__manifest__.py +++ b/pos_access_right/__manifest__.py @@ -4,7 +4,7 @@ { 'name': 'Point of Sale - Extra Access Right', - 'version': '12.0.1.0.1', + 'version': '13.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)', diff --git a/pos_access_right/models/pos_config.py b/pos_access_right/models/pos_config.py index 33d828cd..ebb76e80 100644 --- a/pos_access_right/models/pos_config.py +++ b/pos_access_right/models/pos_config.py @@ -2,7 +2,7 @@ # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import fields, models, api +from odoo import fields, models class PosConfig(models.Model): @@ -50,37 +50,31 @@ class PosConfig(models.Model): help="This field is there to pass the id of the 'PoS - Payment'" " Group to the Point of Sale Frontend.") - @api.multi def _compute_group_negative_qty_id(self): for config in self: self.group_negative_qty_id = \ self.env.ref('pos_access_right.group_negative_qty') - @api.multi def _compute_group_discount_id(self): for config in self: self.group_discount_id = \ self.env.ref('pos_access_right.group_discount') - @api.multi def _compute_group_change_unit_price_id(self): for config in self: self.group_change_unit_price_id = \ self.env.ref('pos_access_right.group_change_unit_price') - @api.multi def _compute_group_multi_order_id(self): for config in self: self.group_multi_order_id = \ self.env.ref('pos_access_right.group_multi_order') - @api.multi def _compute_group_delete_order_id(self): for config in self: self.group_delete_order_id = \ self.env.ref('pos_access_right.group_delete_order') - @api.multi def _compute_group_payment_id(self): for config in self: self.group_payment_id = \ diff --git a/pos_access_right/readme/CONTRIBUTORS.rst b/pos_access_right/readme/CONTRIBUTORS.rst index 9f76a75b..c52583e6 100644 --- a/pos_access_right/readme/CONTRIBUTORS.rst +++ b/pos_access_right/readme/CONTRIBUTORS.rst @@ -1 +1,2 @@ * Sylvain LE GAL +* Ammmar Officewala diff --git a/pos_access_right/static/description/index.html b/pos_access_right/static/description/index.html index 2631a5f8..7d9cd50f 100644 --- a/pos_access_right/static/description/index.html +++ b/pos_access_right/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! 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);
  • @@ -419,6 +419,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

    Contributors

    @@ -428,7 +429,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

    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/pos_access_right.js b/pos_access_right/static/src/js/pos_access_right.js index 2d763cdf..80d61f1d 100644 --- a/pos_access_right/static/src/js/pos_access_right.js +++ b/pos_access_right/static/src/js/pos_access_right.js @@ -13,10 +13,28 @@ odoo.define('pos_access_right.pos_access_right', function (require) { var models = require('point_of_sale.models'); var gui = require('point_of_sale.gui'); var core = require('web.core'); + var DB = require('point_of_sale.DB'); var _t = core._t; + + // New function 'display_access_right' to display disabled functions + gui.Gui.prototype.get_user_groups = function (){ + var self = this; + if (this.pos.get_cashier() && this.pos.user && this.pos.get_cashier().user_id[0] == this.pos.user.id) { + return this.pos.user + }else{ + return _.find(this.pos.users, function(user_id){ + if (self.pos.get_cashier().user_id && self.pos.get_cashier().user_id[0] == user_id.id){ + return user_id + } + }) + } + }, gui.Gui.prototype.display_access_right = function (user) { + if (!user.groups_id){ + user = this.get_user_groups(); + } if (user.groups_id.indexOf( this.pos.config.group_negative_qty_id[0]) === -1) { $('.numpad-minus').addClass('pos-disabled-mode'); @@ -50,12 +68,21 @@ odoo.define('pos_access_right.pos_access_right', function (require) { // unauthorized function after cashier changed var _set_cashier_ = models.PosModel.prototype.set_cashier; models.PosModel.prototype.set_cashier = function (user) { - if (user.groups_id) { - this.gui.display_access_right(user); + var user_groups = user + if (user.user_id && this.user && user.user_id[0] == this.user.id) { + user_groups = this.user + }else{ + user_groups = _.find(this.users, function(user_id){ + if (user.user_id && user.user_id[0] == user_id.id){ + return user_id + } + }) + } + if (user_groups) { + this.gui.display_access_right(user_groups); } _set_cashier_.call(this, user); }; - chrome.OrderSelectorWidget.include({ /** @@ -64,7 +91,10 @@ odoo.define('pos_access_right.pos_access_right', function (require) { * @param {HTMLElement | jQuery} $el */ neworder_click_handler: function (event, $el) { - if (this.pos.get_cashier().groups_id.indexOf( + var user = []; + var self = this + var user = this.gui.get_user_groups() + if (!user || !user.groups_id || user.groups_id.indexOf( this.pos.config.group_multi_order_id[0]) === -1) { this.gui.show_popup('error', { 'title': _t('Many Orders - Unauthorized function'), @@ -81,7 +111,8 @@ odoo.define('pos_access_right.pos_access_right', function (require) { * @param {HTMLElement | jQuery} $el */ deleteorder_click_handler: function (event, $el) { - if (this.pos.get_cashier().groups_id.indexOf( + var user = this.gui.get_user_groups() + if (!user || !user.groups_id || user.groups_id.indexOf( this.pos.config.group_delete_order_id[0]) === -1) { this.gui.show_popup('error', { 'title': _t('Delete Order - Unauthorized function'), @@ -109,7 +140,8 @@ odoo.define('pos_access_right.pos_access_right', function (require) { * @returns {Object} */ clickSwitchSign: function () { - if (this.pos.get_cashier().groups_id.indexOf( + var user = this.gui.get_user_groups() + if (!user || !user.groups_id || user.groups_id.indexOf( this.pos.config.group_negative_qty_id[0]) === -1) { this.gui.show_popup('error', { 'title': _t('Negative Quantity - Unauthorized function'), @@ -128,16 +160,17 @@ odoo.define('pos_access_right.pos_access_right', function (require) { */ clickChangeMode: function (event) { var target = event.currentTarget.attributes['data-mode']; + var user = this.gui.get_user_groups() if (target.nodeValue === 'discount' && - this.pos.get_cashier().groups_id.indexOf( - this.pos.config.group_discount_id[0]) === -1) { + (!user || !user.groups_id || user.groups_id.indexOf( + this.pos.config.group_discount_id[0]) === -1)) { this.gui.show_popup('error', { 'title': _t('Discount - Unauthorized function'), 'body': _t('Please ask your manager to do it.'), }); - } else if (target.nodeValue === 'price' && - this.pos.get_cashier().groups_id.indexOf( - this.pos.config.group_change_unit_price_id[0]) === -1) { + } else if (target.nodeValue === 'price' && (!user || !user.groups_id || + user.groups_id.indexOf( + this.pos.config.group_change_unit_price_id[0]) === -1)) { this.gui.show_popup('error', { 'title': _t('Change Unit Price - Unauthorized function'), 'body': _t('Please ask your manager to do it.'), @@ -160,7 +193,8 @@ odoo.define('pos_access_right.pos_access_right', function (require) { var button_pay_click_handler = $._data( this.$el.find(".button.pay")[0], "events").click[0].handler; this.$('.pay').off('click').click(function () { - if (self.pos.get_cashier().groups_id.indexOf( + var user = self.gui.get_user_groups() + if (!user || !user.groups_id || user.groups_id.indexOf( self.pos.config.group_payment_id[0]) === -1) { self.gui.show_popup('error', { 'title': _t('Payment - Unauthorized function'),