Skip to content

Commit 8dccd54

Browse files
[IMP] product_lot_sequence: add new group to allow editing lot sequence attributes
1 parent 970fb47 commit 8dccd54

File tree

8 files changed

+108
-5
lines changed

8 files changed

+108
-5
lines changed

product_lot_sequence/README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Default Number of Digits for Product Sequence Generation
6161
The default is 7 digits. To change that to something else, go to the inventory
6262
configuration, find "Sequence Number of Digits" and change the number.
6363

64+
To allow a user without settings access rights to update generated lot sequence attributes,
65+
add them to the "Product Lot Sequence Manager: Only Product Lot Sequences" group.
66+
6467
Usage
6568
=====
6669

product_lot_sequence/__manifest__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
"name": "Product Lot Sequence",
66
"summary": """
77
Adds ability to define a lot sequence from the product""",
8-
"version": "16.0.1.0.2",
8+
"version": "16.0.1.0.3",
99
"license": "AGPL-3",
1010
"author": "ForgeFlow S.L., Odoo Community Association (OCA)",
1111
"website": "https://github.com/OCA/product-attribute",
1212
"depends": ["stock"],
1313
"data": [
14+
"security/lot_sequence_security.xml",
1415
"data/ir_config_parameter.xml",
1516
"views/product_views.xml",
1617
"views/res_config_settings_views.xml",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from odoo import SUPERUSER_ID, api
2+
3+
4+
def migrate(cr, version):
5+
env = api.Environment(cr, SUPERUSER_ID, {})
6+
sequences = (
7+
env["product.template"]
8+
.search(
9+
[
10+
("lot_sequence_id.code", "=", False),
11+
("lot_sequence_id", "!=", False),
12+
]
13+
)
14+
.mapped("lot_sequence_id")
15+
)
16+
if sequences:
17+
sequences.write({"code": "product_lot_sequence"})

product_lot_sequence/models/product.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def _create_lot_sequence(self, vals):
4747
padding = vals.get("lot_sequence_padding") or self.lot_sequence_padding
4848
seq = {
4949
"name": name,
50+
"code": "product_lot_sequence",
5051
"implementation": "no_gap",
5152
"prefix": prefix,
5253
"padding": padding,

product_lot_sequence/readme/CONFIGURE.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ Default Number of Digits for Product Sequence Generation
2020

2121
The default is 7 digits. To change that to something else, go to the inventory
2222
configuration, find "Sequence Number of Digits" and change the number.
23+
24+
To allow a user without settings access rights to update generated lot sequence attributes,
25+
add them to the "Product Lot Sequence Manager: Only Product Lot Sequences" group.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<odoo>
2+
<record model="res.groups" id="group_product_lot_sequence_manager">
3+
<field name="name">Manage Product Lot Sequence</field>
4+
</record>
5+
<record id="rule_ir_sequence_product_lot_sequence_only" model="ir.rule">
6+
<field
7+
name="name"
8+
>Product Lot Sequence Manager: only product lot sequences</field>
9+
<field name="model_id" ref="base.model_ir_sequence" />
10+
<field
11+
name="groups"
12+
eval="[Command.link(ref('product_lot_sequence.group_product_lot_sequence_manager'))]"
13+
/>
14+
<field name="domain_force">
15+
[
16+
("code", "=", "product_lot_sequence"),
17+
("company_id", "in", company_ids + [False]),
18+
]
19+
</field>
20+
</record>
21+
<record id="rule_ir_sequence_readonly" model="ir.rule">
22+
<field name="name">Read-Only Access to All Sequences</field>
23+
<field name="model_id" ref="base.model_ir_sequence" />
24+
<field name="domain_force">[(1, '=', 1)]</field>
25+
<field
26+
name="groups"
27+
eval="[Command.link(ref('product_lot_sequence.group_product_lot_sequence_manager'))]"
28+
/>
29+
<field name="perm_write" eval="False" />
30+
<field name="perm_create" eval="False" />
31+
<field name="perm_unlink" eval="False" />
32+
</record>
33+
<record id="access_ir_sequence_product_lot_sequence" model="ir.model.access">
34+
<field name="name">ir.sequence access for Product Lot Sequence Manager</field>
35+
<field name="model_id" ref="base.model_ir_sequence" />
36+
<field
37+
name="group_id"
38+
ref="product_lot_sequence.group_product_lot_sequence_manager"
39+
/>
40+
<field name="perm_read" eval="1" />
41+
<field name="perm_write" eval="1" />
42+
<field name="perm_create" eval="0" />
43+
<field name="perm_unlink" eval="0" />
44+
</record>
45+
</odoo>

product_lot_sequence/static/description/index.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/*
1010
:Author: David Goodger ([email protected])
11-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1516
1617
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1718
customize this style sheet.
@@ -274,7 +275,7 @@
274275
margin-left: 2em ;
275276
margin-right: 2em }
276277

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {
@@ -410,6 +411,8 @@ <h2><a class="toc-backref" href="#toc-entry-2">Lot Sequence policy</a></h2>
410411
<h2><a class="toc-backref" href="#toc-entry-3">Default Number of Digits for Product Sequence Generation</a></h2>
411412
<p>The default is 7 digits. To change that to something else, go to the inventory
412413
configuration, find “Sequence Number of Digits” and change the number.</p>
414+
<p>To allow a user without settings access rights to update generated lot sequence attributes,
415+
add them to the “Product Lot Sequence Manager: Only Product Lot Sequences” group.</p>
413416
</div>
414417
</div>
415418
<div class="section" id="usage">
@@ -473,7 +476,9 @@ <h2><a class="toc-backref" href="#toc-entry-9">Contributors</a></h2>
473476
<div class="section" id="maintainers">
474477
<h2><a class="toc-backref" href="#toc-entry-10">Maintainers</a></h2>
475478
<p>This module is maintained by the OCA.</p>
476-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
479+
<a class="reference external image-reference" href="https://odoo-community.org">
480+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
481+
</a>
477482
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
478483
mission is to support the collaborative development of Odoo features and
479484
promote its widespread use.</p>

product_lot_sequence/tests/test_product_lot_sequence.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from odoo import Command
2+
from odoo.exceptions import AccessError
13
from odoo.tests import Form
24
from odoo.tests.common import TransactionCase
35

@@ -138,3 +140,29 @@ def test_open_detailed_operations(self):
138140
self.assertEqual(
139141
new_next_sequence_number, seq.get_next_char(seq.number_next_actual)
140142
)
143+
144+
def test_product_sequence_access_right(self):
145+
self.assertEqual(self.stock_production_lot._get_sequence_policy(), "product")
146+
product = self.product_product.create(dict(name="Test", tracking="serial"))
147+
self.assertTrue(product.lot_sequence_id)
148+
product.lot_sequence_id.prefix = "Test/"
149+
stock_manager_group = self.env.ref("stock.group_stock_manager")
150+
test_user = self.env["res.users"].create(
151+
{
152+
"name": "Stock Manager User",
153+
"login": "stock_manager_user",
154+
"groups_id": [Command.set([stock_manager_group.id])],
155+
"email": "[email protected]",
156+
}
157+
)
158+
lot_seq_as_user = product.lot_sequence_id.with_user(test_user)
159+
with self.assertRaises(AccessError):
160+
lot_seq_as_user.prefix = "T/"
161+
lot_seq_manager_group = self.env.ref(
162+
"product_lot_sequence.group_product_lot_sequence_manager"
163+
)
164+
test_user.write({"groups_id": [Command.link(lot_seq_manager_group.id)]})
165+
# Retry as same user (now with new group)
166+
lot_seq_as_user = product.lot_sequence_id.with_user(test_user)
167+
lot_seq_as_user.prefix = "T/"
168+
self.assertEqual(lot_seq_as_user.prefix, "T/")

0 commit comments

Comments
 (0)