Skip to content

Commit

Permalink
[MIG] pos_access_right: Migration to 16.0 - Add access right for Cash…
Browse files Browse the repository at this point in the history
… In/Out Button only for Accounting/Manager.
  • Loading branch information
jumeldi74 committed Jun 18, 2023
1 parent 32c1b4c commit c29160e
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pos_access_right/models/pos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ class PosConfig(models.Model):
comodel_name="res.groups",
compute="_compute_groups",
string="Point of Sale - Refund",
help="This field is to hide Refund Button for non Accounting/Pos Manager"
help="This field is to enable Refund Button only for Accounting/Pos Manager"
" Group to the Point of Sale Frontend.",
)

group_cashinout_action = fields.Many2one(
comodel_name="res.groups",
compute="_compute_groups",
string="Point of Sale - Cash In/Out",
help="This field is to enable Cash In/Out Button only for Accounting/Pos Manager"
" Group to the Point of Sale Frontend.",
)

Expand All @@ -91,5 +99,8 @@ def _compute_groups(self):
"group_refund_action": self.env.ref(
"pos_access_right.group_refund_action"
).id,
"group_cashinout_action": self.env.ref(
"pos_access_right.group_cashinout_action"
).id,
}
)
5 changes: 5 additions & 0 deletions pos_access_right/models/pos_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def _get_pos_ui_res_users(self, params):
hasGroupDeleteOrder=config.group_delete_order_id in groups,
hasGroupDeleteOrderLine=config.group_delete_order_line_id in groups,
hasGroupRefundAction=config.group_refund_action in groups,
hasGroupCashinoutAction=config.group_cashinout_action in groups,
)
return user_vals

Expand Down Expand Up @@ -62,4 +63,8 @@ def _get_pos_ui_hr_employee(self, params):
True if config.group_refund_action in groups else False
)

employee["hasGroupCashinoutAction"] = (
True if config.group_cashinout_action in groups else False
)

return employees
1 change: 1 addition & 0 deletions pos_access_right/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ This module extends Odoo Point Of Sale features, restricting possibility to cash
* **PoS - Delete Order**: The cashier can not delete a full order;
* **PoS - Delete Order Line**: The cashier can not delete an order line;
* **Pos - Refund Order**: The cashier can not do refund of an order;
* **Pos - Cash In/Out**: The cashier can not open Cash In/Out Popup;
5 changes: 5 additions & 0 deletions pos_access_right/security/res_groups.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@
<field name="category_id" ref="base.module_category_usability" />
</record>

<record id="group_cashinout_action" model="res.groups">
<field name="name">Point of Sale - Cash In/Out</field>
<field name="category_id" ref="base.module_category_usability" />
</record>

</odoo>
Binary file modified pos_access_right/static/description/new_groups.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions pos_access_right/static/src/js/CashMoveButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
odoo.define("pos_access_right.CashMoveButton", function (require) {
"use strict";
const Registries = require("point_of_sale.Registries");
const CashMoveButton = require("point_of_sale.CashMoveButton");

const PosCashMoveButton = (CashMoveButton) =>
class extends CashMoveButton {
async onClick() {
if (this.env.pos.config.module_pos_hr) {
if (this.env.pos.get_cashier().hasGroupCashinoutAction) {
return super.onClick();
}
} else if (this.env.pos.user.hasGroupCashinoutAction)
return super.onClick();

return false;
}
};

Registries.Component.extend(CashMoveButton, PosCashMoveButton);
return CashMoveButton;
});
7 changes: 7 additions & 0 deletions pos_access_right/tests/test_pos_access_right.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ def test_access_pos(self):
self.assertEqual(
self.group_refund_action, self.pos_config_main.group_refund_action
)

self.group_cashinout_action = self.env.ref(
"pos_access_right.group_cashinout_action"
)
self.assertEqual(
self.group_cashinout_action, self.pos_config_main.group_cashinout_action
)

0 comments on commit c29160e

Please sign in to comment.