Browse Source

[MIG] pos_access_right : Migaration to 13.0

pull/396/head
Ammar Officewala 5 years ago
committed by Ammar Officewala
parent
commit
a092fb7cbe
  1. 1
      pos_access_right/README.rst
  2. 2
      pos_access_right/__manifest__.py
  3. 8
      pos_access_right/models/pos_config.py
  4. 1
      pos_access_right/readme/CONTRIBUTORS.rst
  5. 5
      pos_access_right/static/description/index.html
  6. 58
      pos_access_right/static/src/js/pos_access_right.js

1
pos_access_right/README.rst

@ -73,6 +73,7 @@ Contributors
~~~~~~~~~~~~
* Sylvain LE GAL <https://twitter.com/legalsylvain>
* Ammar Officewla <https://twitter.com/AmmarOfficewala>
Maintainers
~~~~~~~~~~~

2
pos_access_right/__manifest__.py

@ -4,7 +4,7 @@
{
'name': 'Point of Sale - Extra Access Right',
'version': '12.0.1.0.1',
'version': '13.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)',

8
pos_access_right/models/pos_config.py

@ -2,7 +2,7 @@
# @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
from odoo import fields, models
class PosConfig(models.Model):
@ -50,37 +50,31 @@ class PosConfig(models.Model):
help="This field is there to pass the id of the 'PoS - Payment'"
" Group to the Point of Sale Frontend.")
@api.multi
def _compute_group_negative_qty_id(self):
for config in self:
self.group_negative_qty_id = \
self.env.ref('pos_access_right.group_negative_qty')
@api.multi
def _compute_group_discount_id(self):
for config in self:
self.group_discount_id = \
self.env.ref('pos_access_right.group_discount')
@api.multi
def _compute_group_change_unit_price_id(self):
for config in self:
self.group_change_unit_price_id = \
self.env.ref('pos_access_right.group_change_unit_price')
@api.multi
def _compute_group_multi_order_id(self):
for config in self:
self.group_multi_order_id = \
self.env.ref('pos_access_right.group_multi_order')
@api.multi
def _compute_group_delete_order_id(self):
for config in self:
self.group_delete_order_id = \
self.env.ref('pos_access_right.group_delete_order')
@api.multi
def _compute_group_payment_id(self):
for config in self:
self.group_payment_id = \

1
pos_access_right/readme/CONTRIBUTORS.rst

@ -1 +1,2 @@
* Sylvain LE GAL <https://twitter.com/legalsylvain>
* Ammmar Officewala <https://twitter.com/AmmarOfficewala>

5
pos_access_right/static/description/index.html

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/pos/tree/12.0/pos_access_right"><img alt="OCA/pos" src="https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/pos-12-0/pos-12-0-pos_access_right"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/184/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/pos/tree/13.0/pos_access_right"><img alt="OCA/pos" src="https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/pos-12-0/pos-12-0-pos_access_right"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/184/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>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:</p>
<ul class="simple">
<li><strong>PoS - Negative Quantity</strong>: The cashier can sell negative quantity in Point Of Sale (ie, can return products);</li>
@ -419,6 +419,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<ul class="simple">
<li>Sylvain LE GAL &lt;<a class="reference external" href="https://twitter.com/legalsylvain">https://twitter.com/legalsylvain</a>&gt;</li>
<li>Ammar Officewala &lt;<a class="reference external" href="https://twitter.com/AmmarOfficewala">https://twitter.com/AmmarOfficewala</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
@ -428,7 +429,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/pos/tree/12.0/pos_access_right">OCA/pos</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/pos/tree/13.0/pos_access_right">OCA/pos</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>

58
pos_access_right/static/src/js/pos_access_right.js

@ -13,10 +13,28 @@ odoo.define('pos_access_right.pos_access_right', function (require) {
var models = require('point_of_sale.models');
var gui = require('point_of_sale.gui');
var core = require('web.core');
var DB = require('point_of_sale.DB');
var _t = core._t;
// New function 'display_access_right' to display disabled functions
gui.Gui.prototype.get_user_groups = function (){
var self = this;
if (this.pos.get_cashier() && this.pos.user && this.pos.get_cashier().user_id[0] == this.pos.user.id) {
return this.pos.user
}else{
return _.find(this.pos.users, function(user_id){
if (self.pos.get_cashier().user_id && self.pos.get_cashier().user_id[0] == user_id.id){
return user_id
}
})
}
},
gui.Gui.prototype.display_access_right = function (user) {
if (!user.groups_id){
user = this.get_user_groups();
}
if (user.groups_id.indexOf(
this.pos.config.group_negative_qty_id[0]) === -1) {
$('.numpad-minus').addClass('pos-disabled-mode');
@ -50,12 +68,21 @@ odoo.define('pos_access_right.pos_access_right', function (require) {
// unauthorized function after cashier changed
var _set_cashier_ = models.PosModel.prototype.set_cashier;
models.PosModel.prototype.set_cashier = function (user) {
if (user.groups_id) {
this.gui.display_access_right(user);
var user_groups = user
if (user.user_id && this.user && user.user_id[0] == this.user.id) {
user_groups = this.user
}else{
user_groups = _.find(this.users, function(user_id){
if (user.user_id && user.user_id[0] == user_id.id){
return user_id
}
})
}
if (user_groups) {
this.gui.display_access_right(user_groups);
}
_set_cashier_.call(this, user);
};
chrome.OrderSelectorWidget.include({
/**
@ -64,7 +91,10 @@ odoo.define('pos_access_right.pos_access_right', function (require) {
* @param {HTMLElement | jQuery} $el
*/
neworder_click_handler: function (event, $el) {
if (this.pos.get_cashier().groups_id.indexOf(
var user = [];
var self = this
var user = this.gui.get_user_groups()
if (!user || !user.groups_id || user.groups_id.indexOf(
this.pos.config.group_multi_order_id[0]) === -1) {
this.gui.show_popup('error', {
'title': _t('Many Orders - Unauthorized function'),
@ -81,7 +111,8 @@ odoo.define('pos_access_right.pos_access_right', function (require) {
* @param {HTMLElement | jQuery} $el
*/
deleteorder_click_handler: function (event, $el) {
if (this.pos.get_cashier().groups_id.indexOf(
var user = this.gui.get_user_groups()
if (!user || !user.groups_id || user.groups_id.indexOf(
this.pos.config.group_delete_order_id[0]) === -1) {
this.gui.show_popup('error', {
'title': _t('Delete Order - Unauthorized function'),
@ -109,7 +140,8 @@ odoo.define('pos_access_right.pos_access_right', function (require) {
* @returns {Object}
*/
clickSwitchSign: function () {
if (this.pos.get_cashier().groups_id.indexOf(
var user = this.gui.get_user_groups()
if (!user || !user.groups_id || user.groups_id.indexOf(
this.pos.config.group_negative_qty_id[0]) === -1) {
this.gui.show_popup('error', {
'title': _t('Negative Quantity - Unauthorized function'),
@ -128,16 +160,17 @@ odoo.define('pos_access_right.pos_access_right', function (require) {
*/
clickChangeMode: function (event) {
var target = event.currentTarget.attributes['data-mode'];
var user = this.gui.get_user_groups()
if (target.nodeValue === 'discount' &&
this.pos.get_cashier().groups_id.indexOf(
this.pos.config.group_discount_id[0]) === -1) {
(!user || !user.groups_id || user.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 (target.nodeValue === 'price' &&
this.pos.get_cashier().groups_id.indexOf(
this.pos.config.group_change_unit_price_id[0]) === -1) {
} else if (target.nodeValue === 'price' && (!user || !user.groups_id ||
user.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.'),
@ -160,7 +193,8 @@ odoo.define('pos_access_right.pos_access_right', function (require) {
var button_pay_click_handler = $._data(
this.$el.find(".button.pay")[0], "events").click[0].handler;
this.$('.pay').off('click').click(function () {
if (self.pos.get_cashier().groups_id.indexOf(
var user = self.gui.get_user_groups()
if (!user || !user.groups_id || user.groups_id.indexOf(
self.pos.config.group_payment_id[0]) === -1) {
self.gui.show_popup('error', {
'title': _t('Payment - Unauthorized function'),

Loading…
Cancel
Save