Browse Source

[ADD] new module 'pos_access_right'

pull/396/head
Sylvain LE GAL 9 years ago
committed by Ammar Officewala
parent
commit
a0208a7aa1
  1. 84
      pos_access_right/README.rst
  2. 2
      pos_access_right/__init__.py
  3. 25
      pos_access_right/__openerp__.py
  4. 18
      pos_access_right/demo/res_groups.yml
  5. 2
      pos_access_right/models/__init__.py
  6. 52
      pos_access_right/models/pos_config.py
  7. 17
      pos_access_right/security/res_groups.yml
  8. BIN
      pos_access_right/static/description/icon.png
  9. 12
      pos_access_right/static/src/css/pos_access_right.css
  10. 108
      pos_access_right/static/src/js/pos_access_right.js
  11. 17
      pos_access_right/static/src/xml/templates.xml

84
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
<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.

2
pos_access_right/__init__.py

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

25
pos_access_right/__openerp__.py

@ -0,0 +1,25 @@
# -*- 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).
{
'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,
}

18
pos_access_right/demo/res_groups.yml

@ -0,0 +1,18 @@
# -*- 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_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

2
pos_access_right/models/__init__.py

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

52
pos_access_right/models/pos_config.py

@ -0,0 +1,52 @@
# -*- 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).
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')

17
pos_access_right/security/res_groups.yml

@ -0,0 +1,17 @@
# -*- 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_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

BIN
pos_access_right/static/description/icon.png

After

Width: 64  |  Height: 64  |  Size: 4.3 KiB

12
pos_access_right/static/src/css/pos_access_right.css

@ -0,0 +1,12 @@
/*
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).
*/
.pos-disabled-mode {
color: #bbb !important;
}
.pos-disabled-mode:hover {
background: #e2e2e2 !important;
}

108
pos_access_right/static/src/js/pos_access_right.js

@ -0,0 +1,108 @@
/*
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.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);
}
},
});
});

17
pos_access_right/static/src/xml/templates.xml

@ -0,0 +1,17 @@
<?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>
<template id="assets_frontend" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_access_right/static/src/js/pos_access_right.js"/>
</xpath>
<xpath expr="//link[@id='pos-stylesheet']" position="after">
<link rel="stylesheet" href="/pos_access_right/static/src/css/pos_access_right.css" />
</xpath>
</template>
</odoo>
Loading…
Cancel
Save