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 a993278

Browse files
committedFeb 24, 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 a993278

File tree

3 files changed

+93
-22
lines changed

3 files changed

+93
-22
lines changed
 

‎stock_inventory_verification_request/models/stock_slot_verification_request.py

+22-8
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

@@ -86,6 +86,8 @@ def _compute_created_inventory_count(self):
8686
states={"wait": [("readonly", False)]},
8787
tracking=True,
8888
)
89+
product_name = fields.Char("Product", related="product_id.name", store=True)
90+
product_default_code = fields.Char(related="product_id.default_code", store=True)
8991
lot_id = fields.Many2one(
9092
comodel_name="stock.production.lot",
9193
string="Lot",
@@ -120,16 +122,19 @@ def _compute_created_inventory_count(self):
120122
comodel_name="stock.inventory",
121123
string="Created Inventories",
122124
inverse_name="solving_slot_verification_request_id",
123-
help="These inventory adjustment were created from this SVR.",
125+
help="These inventory adjustments were created from this SVR.",
124126
)
125127
created_inventory_count = fields.Integer(compute="_compute_created_inventory_count")
128+
processed_by = fields.Many2one(
129+
"res.users",
130+
readonly=True,
131+
copy=False,
132+
help="User who has solved or cancelled the request.",
133+
)
126134

127135
@api.depends("location_id", "product_id", "lot_id", "state")
128136
def _compute_involved_move_lines(self):
129137
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.
133138
if rec.state == "open":
134139
rec.involved_move_line_ids = self.env["stock.move.line"].search(
135140
rec._get_involved_move_lines_domain()
@@ -172,13 +177,23 @@ def action_confirm(self):
172177
return True
173178

174179
def action_cancel(self):
175-
self.write({"state": "cancelled"})
180+
self.write(
181+
{
182+
"state": "cancelled",
183+
"processed_by": self.env.uid,
184+
}
185+
)
176186
if self.quant_id:
177187
self.quant_id.requested_verification = False
178188
return True
179189

180190
def action_solved(self):
181-
self.write({"state": "done"})
191+
self.write(
192+
{
193+
"state": "done",
194+
"processed_by": self.env.uid,
195+
}
196+
)
182197
if self.quant_id:
183198
self.quant_id.requested_verification = False
184199
return True
@@ -223,7 +238,6 @@ def action_create_inventory_adjustment(self):
223238
)
224239
action = self.env.ref("stock_inventory.action_view_inventory_group_form")
225240
result = action.read()[0]
226-
227241
res = self.env.ref("stock_inventory.view_inventory_group_form", False)
228242
result["views"] = [(res and res.id or False, "form")]
229243
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

+17-14
Original file line numberDiff line numberDiff line change
@@ -9,12 +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" />
20+
<field name="processed_by" />
1821
<field name="inventory_id" />
1922
<field name="state" />
2023
<field name="company_id" groups="base.group_multi_company" />
@@ -64,52 +67,51 @@
6467
<div
6568
class="oe_button_box"
6669
name="button_box"
67-
attrs="{'invisible':
68-
[('state', 'not in', ('open'))]}"
70+
attrs="{'invisible': [('state', 'not in', ('open'))]}"
6971
>
70-
<button
72+
<button
7173
name="action_view_inventories"
7274
type="object"
7375
class="oe_stat_button"
7476
icon="fa-building-o"
7577
attrs="{'invisible':[('created_inventory_count', '=', 0)]}"
7678
>
77-
<field
79+
<field
7880
name="created_inventory_count"
7981
widget="statinfo"
8082
help="Inventory Adjustments created from this SVR."
8183
modifiers="{'readonly': true}"
8284
string="Inv. Adj. Created"
8385
/>
84-
</button>
85-
<button
86+
</button>
87+
<button
8688
name="action_view_move_lines"
8789
type="object"
8890
class="oe_stat_button"
8991
icon="fa-arrows-h"
9092
>
91-
<field
93+
<field
9294
name="involved_move_line_count"
9395
widget="statinfo"
9496
help="Stock Moves related to the given location and product."
9597
modifiers="{'readonly': true}"
9698
string="Stock Moves Involved"
9799
/>
98-
</button>
99-
<button
100+
</button>
101+
<button
100102
name="action_view_quants"
101103
type="object"
102104
class="oe_stat_button"
103105
icon="fa-list"
104106
>
105-
<field
107+
<field
106108
name="involved_quant_count"
107109
widget="statinfo"
108110
help="Stock related to the given location and product."
109111
modifiers="{'readonly': true}"
110112
string="Stock Reviewed"
111113
/>
112-
</button>
114+
</button>
113115
</div>
114116
<div class="oe_title">
115117
<label string="Slot Verification Request" for="name" />
@@ -126,9 +128,10 @@
126128
name="company_id"
127129
groups="base.group_multi_company"
128130
/>
129-
<field name="create_uid" readonly="1" />
130131
<field name="create_date" readonly="1" />
132+
<field name="create_uid" readonly="1" invisible="1" />
131133
<field name="responsible_id" />
134+
<field name="processed_by" readonly="1" />
132135
<field name="inventory_id" />
133136
<field name="quant_id" />
134137
</group>

0 commit comments

Comments
 (0)
Please sign in to comment.