Skip to content

Commit c387311

Browse files
committed
[COV] l10n_it_fiscal_document_type: Access
1 parent 58e0e79 commit c387311

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

l10n_it_fiscal_document_type/__manifest__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2017 Alessandro Camilli
22
# Copyright 2018 Sergio Zanchetta (Associazione PNLUG - Gruppo Odoo)
33
# Copyright 2018 Lorenzo Battistini (https://github.com/eLBati)
4+
# Copyright 2023 Simone Rubino - TAKOBI
45
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
56

67
{
@@ -12,7 +13,10 @@
1213
'website': 'https://github.com/OCA/l10n-italy'
1314
'/tree/12.0/l10n_it_fiscal_document_type',
1415
'license': 'AGPL-3',
15-
'depends': ['l10n_it_account'],
16+
'depends': [
17+
'l10n_it_account',
18+
'mail',
19+
],
1620
'data': [
1721
'views/fiscal_document_type_view.xml',
1822
'views/res_partner_view.xml',

l10n_it_fiscal_document_type/tests/test_doc_type.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Copyright 2017 Lorenzo Battistini
2+
# Copyright 2023 Simone Rubino - TAKOBI
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
24

3-
from odoo.tests.common import TransactionCase
5+
from odoo.addons.test_mail.tests.common import mail_new_test_user
6+
from odoo.exceptions import AccessError
7+
from odoo.tests.common import TransactionCase, users
48

59

610
class TestDocType(TransactionCase):
@@ -20,6 +24,11 @@ def setUp(self):
2024
"name": "FP",
2125
"fiscal_document_type_id": self.TD01.id,
2226
})
27+
self.adviser = mail_new_test_user(
28+
self.env,
29+
login="Adviser",
30+
groups='account.group_account_manager',
31+
)
2332

2433
def test_doc_type(self):
2534
self.TD01.journal_ids = [self.journalrec.id]
@@ -80,3 +89,59 @@ def test_doc_type_refund(self):
8089
invoice.journal_id.id
8190
)
8291
self.assertEqual(refund.fiscal_document_type_id.id, self.TD04.id)
92+
93+
@users("Adviser", "admin")
94+
def test_access(self):
95+
"""Users can only read fiscal documents,
96+
Users can't create/update/delete fiscal documents."""
97+
# Arrange
98+
user = self.env.user
99+
doc_type_model = self.doc_type_model
100+
doc_type = self.TD01
101+
user_doc_type_model = doc_type_model.sudo(user=user.id)
102+
user_doc_type = user_doc_type_model.browse(doc_type.id)
103+
# pre-condition: user_* objects are linked to current user
104+
root_user = self.env.ref("base.user_root")
105+
self.assertEqual(doc_type_model.env.uid, root_user.id)
106+
self.assertEqual(doc_type.env.uid, root_user.id)
107+
self.assertEqual(user_doc_type.env.uid, user.id)
108+
self.assertEqual(user_doc_type_model.env.uid, user.id)
109+
110+
# Act: Read
111+
code = user_doc_type.code
112+
113+
# Assert: Read
114+
self.assertEqual(code, "TD01")
115+
116+
# Act: Create
117+
with self.assertRaises(AccessError) as ae, self.env.cr.savepoint():
118+
user_doc_type_model.create({
119+
"code": "TC04",
120+
"name": "Test Code",
121+
})
122+
123+
# Assert: Create
124+
exc_message = ae.exception.args[0]
125+
self.assertIn("not allowed", exc_message)
126+
self.assertIn("Operation: create", exc_message)
127+
self.assertIn("Document model: " + user_doc_type_model._name, exc_message)
128+
129+
# Act: Update
130+
with self.assertRaises(AccessError) as ae, self.env.cr.savepoint():
131+
user_doc_type.name = "Update is forbidden"
132+
133+
# Assert: Update
134+
exc_message = ae.exception.args[0]
135+
self.assertIn("not allowed", exc_message)
136+
self.assertIn("Operation: write", exc_message)
137+
self.assertIn("Document model: " + user_doc_type_model._name, exc_message)
138+
139+
# Act: Delete
140+
with self.assertRaises(AccessError) as ae, self.env.cr.savepoint():
141+
user_doc_type.unlink()
142+
143+
# Assert: Delete
144+
exc_message = ae.exception.args[0]
145+
self.assertIn("not allowed", exc_message)
146+
self.assertIn("Operation: unlink", exc_message)
147+
self.assertIn("Document model: " + user_doc_type_model._name, exc_message)

0 commit comments

Comments
 (0)