You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
6.4 KiB

8 years ago
8 years ago
  1. /*
  2. Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
  3. @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  4. License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. */
  6. odoo.define('pos_access_right.pos_access_right', function (require) {
  7. "use strict";
  8. var screens = require('point_of_sale.screens');
  9. var chrome = require('point_of_sale.chrome');
  10. var models = require('point_of_sale.models');
  11. var gui = require('point_of_sale.gui');
  12. var core = require('web.core');
  13. var _t = core._t;
  14. /* ********************************************************
  15. point_of_sale.gui
  16. ******************************************************** */
  17. // New function 'display_access_right' to display disabled functions
  18. gui.Gui.prototype.display_access_right = function(user){
  19. if (user.groups_id.indexOf(this.pos.config.group_pos_negative_qty[0]) != -1){
  20. $('.numpad-minus').removeClass('pos-disabled-mode');
  21. }
  22. else{
  23. $('.numpad-minus').addClass('pos-disabled-mode');
  24. }
  25. if (user.groups_id.indexOf(this.pos.config.group_pos_discount[0]) != -1){
  26. $(".mode-button[data-mode='discount']").removeClass('pos-disabled-mode');
  27. }
  28. else{
  29. $(".mode-button[data-mode='discount']").addClass('pos-disabled-mode');
  30. }
  31. if (user.groups_id.indexOf(this.pos.config.group_pos_change_unit_price[0]) != -1){
  32. $(".mode-button[data-mode='price']").removeClass('pos-disabled-mode');
  33. }
  34. else{
  35. $(".mode-button[data-mode='price']").addClass('pos-disabled-mode');
  36. }
  37. if (user.groups_id.indexOf(this.pos.config.group_pos_delete_order_line[0]) != -1){
  38. $('.numpad-backspace').removeClass('pos-disabled-mode');
  39. }
  40. else{
  41. $('.numpad-backspace').addClass('pos-disabled-mode');
  42. }
  43. };
  44. /* ********************************************************
  45. point_of_sale.models
  46. ******************************************************** */
  47. // load extra data from 'pos_config' (ids of new groups)
  48. models.load_fields("pos.config", "group_pos_negative_qty");
  49. models.load_fields("pos.config", "group_pos_discount");
  50. models.load_fields("pos.config", "group_pos_change_unit_price");
  51. models.load_fields("pos.config", "group_pos_multi_order");
  52. models.load_fields("pos.config", "group_pos_delete_order");
  53. models.load_fields("pos.config", "group_pos_delete_order_line");
  54. // Overload 'set_cashier' function to display correctly
  55. // unauthorized function after cashier changed
  56. var _set_cashier_ = models.PosModel.prototype.set_cashier;
  57. models.PosModel.prototype.set_cashier = function(user){
  58. this.gui.display_access_right(user);
  59. _set_cashier_.call(this, user);
  60. };
  61. /* ********************************************************
  62. chrome.OrderSelectorWidget
  63. ******************************************************** */
  64. chrome.OrderSelectorWidget.include({
  65. neworder_click_handler: function(event, $el) {
  66. if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_pos_multi_order[0]) == -1) {
  67. this.gui.show_popup('error',{
  68. 'title': _t('Many Orders - Unauthorized function'),
  69. 'body': _t('Please ask your manager to do it.'),
  70. });
  71. }
  72. else {
  73. return this._super();
  74. }
  75. },
  76. deleteorder_click_handler: function(event, $el) {
  77. if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_pos_delete_order[0]) == -1) {
  78. this.gui.show_popup('error',{
  79. 'title': _t('Delete Order - Unauthorized function'),
  80. 'body': _t('Please ask your manager to do it.'),
  81. });
  82. }
  83. else {
  84. return this._super();
  85. }
  86. },
  87. });
  88. /* ********************************************************
  89. screens.NumpadWidget
  90. ******************************************************** */
  91. screens.NumpadWidget.include({
  92. // Overload 'start' function to display correctly unauthorized function
  93. // at the beginning of the session, based on current user
  94. start: function() {
  95. this._super();
  96. this.gui.display_access_right(this.pos.get_cashier());
  97. },
  98. // block '+/-' button if user doesn't belong to the correct group
  99. clickSwitchSign: function() {
  100. if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_pos_negative_qty[0]) == -1) {
  101. this.gui.show_popup('error',{
  102. 'title': _t('Negative Quantity - Unauthorized function'),
  103. 'body': _t('Please ask your manager to do it.'),
  104. });
  105. }
  106. else {
  107. return this._super();
  108. }
  109. },
  110. // block '+/-' button if user doesn't belong to the correct group
  111. clickDeleteLastChar: function() {
  112. if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_pos_delete_order_line[0]) == -1) {
  113. this.gui.show_popup('error',{
  114. 'title': _t('Delete Order Line - Unauthorized function'),
  115. 'body': _t('Please ask your manager to do it.'),
  116. });
  117. }
  118. else {
  119. return this._super();
  120. }
  121. },
  122. // block 'discount' or 'price' button if user doesn't belong to the correct group
  123. clickChangeMode: function(event) {
  124. if (event.currentTarget.attributes['data-mode'].nodeValue == 'discount' &&
  125. this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_pos_discount[0]) == -1) {
  126. this.gui.show_popup('error',{
  127. 'title': _t('Discount - Unauthorized function'),
  128. 'body': _t('Please ask your manager to do it.'),
  129. });
  130. }
  131. else if (event.currentTarget.attributes['data-mode'].nodeValue == 'price' &&
  132. this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_pos_change_unit_price[0]) == -1) {
  133. this.gui.show_popup('error',{
  134. 'title': _t('Change Unit Price - Unauthorized function'),
  135. 'body': _t('Please ask your manager to do it.'),
  136. });
  137. }
  138. else {
  139. return this._super(event);
  140. }
  141. },
  142. });
  143. });