Browse Source

[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
pull/304/head
GabbasovDinar 6 years ago
committed by Sylvain LE GAL
parent
commit
53f9cc4132
  1. 106
      pos_access_right/README.rst
  2. 1
      pos_access_right/__init__.py
  3. 9
      pos_access_right/__manifest__.py
  4. 29
      pos_access_right/demo/res_groups.xml
  5. 26
      pos_access_right/demo/res_groups.yml
  6. 1
      pos_access_right/models/__init__.py
  7. 1
      pos_access_right/models/pos_config.py
  8. 1
      pos_access_right/readme/CONFIGURE.rst
  9. 1
      pos_access_right/readme/CONTRIBUTORS.rst
  10. 7
      pos_access_right/readme/DESCRIPTION.rst
  11. 3
      pos_access_right/readme/USAGE.rst
  12. 34
      pos_access_right/security/res_groups.xml
  13. 25
      pos_access_right/security/res_groups.yml
  14. 128
      pos_access_right/static/src/js/pos_access_right.js

106
pos_access_right/README.rst

@ -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
<https://github.com/OCA/{project_repo}/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
<https://github.com/OCA/
pos/issues/new?body=module:%20
pos_access_right%0Aversion:%20
9.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Sylvain LE GAL <https://twitter.com/legalsylvain>
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.

1
pos_access_right/__init__.py

@ -1,2 +1 @@
# -*- coding: utf-8 -*-
from . import models from . import models

9
pos_access_right/__openerp__.py → pos_access_right/__manifest__.py

@ -1,25 +1,24 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>) # Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
'name': 'Point of Sale - Extra Access Right', 'name': 'Point of Sale - Extra Access Right',
'version': '9.0.1.0.0',
'version': '12.0.1.0.0',
'category': 'Point Of Sale', 'category': 'Point Of Sale',
'summary': 'Point of Sale - Extra Access Right for certain actions', 'summary': 'Point of Sale - Extra Access Right for certain actions',
'author': 'La Louve, GRAP, Odoo Community Association (OCA)', 'author': 'La Louve, GRAP, Odoo Community Association (OCA)',
'website': 'http://www.lalouve.net/',
'website': 'http://www.github.com/OCA/pos',
'license': 'AGPL-3', 'license': 'AGPL-3',
'depends': [ 'depends': [
'point_of_sale', 'point_of_sale',
], ],
'data': [ 'data': [
'security/res_groups.yml',
'security/res_groups.xml',
'static/src/xml/templates.xml', 'static/src/xml/templates.xml',
], ],
'demo': [ 'demo': [
'demo/res_groups.yml',
'demo/res_groups.xml',
], ],
'installable': True, 'installable': True,
} }

29
pos_access_right/demo/res_groups.xml

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="group_negative_qty" model="res.groups">
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>
<record id="group_discount" model="res.groups">
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin')), (4, ref('base.user_demo'))]"/>
</record>
<record id="group_change_unit_price" model="res.groups">
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>
<record id="group_multi_order" model="res.groups">
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>
<record id="group_delete_order" model="res.groups">
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>
</odoo>

26
pos_access_right/demo/res_groups.yml

@ -1,26 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# @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

1
pos_access_right/models/__init__.py

@ -1,2 +1 @@
# -*- coding: utf-8 -*-
from . import pos_config from . import pos_config

1
pos_access_right/models/pos_config.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>) # Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

1
pos_access_right/readme/CONFIGURE.rst

@ -0,0 +1 @@
Once installed, you have to give correct access right to your cashiers.

1
pos_access_right/readme/CONTRIBUTORS.rst

@ -0,0 +1 @@
* Sylvain LE GAL <https://twitter.com/legalsylvain>

7
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;

3
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

34
pos_access_right/security/res_groups.xml

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo noupdate="1">
<record id="group_negative_qty" model="res.groups">
<field name="name">Point of Sale - Negative Quantity</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="group_discount" model="res.groups">
<field name="name">Point of Sale - Discount</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="group_change_unit_price" model="res.groups">
<field name="name">Point of Sale - Unit Price Change</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="group_multi_order" model="res.groups">
<field name="name">Point of Sale - Many Orders</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="group_delete_order" model="res.groups">
<field name="name">Point of Sale - Delete Order</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
</odoo>

25
pos_access_right/security/res_groups.yml

@ -1,25 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# @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

128
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 core = require('web.core');
var _t = core._t; var _t = core._t;
/* ********************************************************
point_of_sale.gui
******************************************************** */
// New function 'display_access_right' to display disabled functions // 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'); $('.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'); $(".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'); $(".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 // Overload 'set_cashier' function to display correctly
// unauthorized function after cashier changed // unauthorized function after cashier changed
var _set_cashier_ = models.PosModel.prototype.set_cashier; var _set_cashier_ = models.PosModel.prototype.set_cashier;
models.PosModel.prototype.set_cashier = function(user){
models.PosModel.prototype.set_cashier = function (user) {
if (user.groups_id) {
this.gui.display_access_right(user); this.gui.display_access_right(user);
}
_set_cashier_.call(this, user); _set_cashier_.call(this, user);
}; };
/* ********************************************************
chrome.OrderSelectorWidget
******************************************************** */
chrome.OrderSelectorWidget.include({ 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'), 'title': _t('Many Orders - Unauthorized function'),
'body': _t('Please ask your manager to do it.'), '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'), 'title': _t('Delete Order - Unauthorized function'),
'body': _t('Please ask your manager to do it.'), 'body': _t('Please ask your manager to do it.'),
}); });
}
else {
return this._super();
} else {
this._super(event, $el);
} }
}, },
}); });
/* ********************************************************
screens.NumpadWidget
******************************************************** */
screens.NumpadWidget.include({ 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._super();
this.gui.display_access_right(this.pos.get_cashier()); 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'), 'title': _t('Negative Quantity - Unauthorized function'),
'body': _t('Please ask your manager to do it.'), 'body': _t('Please ask your manager to do it.'),
}); });
}
else {
} else {
return this._super(); 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'), 'title': _t('Discount - Unauthorized function'),
'body': _t('Please ask your manager to do it.'), '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'), 'title': _t('Change Unit Price - Unauthorized function'),
'body': _t('Please ask your manager to do it.'), 'body': _t('Please ask your manager to do it.'),
}); });
}
else {
} else {
return this._super(event); return this._super(event);
} }
}, },

Loading…
Cancel
Save