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.

159 lines
6.2 KiB

  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. // New function 'display_access_right' to display disabled functions
  15. gui.Gui.prototype.display_access_right = function (user) {
  16. if (user.groups_id.indexOf(this.pos.config.group_negative_qty_id[0]) === -1) {
  17. $('.numpad-minus').addClass('pos-disabled-mode');
  18. } else {
  19. $('.numpad-minus').removeClass('pos-disabled-mode');
  20. }
  21. if (user.groups_id.indexOf(this.pos.config.group_discount_id[0]) === -1) {
  22. $(".mode-button[data-mode='discount']").addClass('pos-disabled-mode');
  23. } else {
  24. $(".mode-button[data-mode='discount']").removeClass('pos-disabled-mode');
  25. }
  26. if (user.groups_id.indexOf(this.pos.config.group_change_unit_price_id[0]) === -1) {
  27. $(".mode-button[data-mode='price']").addClass('pos-disabled-mode');
  28. } else {
  29. $(".mode-button[data-mode='price']").removeClass('pos-disabled-mode');
  30. }
  31. if (user.groups_id.indexOf(this.pos.config.group_payment_id[0]) === -1) {
  32. $(".button.pay").addClass('pos-disabled-mode');
  33. } else {
  34. $(".button.pay").removeClass('pos-disabled-mode');
  35. }
  36. };
  37. // Overload 'set_cashier' function to display correctly
  38. // unauthorized function after cashier changed
  39. var _set_cashier_ = models.PosModel.prototype.set_cashier;
  40. models.PosModel.prototype.set_cashier = function (user) {
  41. if (user.groups_id) {
  42. this.gui.display_access_right(user);
  43. }
  44. _set_cashier_.call(this, user);
  45. };
  46. chrome.OrderSelectorWidget.include({
  47. /**
  48. * Click new order
  49. * @param {MouseEvent} event
  50. * @param {HTMLElement | jQuery} $el
  51. */
  52. neworder_click_handler: function (event, $el) {
  53. if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_multi_order_id[0]) === -1) {
  54. this.gui.show_popup('error', {
  55. 'title': _t('Many Orders - Unauthorized function'),
  56. 'body': _t('Please ask your manager to do it.'),
  57. });
  58. } else {
  59. this._super(event, $el);
  60. }
  61. },
  62. /**
  63. * Click delete order
  64. * @param {MouseEvent} event
  65. * @param {HTMLElement | jQuery} $el
  66. */
  67. deleteorder_click_handler: function (event, $el) {
  68. if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_delete_order_id[0]) === -1) {
  69. this.gui.show_popup('error', {
  70. 'title': _t('Delete Order - Unauthorized function'),
  71. 'body': _t('Please ask your manager to do it.'),
  72. });
  73. } else {
  74. this._super(event, $el);
  75. }
  76. },
  77. });
  78. screens.NumpadWidget.include({
  79. /**
  80. * To display correctly unauthorized function at the beginning of the session, based on current user
  81. */
  82. start: function () {
  83. this._super();
  84. this.gui.display_access_right(this.pos.get_cashier());
  85. },
  86. /**
  87. * Block '+/-' button if user doesn't belong to the correct group
  88. * @returns {Object}
  89. */
  90. clickSwitchSign: function () {
  91. if (this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_negative_qty_id[0]) === -1) {
  92. this.gui.show_popup('error', {
  93. 'title': _t('Negative Quantity - Unauthorized function'),
  94. 'body': _t('Please ask your manager to do it.'),
  95. });
  96. } else {
  97. return this._super();
  98. }
  99. },
  100. /**
  101. * Block 'discount' or 'price' button if user doesn't belong to the correct group
  102. * @param {MouseEvent} event
  103. * @returns {Object}
  104. */
  105. clickChangeMode: function (event) {
  106. if (event.currentTarget.attributes['data-mode'].nodeValue === 'discount' &&
  107. this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_discount_id[0]) === -1) {
  108. this.gui.show_popup('error', {
  109. 'title': _t('Discount - Unauthorized function'),
  110. 'body': _t('Please ask your manager to do it.'),
  111. });
  112. } else if (event.currentTarget.attributes['data-mode'].nodeValue === 'price' &&
  113. this.pos.get_cashier().groups_id.indexOf(this.pos.config.group_change_unit_price_id[0]) === -1) {
  114. this.gui.show_popup('error', {
  115. 'title': _t('Change Unit Price - Unauthorized function'),
  116. 'body': _t('Please ask your manager to do it.'),
  117. });
  118. } else {
  119. return this._super(event);
  120. }
  121. },
  122. });
  123. screens.ActionpadWidget.include({
  124. /**
  125. * Block 'Payment' button if user doesn't belong to the correct group
  126. */
  127. renderElement: function() {
  128. var self = this;
  129. this._super();
  130. this.gui.display_access_right(this.pos.get_cashier());
  131. var button_pay_click_handler = $._data(this.$el.find(".button.pay")[0],"events").click[0].handler;
  132. this.$('.pay').off('click').click(function(){
  133. if (self.pos.get_cashier().groups_id.indexOf(self.pos.config.group_payment_id[0]) === -1) {
  134. self.gui.show_popup('error', {
  135. 'title': _t('Payment - Unauthorized function'),
  136. 'body': _t('Please ask your manager to do it.'),
  137. });
  138. } else {
  139. button_pay_click_handler();
  140. }
  141. });
  142. }
  143. });
  144. });