From 98288aaa2773cbd8bd692995fc994b60f9be29fe Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Mon, 1 Feb 2016 00:22:05 +0100 Subject: [PATCH] [ADD] new module 'pos_access_right' --- pos_access_right/README.rst | 84 ++++++++++++++ pos_access_right/__init__.py | 2 + pos_access_right/__openerp__.py | 25 ++++ pos_access_right/demo/res_groups.yml | 18 +++ pos_access_right/models/__init__.py | 2 + pos_access_right/models/pos_config.py | 52 +++++++++ pos_access_right/security/res_groups.yml | 17 +++ pos_access_right/static/description/icon.png | Bin 0 -> 4374 bytes .../static/src/css/pos_access_right.css | 12 ++ .../static/src/js/pos_access_right.js | 108 ++++++++++++++++++ pos_access_right/static/src/xml/templates.xml | 17 +++ 11 files changed, 337 insertions(+) create mode 100644 pos_access_right/README.rst create mode 100644 pos_access_right/__init__.py create mode 100644 pos_access_right/__openerp__.py create mode 100644 pos_access_right/demo/res_groups.yml create mode 100644 pos_access_right/models/__init__.py create mode 100644 pos_access_right/models/pos_config.py create mode 100644 pos_access_right/security/res_groups.yml create mode 100644 pos_access_right/static/description/icon.png create mode 100644 pos_access_right/static/src/css/pos_access_right.css create mode 100644 pos_access_right/static/src/js/pos_access_right.js create mode 100644 pos_access_right/static/src/xml/templates.xml diff --git a/pos_access_right/README.rst b/pos_access_right/README.rst new file mode 100644 index 00000000..021c681e --- /dev/null +++ b/pos_access_right/README.rst @@ -0,0 +1,84 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +====================================================== +Point of Sale - Extra Access Right for Certain Actions +====================================================== + +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); + +* PoS - Discount: The cashier can set Discount in Point Of Sale; + +* PoS - Change Unit Price: The cashier can change the unit price of a product + in Point Of Sale; + +Important Note +-------------- + +* On PoS Front End, the cashier access right are used. This feature allow + a manager to log into PoS to unblock a specific feature, + + +.. image:: /pos_access_right/static/description/pos_xxx.png + + +Installation +============ + +Normal installation. + +Configuration +============= + +Once installed, you have to give correct access right to your cashiers. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/184/9.0 + +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 smashing it by providing a detailed and welcomed `feedback +`_. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Sylvain LE GAL + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/pos_access_right/__init__.py b/pos_access_right/__init__.py new file mode 100644 index 00000000..a0fdc10f --- /dev/null +++ b/pos_access_right/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import models diff --git a/pos_access_right/__openerp__.py b/pos_access_right/__openerp__.py new file mode 100644 index 00000000..6211f8bd --- /dev/null +++ b/pos_access_right/__openerp__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2016-Today: La Louve () +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Point of Sale - Extra Access Right', + 'version': '9.0.1.0.0', + 'category': 'Point Of Sale', + 'summary': 'Point of Sale - Extra Access Right for certain actions', + 'author': 'La Louve, Odoo Community Association (OCA)', + 'website': 'http://www.lalouve.net/', + 'license': 'AGPL-3', + 'depends': [ + 'point_of_sale', + ], + 'data': [ + 'security/res_groups.yml', + 'static/src/xml/templates.xml', + ], + 'demo': [ + 'demo/res_groups.yml', + ], + 'installable': True, +} diff --git a/pos_access_right/demo/res_groups.yml b/pos_access_right/demo/res_groups.yml new file mode 100644 index 00000000..d79411cb --- /dev/null +++ b/pos_access_right/demo/res_groups.yml @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2016-Today: La Louve () +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +- !record {model: res.groups, id: group_pos_negative_qty}: + users: + - base.user_root + +- !record {model: res.groups, id: group_pos_discount}: + users: + - base.user_root + - base.user_demo + +- !record {model: res.groups, id: group_pos_change_unit_price}: + users: + - base.user_root diff --git a/pos_access_right/models/__init__.py b/pos_access_right/models/__init__.py new file mode 100644 index 00000000..e77b6015 --- /dev/null +++ b/pos_access_right/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import pos_config diff --git a/pos_access_right/models/pos_config.py b/pos_access_right/models/pos_config.py new file mode 100644 index 00000000..19e5fb01 --- /dev/null +++ b/pos_access_right/models/pos_config.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2016-Today: La Louve () +# @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 + + +class PosConfig(models.Model): + _inherit = 'pos.config' + + group_pos_negative_qty = fields.Many2one( + comodel_name='res.groups', + compute='_compute_group_pos_negative_qty', + string='Point of Sale - Allow Negative Quantity', + help="This field is there to pass the id of the 'PoS - Allow Negative" + " Quantity' Group to the Point of Sale Frontend.") + + group_pos_discount = fields.Many2one( + comodel_name='res.groups', + compute='_compute_group_pos_discount', + string='Point of Sale - Allow Discount', + help="This field is there to pass the id of the 'PoS - Allow Discount'" + " Group to the Point of Sale Frontend.") + + group_pos_change_unit_price = fields.Many2one( + comodel_name='res.groups', + compute='_compute_group_pos_change_unit_price', + string='Point of Sale - Allow Unit Price Change', + help="This field is there to pass the id of the 'PoS - Allow Unit" + " Price Change' Group to the Point of Sale Frontend.") + + @api.multi + def _compute_group_pos_negative_qty(self): + print self.env.ref('pos_access_right.group_pos_negative_qty') + for config in self: + self.group_pos_negative_qty = \ + self.env.ref('pos_access_right.group_pos_negative_qty') + + @api.multi + def _compute_group_pos_discount(self): + print self.env.ref('pos_access_right.group_pos_discount') + for config in self: + self.group_pos_discount = \ + self.env.ref('pos_access_right.group_pos_discount') + + @api.multi + def _compute_group_pos_change_unit_price(self): + print self.env.ref('pos_access_right.group_pos_change_unit_price') + for config in self: + self.group_pos_change_unit_price = \ + self.env.ref('pos_access_right.group_pos_change_unit_price') diff --git a/pos_access_right/security/res_groups.yml b/pos_access_right/security/res_groups.yml new file mode 100644 index 00000000..ff4389d1 --- /dev/null +++ b/pos_access_right/security/res_groups.yml @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2016-Today: La Louve () +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +- !record {model: res.groups, id: group_pos_negative_qty}: + name: Point of Sale - Allow Negative Quantity + category_id: base.module_category_usability + +- !record {model: res.groups, id: group_pos_discount}: + name: Point of Sale - Allow Discount + category_id: base.module_category_usability + +- !record {model: res.groups, id: group_pos_change_unit_price}: + name: Point of Sale - Allow Price Change + category_id: base.module_category_usability diff --git a/pos_access_right/static/description/icon.png b/pos_access_right/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..2c83d7101b7d63990c85fa50905fc5904048354b GIT binary patch literal 4374 zcmZ{oXEa>j*T=^wK@c@MiNugmGDfe_dymnHGDI1DM6WSK$skHF#soo#P7u)rqYKdq z(M1apCE9;}FP|6BUFY1r?zwB9bI;zN@7?R(ctd>+YDzXr002O(rKxI6u!{e6ax%iX z%+==y!I1bVYnhM}j!<&=E5bE}x2A<306_EgzfP1PK*LTLr1t3rv2*g^l`u+cL@bH4WItTs#4nl6^EC2wlsg|meNnq|C zCIn$^hV6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cG3R> DMU_o_ literal 0 HcmV?d00001 diff --git a/pos_access_right/static/src/css/pos_access_right.css b/pos_access_right/static/src/css/pos_access_right.css new file mode 100644 index 00000000..00bc938a --- /dev/null +++ b/pos_access_right/static/src/css/pos_access_right.css @@ -0,0 +1,12 @@ +/* + Copyright (C) 2016-Today: La Louve () + @author: Sylvain LE GAL (https://twitter.com/legalsylvain) + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +*/ + +.pos-disabled-mode { + color: #bbb !important; +} +.pos-disabled-mode:hover { + background: #e2e2e2 !important; +} diff --git a/pos_access_right/static/src/js/pos_access_right.js b/pos_access_right/static/src/js/pos_access_right.js new file mode 100644 index 00000000..4013d204 --- /dev/null +++ b/pos_access_right/static/src/js/pos_access_right.js @@ -0,0 +1,108 @@ +/* + Copyright (C) 2016-Today: La Louve () + @author: Sylvain LE GAL (https://twitter.com/legalsylvain) + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +*/ + + +odoo.define('pos_access_right.pos_access_right', function (require) { + "use strict"; + + var screens = require('point_of_sale.screens'); + var models = require('point_of_sale.models'); + var gui = require('point_of_sale.gui'); + var core = require('web.core'); + var _t = core._t; + +/* ******************************************************** +point_of_sale.gui +******************************************************** */ + + // New function 'display_access_right' to display disabled functions + gui.Gui.prototype.display_access_right = function(user){ + if (user.groups_id.indexOf(this.pos.config.group_pos_negative_qty[0]) != -1){ + $('.numpad-minus').removeClass('pos-disabled-mode'); + } + else{ + $('.numpad-minus').addClass('pos-disabled-mode'); + } + if (user.groups_id.indexOf(this.pos.config.group_pos_discount[0]) != -1){ + $(".mode-button[data-mode='discount']").removeClass('pos-disabled-mode'); + } + else{ + $(".mode-button[data-mode='discount']").addClass('pos-disabled-mode'); + } + if (user.groups_id.indexOf(this.pos.config.group_pos_change_unit_price[0]) != -1){ + $(".mode-button[data-mode='price']").removeClass('pos-disabled-mode'); + } + else{ + $(".mode-button[data-mode='price']").addClass('pos-disabled-mode'); + } + }; + + +/* ******************************************************** +point_of_sale.models +******************************************************** */ + + // load extra data from 'pos_config' (ids of new groups) + models.load_fields("pos.config", "group_pos_negative_qty"); + models.load_fields("pos.config", "group_pos_discount"); + models.load_fields("pos.config", "group_pos_change_unit_price"); + + // Overload 'set_cashier' function to display correctly + // unauthorized function after cashier changed + var _set_cashier_ = models.PosModel.prototype.set_cashier; + models.PosModel.prototype.set_cashier = function(user){ + this.gui.display_access_right(user); + _set_cashier_.call(this, user); + }; + + +/* ******************************************************** +screens.NumpadWidget +******************************************************** */ + screens.NumpadWidget.include({ + + // Overload 'start' function to display correctly unauthorized function + // at the beginning of the session, based on current user + start: function() { + this._super(); + this.gui.display_access_right(this.pos.get_cashier()); + }, + + // block '+/-' button if user doesn't belong to the correct group + clickSwitchSign: function() { + if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_pos_negative_qty[0]) == -1) { + this.gui.show_popup('error',{ + 'title': _t('Negative Quantity - Unauthorized function'), + 'body': _t('Please ask your manager to do it.'), + }); + } + else { + return this._super(); + } + }, + + // block 'discount' or 'price' button if user doesn't belong to the correct group + clickChangeMode: function(event) { + if (event.currentTarget.attributes['data-mode'].nodeValue == 'discount' && + this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_pos_discount[0]) == -1) { + this.gui.show_popup('error',{ + 'title': _t('Discount - Unauthorized function'), + 'body': _t('Please ask your manager to do it.'), + }); + } + else if (event.currentTarget.attributes['data-mode'].nodeValue == 'price' && + this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_pos_change_unit_price[0]) == -1) { + this.gui.show_popup('error',{ + 'title': _t('Change Unit Price - Unauthorized function'), + 'body': _t('Please ask your manager to do it.'), + }); + } + else { + return this._super(event); + } + }, + }); +}); diff --git a/pos_access_right/static/src/xml/templates.xml b/pos_access_right/static/src/xml/templates.xml new file mode 100644 index 00000000..37422698 --- /dev/null +++ b/pos_access_right/static/src/xml/templates.xml @@ -0,0 +1,17 @@ + + + + +