Browse Source

Merge pull request #364 from KolushovAlexandr/12.0-pos_access_right-payment

[ADD] block payment button
pull/369/head
David Vidal 5 years ago
committed by GitHub
parent
commit
55bfcb20f0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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'))]"/> <field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record> </record>
<record id="group_payment" model="res.groups">
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>
</odoo> </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'" help="This field is there to pass the id of the 'PoS - Delete Order'"
" Group to the Point of Sale Frontend.") " 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 @api.multi
def _compute_group_negative_qty_id(self): def _compute_group_negative_qty_id(self):
for config in self: for config in self:
@ -72,3 +79,9 @@ class PosConfig(models.Model):
for config in self: for config in self:
self.group_delete_order_id = \ self.group_delete_order_id = \
self.env.ref('pos_access_right.group_delete_order') 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"/> <field name="category_id" ref="base.module_category_usability"/>
</record> </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> </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 { } else {
$(".mode-button[data-mode='price']").removeClass('pos-disabled-mode'); $(".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 // 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