Skip to content

Commit

Permalink
[MIG] pos_operating_unit: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdidderen-nsi committed Jul 8, 2024
1 parent 50d0c93 commit c62964c
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 126 deletions.
11 changes: 7 additions & 4 deletions operating_unit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -441,7 +442,9 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<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>
Expand Down
6 changes: 3 additions & 3 deletions pos_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=========================
POS Operating Unit Access
=========================
========================
POS with Operating Units
========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand Down
5 changes: 3 additions & 2 deletions pos_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "POS Operating Unit Access",
"version": "14.0.1.0.0",
"name": "POS with Operating Units",
"version": "17.0.1.0.0",
"author": "Ilyas, Ooops404, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
"category": "Point of sale",
Expand All @@ -9,5 +9,6 @@
"data": [
"security/pos_security.xml",
"views/pos_views.xml",
"views/res_config_settings_views.xml",
],
}
1 change: 1 addition & 0 deletions pos_operating_unit/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from . import pos_order
from . import pos_session
from . import pos_payment
from . import res_config_settings
34 changes: 18 additions & 16 deletions pos_operating_unit/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ class POSOrder(models.Model):
)
config_id = fields.Many2one(related="session_id.config_id", readonly=True)

@api.model
def create(self, vals):
session_id = self.env["pos.session"].sudo().browse(vals.get("session_id"))
if session_id.config_id:
vals["operating_unit_ids"] = [
(6, 0, session_id.config_id.operating_unit_ids.ids)
]
return super(POSOrder, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
session_id = self.env["pos.session"].sudo().browse(vals.get("session_id"))
if session_id.config_id:
vals["operating_unit_ids"] = [
(6, 0, session_id.config_id.operating_unit_ids.ids)
]
return super().create(vals_list)


class POSOrderLine(models.Model):
Expand All @@ -30,11 +31,12 @@ class POSOrderLine(models.Model):
string="Operating Units",
)

@api.model
def create(self, vals):
order_id = self.env["pos.order"].sudo().browse(vals.get("order_id"))
if order_id.config_id:
vals["operating_unit_ids"] = [
(6, 0, order_id.config_id.operating_unit_ids.ids)
]
return super(POSOrderLine, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
order_id = self.env["pos.order"].sudo().browse(vals.get("order_id"))
if order_id.config_id:
vals["operating_unit_ids"] = [
(6, 0, order_id.config_id.operating_unit_ids.ids)
]
return super().create(vals_list)
17 changes: 9 additions & 8 deletions pos_operating_unit/models/pos_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ class POSPayment(models.Model):
)
config_id = fields.Many2one(related="session_id.config_id", readonly=True)

@api.model
def create(self, vals):
pos_order_id = self.env["pos.order"].sudo().browse(vals.get("pos_order_id"))
if pos_order_id.config_id:
vals["operating_unit_ids"] = [
(6, 0, pos_order_id.config_id.operating_unit_ids.ids)
]
return super(POSPayment, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
pos_order_id = self.env["pos.order"].sudo().browse(vals.get("pos_order_id"))
if pos_order_id.config_id:
vals["operating_unit_ids"] = [
(6, 0, pos_order_id.config_id.operating_unit_ids.ids)
]
return super().create(vals_list)
13 changes: 7 additions & 6 deletions pos_operating_unit/models/pos_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ class POSSession(models.Model):
string="Operating Units",
)

@api.model
def create(self, vals):
config_id = self.env["pos.config"].sudo().browse(vals.get("config_id"))
if config_id:
vals["operating_unit_ids"] = [(6, 0, config_id.operating_unit_ids.ids)]
return super(POSSession, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
config_id = self.env["pos.config"].sudo().browse(vals.get("config_id"))
if config_id:
vals["operating_unit_ids"] = [(6, 0, config_id.operating_unit_ids.ids)]
return super().create(vals_list)
10 changes: 10 additions & 0 deletions pos_operating_unit/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

pos_operating_unit_ids = fields.Many2many(
related="pos_config_id.operating_unit_ids",
readonly=False,
)
12 changes: 6 additions & 6 deletions pos_operating_unit/security/pos_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<record id="ir_rule_pos_config_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="point_of_sale.model_pos_config" />
<field name="domain_force">['|', ('operating_unit_ids', '=', False),
('operating_unit_ids', 'in', user.operating_unit_ids.ids)]</field>
('operating_unit_ids', 'in', operating_unit_ids)]</field>
<field name="name">POS Config allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
Expand All @@ -15,7 +15,7 @@
<record id="ir_rule_pos_session_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="point_of_sale.model_pos_session" />
<field name="domain_force">['|', ('operating_unit_ids', '=', False),
('operating_unit_ids', 'in', user.operating_unit_ids.ids)]</field>
('operating_unit_ids', 'in', operating_unit_ids)]</field>
<field name="name">POS Session allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
Expand All @@ -27,7 +27,7 @@
<record id="ir_rule_pos_order_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="point_of_sale.model_pos_order" />
<field name="domain_force">['|', ('operating_unit_ids', '=', False),
('operating_unit_ids', 'in', user.operating_unit_ids.ids)]</field>
('operating_unit_ids', 'in', operating_unit_ids)]</field>
<field name="name">POS Order allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
Expand All @@ -39,7 +39,7 @@
<record id="ir_rule_pos_order_line_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="point_of_sale.model_pos_order_line" />
<field name="domain_force">['|', ('operating_unit_ids', '=', False),
('operating_unit_ids', 'in', user.operating_unit_ids.ids)]</field>
('operating_unit_ids', 'in', operating_unit_ids)]</field>
<field name="name">POS Order Line allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
Expand All @@ -51,7 +51,7 @@
<record id="ir_rule_pos_payment_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="point_of_sale.model_pos_payment" />
<field name="domain_force">['|', ('operating_unit_ids', '=', False),
('operating_unit_ids', 'in', user.operating_unit_ids.ids)]</field>
('operating_unit_ids', 'in', operating_unit_ids)]</field>
<field name="name">POS Payment allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
Expand All @@ -63,7 +63,7 @@
<record id="ir_rule_report_pos_order_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="point_of_sale.model_report_pos_order" />
<field name="domain_force">['|', ('config_id.operating_unit_ids', '=', False),
('config_id.operating_unit_ids', 'in', user.operating_unit_ids.ids)]</field>
('config_id.operating_unit_ids', 'in', operating_unit_ids)]</field>
<field name="name">POS Order Report allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
Expand Down
6 changes: 3 additions & 3 deletions pos_operating_unit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>POS Operating Unit Access</title>
<title>POS with Operating Units</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,8 +360,8 @@
</style>
</head>
<body>
<div class="document" id="pos-operating-unit-access">
<h1 class="title">POS Operating Unit Access</h1>
<div class="document" id="pos-with-operating-units">
<h1 class="title">POS with Operating Units</h1>

<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
Expand Down
2 changes: 1 addition & 1 deletion pos_operating_unit/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import test_module
from . import test_pos_operating_unit
Original file line number Diff line number Diff line change
@@ -1,68 +1,67 @@
from odoo import fields
from odoo.exceptions import AccessError
from odoo.tests.common import TransactionCase
from odoo.models import Command

from odoo.addons.operating_unit.tests.common import OperatingUnitCommon

class TestModule(TransactionCase):
def setUp(self):
super(TestModule, self).setUp()
self.ResUsers = self.env["res.users"]
self.PosOrder = self.env["pos.order"]
self.pos_product = self.env.ref("point_of_sale.whiteboard_pen")
self.pricelist = self.env.ref("product.list0")

# Create a new pos config and open it
self.pos_config = self.env.ref("point_of_sale.pos_config_main").copy()
class TestPOSOperatingUnit(OperatingUnitCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.PosOrder = cls.env["pos.order"]
cls.pos_product = cls.env.ref("point_of_sale.whiteboard_pen")
cls.pricelist = cls.env["product.pricelist"].search([], limit=1)

# company
self.company = self.env.ref("base.main_company")
# group
self.group_user = self.env.ref("base.group_user")
self.group_pos_manager = self.env.ref("point_of_sale.group_pos_manager")
# Main Operating Unit
self.ou1 = self.env.ref("operating_unit.main_operating_unit")
# B2B Operating Unit
self.b2b = self.env.ref("operating_unit.b2b_operating_unit")
# Create a new pos config and open it
cls.pos_config = cls.env.ref("point_of_sale.pos_config_main").copy()
cls.group_pos_manager = cls.env.ref("point_of_sale.group_pos_manager")
cls.group_account_invoice = cls.env.ref("account.group_account_invoice")

self.pos_config.operating_unit_ids = [(6, 0, [self.ou1.id])]
self.pos_config.open_session_cb()
cls.pos_config.operating_unit_ids = [Command.set([cls.ou1.id])]
cls.pos_config.open_ui()

# Create users
self.user1_id = self._create_user(
"user_1",
[self.group_user, self.group_pos_manager],
self.company,
[self.ou1, self.b2b],
cls.user1.write(
{
"groups_id": [
Command.link(cls.group_pos_manager.id),
Command.link(cls.group_account_invoice.id),
],
"operating_unit_ids": [Command.link(cls.b2b.id)],
}
)
self.user2_id = self._create_user(
"user_2",
[self.group_user, self.group_pos_manager],
self.company,
[self.b2b],
cls.user2.write(
{
"groups_id": [
Command.link(cls.group_pos_manager.id),
Command.link(cls.group_account_invoice.id),
],
"operating_unit_ids": [Command.set([cls.b2b.id])],
}
)

def test_operating_unit_access_config(self):
config1_ids = self.env["pos.config"].with_user(self.user1_id).search([])
config1_ids = self.env["pos.config"].with_user(self.user1).search([])
self.assertIn(self.pos_config, config1_ids)
config2_ids = self.env["pos.config"].with_user(self.user2_id).search([])
config2_ids = self.env["pos.config"].with_user(self.user2).search([])
self.assertNotIn(self.pos_config, config2_ids)

def test_operating_unit_access_session(self):
self.pos_config.current_session_id.with_user(self.user1_id).read()
self.pos_config.current_session_id.with_user(self.user1).read()
with self.assertRaises(AccessError):
self.pos_config.current_session_id.with_user(self.user2_id).read()
self.pos_config.current_session_id.with_user(self.user2).read()

def test_operating_unit_access_order_and_line_and_payment(self):
order = self._create_order()
order.with_user(self.user1_id).read()
order.lines.with_user(self.user1_id).read()
order.with_user(self.user1).read()
order.lines.with_user(self.user1).read()
with self.assertRaises(AccessError):
order.with_user(self.user2_id).read()
order.with_user(self.user2).read()
with self.assertRaises(AccessError):
order.lines.with_user(self.user2_id).read()
order.payment_ids.with_user(self.user1_id).read()
order.lines.with_user(self.user2).read()
order.payment_ids.with_user(self.user1).read()
with self.assertRaises(AccessError):
order.payment_ids.with_user(self.user2_id).read()
order.payment_ids.with_user(self.user2).read()

def _create_order(self):
# Create order
Expand All @@ -71,6 +70,7 @@ def _create_order(self):
"id": "0006-001-0010",
"to_invoice": False,
"data": {
"date_order": fields.Datetime.to_string(fields.Datetime.now()),
"pricelist_id": self.pricelist.id,
"user_id": 1,
"name": "Order 0006-001-0010",
Expand All @@ -84,6 +84,7 @@ def _create_order(self):
{
"product_id": self.pos_product.id,
"qty": 1,
"price_unit": 1000,
"price_subtotal": 1000,
"price_subtotal_incl": 1000,
},
Expand Down Expand Up @@ -117,20 +118,3 @@ def _create_order(self):
result = self.PosOrder.create_from_ui([order_data])
order = self.PosOrder.browse(result[0].get("id"))
return order

def _create_user(self, login, groups, company, operating_units):
"""Create a user."""
group_ids = [group.id for group in groups]
user = self.ResUsers.with_context({"no_reset_password": True}).create(
{
"name": "Chicago Purchase User",
"login": login,
"password": "demo",
"email": "[email protected]",
"company_id": company.id,
"company_ids": [(4, company.id)],
"operating_unit_ids": [(4, ou.id) for ou in operating_units],
"groups_id": [(6, 0, group_ids)],
}
)
return user.id
Loading

0 comments on commit c62964c

Please sign in to comment.