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 00000000..2c83d710 Binary files /dev/null and b/pos_access_right/static/description/icon.png differ 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 @@ + + + + +