Skip to content

Commit 61c2ddc

Browse files
[FIX] stock_scrap_tier_validation: workaround added to escape client error when pressing scrap from picking
Co-authored-by: Eugene Molotov <[email protected]>
1 parent 1c4f350 commit 61c2ddc

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2023 Jarsa
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4+
from . import stock_picking
45
from . import stock_scrap
56
from . import tier_definition
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2024 360ERP (<https://www.360erp.com>)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import models
5+
6+
7+
class StockPicking(models.Model):
8+
_inherit = "stock.picking"
9+
10+
def button_scrap(self):
11+
"""Fix compatibility with stock_scrap_tier_validation.
12+
13+
The way that super opens the scrap form in a popup window prevents
14+
the tier validation UI elements from being effective. The record is
15+
only saved when closing the popup. Given that it's only possible to
16+
check if the record needs validation after saving, the popup will
17+
always raise the 'validation required' error which blocks saving it.
18+
19+
As a workaround, we open the unsaved scrap record in the main window
20+
so that it can be saved first and then be requested validation for
21+
in the usual way.
22+
"""
23+
action = super().button_scrap()
24+
action.pop("target")
25+
return action

stock_scrap_tier_validation/tests/test_tier_validation.py

+6
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@ def test_validation_stock_scrap(self):
6464
scrap.with_user(self.test_user_1).validate_tier()
6565
scrap.action_validate()
6666
self.assertEqual(scrap.state, "done")
67+
68+
def test_stock_picking_scrap(self):
69+
"""Scrapping from picking does not open in a popup"""
70+
picking = self.env["stock.picking"].search([], limit=1)
71+
action = picking.button_scrap()
72+
self.assertFalse(action.get("target"))

stock_scrap_tier_validation/views/stock_scrap_view.xml

+36
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,40 @@
2121
</xpath>
2222
</field>
2323
</record>
24+
<!--
25+
Boost this minimal view with sheet and header tags,
26+
for compatibility with base_tier_validation's automatic
27+
view manipulation.
28+
-->
29+
<record id="stock_scrap_form_view2" model="ir.ui.view">
30+
<field name="inherit_id" ref="stock.stock_scrap_form_view2" />
31+
<field name="model">stock.scrap</field>
32+
<field name="priority" eval="999" />
33+
<field name="arch" type="xml">
34+
<xpath expr="/form/group" position="before">
35+
<header>
36+
<!-- Include some buttons from the primary form -->
37+
<button
38+
name="action_validate"
39+
attrs="{'invisible': [('state', '!=', 'draft')]}"
40+
string="Validate"
41+
type="object"
42+
class="oe_highlight"
43+
context="{'not_unlink_on_discard': True}"
44+
data-hotkey="v"
45+
/>
46+
<field
47+
name="state"
48+
widget="statusbar"
49+
statusbar_visible="draft,done"
50+
/>
51+
</header>
52+
<sheet />
53+
<footer position="replace" />
54+
</xpath>
55+
<sheet position="inside">
56+
<xpath expr="/form/group" position="move" />
57+
</sheet>
58+
</field>
59+
</record>
2460
</odoo>

0 commit comments

Comments
 (0)