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.

176 lines
6.4 KiB

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