Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 44dc460

Browse files
committedFeb 25, 2025·
[IMP] stock_inventory_verification_request: improvements in order to see in the tree view who has processed the svr and some minor improvements
1 parent 6c43ef5 commit 44dc460

File tree

3 files changed

+94
-28
lines changed

3 files changed

+94
-28
lines changed
 

‎stock_inventory_verification_request/models/stock_slot_verification_request.py

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017-20 ForgeFlow S.L.
1+
# Copyright 2017-25 ForgeFlow S.L.
22
# (http://www.forgeflow.com)
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
44

@@ -42,9 +42,6 @@ def _compute_created_inventory_count(self):
4242
readonly=True,
4343
states={"wait": [("readonly", False)]},
4444
)
45-
inventory_id = fields.Many2one(
46-
comodel_name="stock.inventory", string="Inventory Adjustment", readonly=True
47-
)
4845
quant_id = fields.Many2one(
4946
comodel_name="stock.quant", string="Stock Line", readonly=True
5047
)
@@ -86,6 +83,8 @@ def _compute_created_inventory_count(self):
8683
states={"wait": [("readonly", False)]},
8784
tracking=True,
8885
)
86+
product_name = fields.Char("Product", related="product_id.name", store=True)
87+
product_default_code = fields.Char(related="product_id.default_code", store=True)
8988
lot_id = fields.Many2one(
9089
comodel_name="stock.production.lot",
9190
string="Lot",
@@ -120,16 +119,19 @@ def _compute_created_inventory_count(self):
120119
comodel_name="stock.inventory",
121120
string="Created Inventories",
122121
inverse_name="solving_slot_verification_request_id",
123-
help="These inventory adjustment were created from this SVR.",
122+
help="These inventory adjustments were created from this SVR.",
124123
)
125124
created_inventory_count = fields.Integer(compute="_compute_created_inventory_count")
125+
processed_by = fields.Many2one(
126+
"res.users",
127+
readonly=True,
128+
copy=False,
129+
help="User who has solved or cancelled the request.",
130+
)
126131

127132
@api.depends("location_id", "product_id", "lot_id", "state")
128133
def _compute_involved_move_lines(self):
129134
for rec in self:
130-
# Only compute when state is 'open' to prevent irrelevant data accumulation.
131-
# No need to accumulate movements for a 'solved' or 'cancelled'
132-
# SVR a lot of time after resolution.
133135
if rec.state == "open":
134136
rec.involved_move_line_ids = self.env["stock.move.line"].search(
135137
rec._get_involved_move_lines_domain()
@@ -172,13 +174,23 @@ def action_confirm(self):
172174
return True
173175

174176
def action_cancel(self):
175-
self.write({"state": "cancelled"})
177+
self.write(
178+
{
179+
"state": "cancelled",
180+
"processed_by": self.env.uid,
181+
}
182+
)
176183
if self.quant_id:
177184
self.quant_id.requested_verification = False
178185
return True
179186

180187
def action_solved(self):
181-
self.write({"state": "done"})
188+
self.write(
189+
{
190+
"state": "done",
191+
"processed_by": self.env.uid,
192+
}
193+
)
182194
if self.quant_id:
183195
self.quant_id.requested_verification = False
184196
return True
@@ -223,7 +235,6 @@ def action_create_inventory_adjustment(self):
223235
)
224236
action = self.env.ref("stock_inventory.action_view_inventory_group_form")
225237
result = action.read()[0]
226-
227238
res = self.env.ref("stock_inventory.view_inventory_group_form", False)
228239
result["views"] = [(res and res.id or False, "form")]
229240
result["res_id"] = inventory.id

‎stock_inventory_verification_request/tests/test_verification_request.py

+54
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,57 @@ def test_08_involved_quants_compute(self):
263263
test_svr.involved_quant_ids,
264264
"Quant3 not found in involved_quant_ids",
265265
)
266+
267+
def test_09_product_related_fields(self):
268+
svr = self.obj_svr.create(
269+
{
270+
"location_id": self.test_loc.id,
271+
"state": "wait",
272+
"product_id": self.product1.id,
273+
}
274+
)
275+
self.assertEqual(
276+
svr.product_name, "Test Product 1", "Product name not set correctly in SVR."
277+
)
278+
self.assertEqual(
279+
svr.product_default_code,
280+
"PROD1",
281+
"Product default code not set correctly in SVR.",
282+
)
283+
284+
def test_10_processed_by(self):
285+
svr = self.obj_svr.create(
286+
{
287+
"location_id": self.test_loc.id,
288+
"state": "wait",
289+
"product_id": self.product1.id,
290+
}
291+
)
292+
self.assertFalse(svr.processed_by)
293+
svr.action_confirm()
294+
self.assertFalse(
295+
svr.processed_by, "Processed By should remain empty after confirm."
296+
)
297+
svr.action_solved()
298+
self.assertEqual(
299+
svr.processed_by.id,
300+
self.env.uid,
301+
"Processed By not set correctly after solved action.",
302+
)
303+
svr_cancel = self.obj_svr.create(
304+
{
305+
"location_id": self.test_loc.id,
306+
"state": "wait",
307+
"product_id": self.product1.id,
308+
}
309+
)
310+
svr_cancel.action_confirm()
311+
self.assertFalse(
312+
svr_cancel.processed_by, "Processed By should remain empty after confirm."
313+
)
314+
svr_cancel.action_cancel()
315+
self.assertEqual(
316+
svr_cancel.processed_by.id,
317+
self.env.uid,
318+
"Processed By not set correctly after cancel action.",
319+
)

‎stock_inventory_verification_request/views/stock_slot_verification_request_view.xml

+18-17
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
<field name="arch" type="xml">
1010
<tree default_order="id desc">
1111
<field name="name" />
12+
<field name="product_id" invisible="1" />
13+
<field name="product_default_code" />
14+
<field name="product_name" />
1215
<field name="location_id" />
13-
<field name="product_id" />
1416
<field name="lot_id" groups="stock.group_production_lot" />
15-
<field name="create_uid" readonly="1" />
17+
<field name="create_uid" readonly="1" invisible="1" />
1618
<field name="create_date" readonly="1" />
1719
<field name="responsible_id" />
18-
<field name="inventory_id" />
20+
<field name="processed_by" />
1921
<field name="state" />
2022
<field name="company_id" groups="base.group_multi_company" />
2123
</tree>
@@ -64,52 +66,51 @@
6466
<div
6567
class="oe_button_box"
6668
name="button_box"
67-
attrs="{'invisible':
68-
[('state', 'not in', ('open'))]}"
69+
attrs="{'invisible': [('state', 'not in', ('open'))]}"
6970
>
70-
<button
71+
<button
7172
name="action_view_inventories"
7273
type="object"
7374
class="oe_stat_button"
7475
icon="fa-building-o"
7576
attrs="{'invisible':[('created_inventory_count', '=', 0)]}"
7677
>
77-
<field
78+
<field
7879
name="created_inventory_count"
7980
widget="statinfo"
8081
help="Inventory Adjustments created from this SVR."
8182
modifiers="{'readonly': true}"
8283
string="Inv. Adj. Created"
8384
/>
84-
</button>
85-
<button
85+
</button>
86+
<button
8687
name="action_view_move_lines"
8788
type="object"
8889
class="oe_stat_button"
8990
icon="fa-arrows-h"
9091
>
91-
<field
92+
<field
9293
name="involved_move_line_count"
9394
widget="statinfo"
9495
help="Stock Moves related to the given location and product."
9596
modifiers="{'readonly': true}"
9697
string="Stock Moves Involved"
9798
/>
98-
</button>
99-
<button
99+
</button>
100+
<button
100101
name="action_view_quants"
101102
type="object"
102103
class="oe_stat_button"
103104
icon="fa-list"
104105
>
105-
<field
106+
<field
106107
name="involved_quant_count"
107108
widget="statinfo"
108109
help="Stock related to the given location and product."
109110
modifiers="{'readonly': true}"
110111
string="Stock Reviewed"
111112
/>
112-
</button>
113+
</button>
113114
</div>
114115
<div class="oe_title">
115116
<label string="Slot Verification Request" for="name" />
@@ -126,11 +127,11 @@
126127
name="company_id"
127128
groups="base.group_multi_company"
128129
/>
129-
<field name="create_uid" readonly="1" />
130130
<field name="create_date" readonly="1" />
131+
<field name="create_uid" readonly="1" invisible="1" />
131132
<field name="responsible_id" />
132-
<field name="inventory_id" />
133-
<field name="quant_id" />
133+
<field name="processed_by" readonly="1" />
134+
<field name="quant_id" invisible="1" />
134135
</group>
135136
<group>
136137
<field name="notes" />

0 commit comments

Comments
 (0)
Please sign in to comment.