Browse Source

[ADD] block payment button

pull/364/head
KolushovAlexandr 5 years ago
parent
commit
f240251f2f
No known key found for this signature in database GPG Key ID: C3E04B793421FD2
  1. 4
      pos_access_right/demo/res_groups.xml
  2. 13
      pos_access_right/models/pos_config.py
  3. 5
      pos_access_right/security/res_groups.xml
  4. 29
      pos_access_right/static/src/js/pos_access_right.js

4
pos_access_right/demo/res_groups.xml

@ -26,4 +26,8 @@
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>
<record id="group_payment" model="res.groups">
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>
</odoo>

13
pos_access_right/models/pos_config.py

@ -43,6 +43,13 @@ class PosConfig(models.Model):
help="This field is there to pass the id of the 'PoS - Delete Order'"
" Group to the Point of Sale Frontend.")
group_payment_id = fields.Many2one(
comodel_name='res.groups',
compute='_compute_group_payment_id',
string='Point of Sale - Payment',
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:
@ -72,3 +79,9 @@ class PosConfig(models.Model):
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 = \
self.env.ref('pos_access_right.group_payment')

5
pos_access_right/security/res_groups.xml

@ -31,4 +31,9 @@
<field name="category_id" ref="base.module_category_usability"/>
</record>
<record id="group_payment" model="res.groups">
<field name="name">Point of Sale - Payment</field>
<field name="category_id" ref="base.module_category_usability"/>
</record>
</odoo>

29
pos_access_right/static/src/js/pos_access_right.js

@ -32,6 +32,11 @@ odoo.define('pos_access_right.pos_access_right', function (require) {
} else {
$(".mode-button[data-mode='price']").removeClass('pos-disabled-mode');
}
if (user.groups_id.indexOf(this.pos.config.group_payment_id[0]) === -1) {
$(".button.pay").addClass('pos-disabled-mode');
} else {
$(".button.pay").removeClass('pos-disabled-mode');
}
};
// Overload 'set_cashier' function to display correctly
@ -127,4 +132,28 @@ odoo.define('pos_access_right.pos_access_right', function (require) {
}
},
});
screens.ActionpadWidget.include({
/**
* Block 'Payment' button if user doesn't belong to the correct group
*/
renderElement: function() {
var self = this;
this._super();
this.gui.display_access_right(this.pos.get_cashier());
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(self.pos.config.group_payment_id[0]) === -1) {
self.gui.show_popup('error', {
'title': _t('Payment - Unauthorized function'),
'body': _t('Please ask your manager to do it.'),
});
} else {
button_pay_click_handler();
}
});
}
});
});
Loading…
Cancel
Save