Skip to content

Commit

Permalink
[MIG] pos_access_right: Migration to 16.0 - revision
Browse files Browse the repository at this point in the history
[MIG] pos_access_right: Migration to 16.0 - revision 2

[MIG] pos_access_right: Migration to 16.0 - adjusted test unit and add one line information in description.

[MIG] pos_access_right: Migration to 16.0 - repair test unit error.

[MIG] pos_access_right: Migration to 16.0 - still repair test unit error.

[MIG] pos_access_right: Migration to 16.0 - give access right for backspace button in keyboard and button remove in order line to delete order line.
  • Loading branch information
jumeldi74 committed Apr 27, 2023
1 parent 1bb1fbc commit e9bb9be
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 17 deletions.
8 changes: 4 additions & 4 deletions pos_access_right/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ Point of Sale - Extra Access Right
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github
:target: https://github.com/OCA/pos/tree/14.0/pos_access_right
:target: https://github.com/OCA/pos/tree/16.0/pos_access_right
:alt: OCA/pos
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/pos-14-0/pos-14-0-pos_access_right
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/184/14.0
:target: https://runbot.odoo-community.org/runbot/184/16.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends Odoo Point Of Sale features, restricting possibility to cashier to make some actions in the Point of Sale. This module will add the following groups to Odoo:

Expand Down Expand Up @@ -89,6 +89,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/pos <https://github.com/OCA/pos/tree/14.0/pos_access_right>`_ project on GitHub.
This module is part of the `OCA/pos <https://github.com/OCA/pos/tree/16.0/pos_access_right>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
7 changes: 7 additions & 0 deletions pos_access_right/demo/res_groups.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
/>
</record>

<record id="group_delete_order_line" model="res.groups">
<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"
Expand Down
2 changes: 1 addition & 1 deletion pos_access_right/i18n/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-03-09 22:22+0000\n"
"Last-Translator: mymage <[email protected]>\n"
Expand Down
2 changes: 1 addition & 1 deletion pos_access_right/i18n/pos_access_right.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
Expand Down
11 changes: 11 additions & 0 deletions pos_access_right/models/pos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class PosConfig(models.Model):
" Group to the Point of Sale Frontend.",
)

group_delete_order_line_id = fields.Many2one(
comodel_name="res.groups",
compute="_compute_groups",
string="Point of Sale - Delete Order Line",
help="This field is there to pass the id of the 'PoS - Delete Order Line'"
" Group to the Point of Sale Frontend.",
)

group_payment_id = fields.Many2one(
comodel_name="res.groups",
compute="_compute_groups",
Expand All @@ -68,6 +76,9 @@ def _compute_groups(self):
"group_delete_order_id": self.env.ref(
"pos_access_right.group_delete_order"
).id,
"group_delete_order_line_id": self.env.ref(
"pos_access_right.group_delete_order_line"
).id,
"group_payment_id": self.env.ref("pos_access_right.group_payment").id,
}
)
22 changes: 22 additions & 0 deletions pos_access_right/models/pos_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
class PosSession(models.Model):
_inherit = "pos.session"

def _get_pos_ui_res_users(self, params):
user_vals = super()._get_pos_ui_res_users(params)
user_id = user_vals.get("id")
if user_id:
user = self.env["res.users"].browse(user_id)
groups = user.groups_id
config = self.config_id
user_vals.update(
hasGroupPayment=config.group_payment_id in groups,
hasGroupDiscount=config.group_discount_id in groups,
hasGroupNegativeQty=config.group_negative_qty_id in groups,
hasGroupPriceControl=config.group_change_unit_price_id in groups,
hasGroupMultiOrder=config.group_multi_order_id in groups,
hasGroupDeleteOrder=config.group_delete_order_id in groups,
hasGroupDeleteOrderLine=config.group_delete_order_line_id in groups,
)
return user_vals

def _get_pos_ui_hr_employee(self, params):
employees = super()._get_pos_ui_hr_employee(params)
for employee in employees:
Expand Down Expand Up @@ -35,4 +53,8 @@ def _get_pos_ui_hr_employee(self, params):
True if config.group_delete_order_id in groups else False
)

employee["hasGroupDeleteOrderLine"] = (
True if config.group_delete_order_line_id 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 @@ -5,3 +5,4 @@ This module extends Odoo Point Of Sale features, restricting possibility to cash
* **PoS - Change Unit Price**: The cashier can change the unit price of a product in Point Of Sale;
* **PoS - Many Orders**: The cashier can many orders at the same time;
* **PoS - Delete Order**: The cashier can not delete a full order;
* **PoS - Delete Order Line**: The cashier can not delete an order line;
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 @@ -31,6 +31,11 @@
<field name="category_id" ref="base.module_category_usability" />
</record>

<record id="group_delete_order_line" model="res.groups">
<field name="name">Point of Sale - Delete Order Line</field>
<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" />
Expand Down
4 changes: 2 additions & 2 deletions pos_access_right/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Point of Sale - Extra Access Right</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/pos/tree/14.0/pos_access_right"><img alt="OCA/pos" src="https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/pos-14-0/pos-14-0-pos_access_right"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/184/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/pos/tree/16.0/pos_access_right"><img alt="OCA/pos" src="https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/pos-14-0/pos-14-0-pos_access_right"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/184/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module extends Odoo Point Of Sale features, restricting possibility to cashier to make some actions in the Point of Sale. This module will add the following groups to Odoo:</p>
<ul class="simple">
<li><strong>PoS - Negative Quantity</strong>: The cashier can sell negative quantity in Point Of Sale (ie, can return products);</li>
Expand Down Expand Up @@ -430,7 +430,7 @@ <h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/pos/tree/14.0/pos_access_right">OCA/pos</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/pos/tree/16.0/pos_access_right">OCA/pos</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion pos_access_right/static/src/js/ActionpadWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ odoo.define("pos_access_right.ActionpadWidget", function (require) {
const PosActionpadWidget = (ActionpadWidget) =>
class extends ActionpadWidget {
get hasPaymentControlRights() {
return this.env.pos.get_cashier().hasGroupPayment;
if (this.env.pos.config.module_pos_hr)
return this.env.pos.get_cashier().hasGroupPayment;
return this.env.pos.user.hasGroupPayment;
}
};

Expand Down
16 changes: 12 additions & 4 deletions pos_access_right/static/src/js/NumpadWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@ odoo.define("pos_access_right.NumpadWidget", function (require) {
get hasManualDiscount() {
const res = super.hasManualDiscount;
if (res) {
return this.env.pos.get_cashier().hasGroupDiscount;
if (this.env.pos.config.module_pos_hr)
return this.env.pos.get_cashier().hasGroupDiscount;
return this.env.pos.user.hasGroupDiscount;
}
return res;
}
get hasMinusControlRights() {
return this.env.pos.get_cashier().hasGroupNegativeQty;
if (this.env.pos.config.module_pos_hr)
return this.env.pos.get_cashier().hasGroupNegativeQty;
return this.env.pos.user.hasGroupNegativeQty;
}
get hasPriceControlRights() {
const res = super.hasPriceControlRights;
if (res) {
return this.env.pos.get_cashier().hasGroupPriceControl;
if (this.env.pos.config.module_pos_hr)
return this.env.pos.get_cashier().hasGroupPriceControl;
return this.env.pos.user.hasGroupPriceControl;
}
return res;
}

get hasDeleteOrderLineRights() {
return this.env.pos.get_cashier().hasGroupDeleteOrder;
if (this.env.pos.config.module_pos_hr)
return this.env.pos.get_cashier().hasGroupDeleteOrderLine;
return this.env.pos.user.hasGroupDeleteOrderLine;
}
};

Expand Down
9 changes: 7 additions & 2 deletions pos_access_right/static/src/js/TicketScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ odoo.define("pos_access_right.TicketScreen", function (require) {
const PosTicketScreen = (TicketScreen) =>
class extends TicketScreen {
get hasNewOrdersControlRights() {
return this.env.pos.get_cashier().hasGroupMultiOrder;
if (this.env.pos.config.module_pos_hr)
return this.env.pos.get_cashier().hasGroupMultiOrder;
return this.env.pos.user.hasGroupMultiOrder;
}

async _onDeleteOrder({detail: order}) {
if (this.env.pos.get_cashier().hasGroupDeleteOrder) {
if (
this.env.pos.get_cashier().hasGroupDeleteOrder &&
this.env.pos.user.hasGroupDeleteOrder
) {
return super._onDeleteOrder({detail: order});
}
return false;
Expand Down
20 changes: 20 additions & 0 deletions pos_access_right/static/src/js/models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
odoo.define("pos_access_right.models", function (require) {
"use strict";

const Registries = require("point_of_sale.Registries");
var {Order} = require("point_of_sale.models");

const PosAccessRightOrder = (Order) =>
class PosAccessRightOrder extends Order {
remove_orderline(line) {
if (
this.pos.get_cashier().hasGroupDeleteOrderLine &&
this.pos.user.hasGroupDeleteOrderLine
) {
return super.remove_orderline(line);
}
return false;
}
};
Registries.Model.extend(Order, PosAccessRightOrder);
});
20 changes: 18 additions & 2 deletions pos_access_right/tests/test_pos_access_right.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from odoo.tests.common import SavepointCase
from odoo.tests import TransactionCase, tagged

from odoo.addons.pos_hr.tests.test_frontend import TestPosHrHttpCommon

class TestUserRestriction(SavepointCase):

class TestUserRestriction(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down Expand Up @@ -50,5 +52,19 @@ def test_access_pos(self):
self.group_delete_order, self.pos_config_main.group_delete_order_id
)

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

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


@tagged("post_install", "-at_install")
class TestPosAccessRightHttpCommonUi(TestPosHrHttpCommon):
def test_01_load_employee(self):
self.main_pos_config.open_ui()

0 comments on commit e9bb9be

Please sign in to comment.