From 53f9cc41327a6cef92316176e2c742008c87cc45 Mon Sep 17 00:00:00 2001 From: GabbasovDinar Date: Mon, 29 Oct 2018 15:10:46 +0500 Subject: [PATCH] [MIG] pos_access_right: Migration to 12.0 [DOC] update README [FIX] fix variable name [REF] the pos.config model load all fields [DOC] update website link [LINT] fix lint errors [LINT] fix lint errors --- pos_access_right/README.rst | 106 -------------- pos_access_right/__init__.py | 1 - .../{__openerp__.py => __manifest__.py} | 9 +- pos_access_right/demo/res_groups.xml | 29 ++++ pos_access_right/demo/res_groups.yml | 26 ---- pos_access_right/models/__init__.py | 1 - pos_access_right/models/pos_config.py | 1 - pos_access_right/readme/CONFIGURE.rst | 1 + pos_access_right/readme/CONTRIBUTORS.rst | 1 + pos_access_right/readme/DESCRIPTION.rst | 7 + pos_access_right/readme/USAGE.rst | 3 + pos_access_right/security/res_groups.xml | 34 +++++ pos_access_right/security/res_groups.yml | 25 ---- .../static/src/js/pos_access_right.js | 130 ++++++++---------- 14 files changed, 139 insertions(+), 235 deletions(-) delete mode 100644 pos_access_right/README.rst rename pos_access_right/{__openerp__.py => __manifest__.py} (79%) create mode 100644 pos_access_right/demo/res_groups.xml delete mode 100644 pos_access_right/demo/res_groups.yml create mode 100644 pos_access_right/readme/CONFIGURE.rst create mode 100644 pos_access_right/readme/CONTRIBUTORS.rst create mode 100644 pos_access_right/readme/DESCRIPTION.rst create mode 100644 pos_access_right/readme/USAGE.rst create mode 100644 pos_access_right/security/res_groups.xml delete mode 100644 pos_access_right/security/res_groups.yml diff --git a/pos_access_right/README.rst b/pos_access_right/README.rst deleted file mode 100644 index 68f7ce93..00000000 --- a/pos_access_right/README.rst +++ /dev/null @@ -1,106 +0,0 @@ -.. 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 extends Odoo Point Of Sale features, restricting possibility -to cashier to make some actions in the Point of Sale (set discount, change -unit prices, etc...) - -this module can be usefull to limit errors and / or fraud. - -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; - -* PoS - Many Orders: The cashier can many orders at the same time; - -* PoS - Delete Order: The cashier can not delete a full order; - -.. image:: /pos_access_right/static/description/new_groups.png - -If a user doesn't belong to a group, he can not use the according feature. - -For example, here is the default numpad for the demo data user : - -.. image:: /pos_access_right/static/description/demo_numpad.png - -If the user try to use a forbidden feature, here is the warning displayed. - -.. image:: /pos_access_right/static/description/demo_error.png - -If the cashier changed, the new right are applied : - -.. image:: /pos_access_right/static/description/admin_numpad.png - -Installation -============ - -Normal installation. - -Configuration -============= - -Once installed, you have to give correct access right to your cashiers. - -Limits / Roadmap -================ - -The feature are only blocked on the Point of sale Frond End UI. it could be -interesting do the same in the back-end office for some of this blockages. - -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 index a0fdc10f..0650744f 100644 --- a/pos_access_right/__init__.py +++ b/pos_access_right/__init__.py @@ -1,2 +1 @@ -# -*- coding: utf-8 -*- from . import models diff --git a/pos_access_right/__openerp__.py b/pos_access_right/__manifest__.py similarity index 79% rename from pos_access_right/__openerp__.py rename to pos_access_right/__manifest__.py index ad024ef6..bac8865e 100644 --- a/pos_access_right/__openerp__.py +++ b/pos_access_right/__manifest__.py @@ -1,25 +1,24 @@ -# -*- 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', + 'version': '12.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': 'http://www.lalouve.net/', + 'website': 'http://www.github.com/OCA/pos', 'license': 'AGPL-3', 'depends': [ 'point_of_sale', ], 'data': [ - 'security/res_groups.yml', + 'security/res_groups.xml', 'static/src/xml/templates.xml', ], 'demo': [ - 'demo/res_groups.yml', + 'demo/res_groups.xml', ], 'installable': True, } diff --git a/pos_access_right/demo/res_groups.xml b/pos_access_right/demo/res_groups.xml new file mode 100644 index 00000000..bc7eef33 --- /dev/null +++ b/pos_access_right/demo/res_groups.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pos_access_right/demo/res_groups.yml b/pos_access_right/demo/res_groups.yml deleted file mode 100644 index fd74b5ec..00000000 --- a/pos_access_right/demo/res_groups.yml +++ /dev/null @@ -1,26 +0,0 @@ -# -*- 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_negative_qty}: - users: - - base.user_root - -- !record {model: res.groups, id: group_discount}: - users: - - base.user_root - - base.user_demo - -- !record {model: res.groups, id: group_change_unit_price}: - users: - - base.user_root - -- !record {model: res.groups, id: group_multi_order}: - users: - - base.user_root - -- !record {model: res.groups, id: group_delete_order}: - users: - - base.user_root diff --git a/pos_access_right/models/__init__.py b/pos_access_right/models/__init__.py index e77b6015..db8634ad 100644 --- a/pos_access_right/models/__init__.py +++ b/pos_access_right/models/__init__.py @@ -1,2 +1 @@ -# -*- 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 index be39876c..df19a678 100644 --- a/pos_access_right/models/pos_config.py +++ b/pos_access_right/models/pos_config.py @@ -1,4 +1,3 @@ -# -*- 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). diff --git a/pos_access_right/readme/CONFIGURE.rst b/pos_access_right/readme/CONFIGURE.rst new file mode 100644 index 00000000..ee6194f2 --- /dev/null +++ b/pos_access_right/readme/CONFIGURE.rst @@ -0,0 +1 @@ +Once installed, you have to give correct access right to your cashiers. diff --git a/pos_access_right/readme/CONTRIBUTORS.rst b/pos_access_right/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..9f76a75b --- /dev/null +++ b/pos_access_right/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Sylvain LE GAL diff --git a/pos_access_right/readme/DESCRIPTION.rst b/pos_access_right/readme/DESCRIPTION.rst new file mode 100644 index 00000000..f475ace9 --- /dev/null +++ b/pos_access_right/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +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); +* **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; +* **PoS - Many Orders**: The cashier can many orders at the same time; +* **PoS - Delete Order**: The cashier can not delete a full order; diff --git a/pos_access_right/readme/USAGE.rst b/pos_access_right/readme/USAGE.rst new file mode 100644 index 00000000..8471f7f9 --- /dev/null +++ b/pos_access_right/readme/USAGE.rst @@ -0,0 +1,3 @@ +.. 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 diff --git a/pos_access_right/security/res_groups.xml b/pos_access_right/security/res_groups.xml new file mode 100644 index 00000000..b9e71749 --- /dev/null +++ b/pos_access_right/security/res_groups.xml @@ -0,0 +1,34 @@ + + + + + + Point of Sale - Negative Quantity + + + + + Point of Sale - Discount + + + + + Point of Sale - Unit Price Change + + + + + Point of Sale - Many Orders + + + + + Point of Sale - Delete Order + + + + diff --git a/pos_access_right/security/res_groups.yml b/pos_access_right/security/res_groups.yml deleted file mode 100644 index 3813e4e8..00000000 --- a/pos_access_right/security/res_groups.yml +++ /dev/null @@ -1,25 +0,0 @@ -# -*- 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_negative_qty}: - name: Point of Sale - Negative Quantity - category_id: base.module_category_usability - -- !record {model: res.groups, id: group_discount}: - name: Point of Sale - Discount - category_id: base.module_category_usability - -- !record {model: res.groups, id: group_change_unit_price}: - name: Point of Sale - Unit Price Change - category_id: base.module_category_usability - -- !record {model: res.groups, id: group_multi_order}: - name: Point of Sale - Many Orders - category_id: base.module_category_usability - -- !record {model: res.groups, id: group_delete_order}: - name: Point of Sale - Delete Order - category_id: base.module_category_usability 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 2781c888..5995d94b 100644 --- a/pos_access_right/static/src/js/pos_access_right.js +++ b/pos_access_right/static/src/js/pos_access_right.js @@ -15,124 +15,114 @@ odoo.define('pos_access_right.pos_access_right', function (require) { 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_negative_qty_id[0]) != -1){ - $('.numpad-minus').removeClass('pos-disabled-mode'); - } - else{ + gui.Gui.prototype.display_access_right = function (user) { + if (user.groups_id.indexOf(this.pos.config.group_negative_qty_id[0]) === -1) { $('.numpad-minus').addClass('pos-disabled-mode'); + } else { + $('.numpad-minus').removeClass('pos-disabled-mode'); } - if (user.groups_id.indexOf(this.pos.config.group_discount_id[0]) != -1){ - $(".mode-button[data-mode='discount']").removeClass('pos-disabled-mode'); - } - else{ + if (user.groups_id.indexOf(this.pos.config.group_discount_id[0]) === -1) { $(".mode-button[data-mode='discount']").addClass('pos-disabled-mode'); + } else { + $(".mode-button[data-mode='discount']").removeClass('pos-disabled-mode'); } - if (user.groups_id.indexOf(this.pos.config.group_change_unit_price_id[0]) != -1){ - $(".mode-button[data-mode='price']").removeClass('pos-disabled-mode'); - } - else{ + if (user.groups_id.indexOf(this.pos.config.group_change_unit_price_id[0]) === -1) { $(".mode-button[data-mode='price']").addClass('pos-disabled-mode'); + } else { + $(".mode-button[data-mode='price']").removeClass('pos-disabled-mode'); } }; - -/* ******************************************************** -point_of_sale.models -******************************************************** */ - - // load extra data from 'pos_config' (ids of new groups) - models.load_fields("pos.config", "group_negative_qty_id"); - models.load_fields("pos.config", "group_discount_id"); - models.load_fields("pos.config", "group_change_unit_price_id"); - models.load_fields("pos.config", "group_multi_order_id"); - models.load_fields("pos.config", "group_delete_order_id"); - // 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); + models.PosModel.prototype.set_cashier = function (user) { + if (user.groups_id) { + this.gui.display_access_right(user); + } _set_cashier_.call(this, user); }; -/* ******************************************************** -chrome.OrderSelectorWidget -******************************************************** */ chrome.OrderSelectorWidget.include({ - neworder_click_handler: function(event, $el) { - if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_multi_order_id[0]) == -1) { - this.gui.show_popup('error',{ + /** + * Click new order + * @param {MouseEvent} event + * @param {HTMLElement | jQuery} $el + */ + neworder_click_handler: function (event, $el) { + if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_multi_order_id[0]) === -1) { + this.gui.show_popup('error', { 'title': _t('Many Orders - Unauthorized function'), 'body': _t('Please ask your manager to do it.'), }); - } - else { - return this._super(); + } else { + this._super(event, $el); } }, - deleteorder_click_handler: function(event, $el) { - if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_delete_order_id[0]) == -1) { - this.gui.show_popup('error',{ + + /** + * Click delete order + * @param {MouseEvent} event + * @param {HTMLElement | jQuery} $el + */ + deleteorder_click_handler: function (event, $el) { + if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_delete_order_id[0]) === -1) { + this.gui.show_popup('error', { 'title': _t('Delete Order - Unauthorized function'), 'body': _t('Please ask your manager to do it.'), }); - } - else { - return this._super(); + } else { + this._super(event, $el); } }, }); - -/* ******************************************************** -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() { + /** + * 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_negative_qty_id[0]) == -1) { - this.gui.show_popup('error',{ + /** + * Block '+/-' button if user doesn't belong to the correct group + * @returns {Object} + */ + clickSwitchSign: function () { + if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_negative_qty_id[0]) === -1) { + this.gui.show_popup('error', { 'title': _t('Negative Quantity - Unauthorized function'), 'body': _t('Please ask your manager to do it.'), }); - } - else { + } 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_discount_id[0]) == -1) { - this.gui.show_popup('error',{ + /** + * Block 'discount' or 'price' button if user doesn't belong to the correct group + * @param {MouseEvent} event + * @returns {Object} + */ + clickChangeMode: function (event) { + if (event.currentTarget.attributes['data-mode'].nodeValue === 'discount' && + this.pos.get_cashier().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 (event.currentTarget.attributes['data-mode'].nodeValue == 'price' && - this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_change_unit_price_id[0]) == -1) { - this.gui.show_popup('error',{ + } else if (event.currentTarget.attributes['data-mode'].nodeValue === 'price' && + this.pos.get_cashier().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.'), }); - } - else { + } else { return this._super(event); } },