Skip to content

Commit

Permalink
[FIX] stock_scrap_tier_validation: workaround added to escape client …
Browse files Browse the repository at this point in the history
…error when pressing scrap from picking

Co-authored-by: Eugene Molotov <[email protected]>
  • Loading branch information
StefanRijnhart and em230418 committed Feb 5, 2025
1 parent 1c4f350 commit 61c2ddc
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions stock_scrap_tier_validation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2023 Jarsa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import stock_picking
from . import stock_scrap
from . import tier_definition
25 changes: 25 additions & 0 deletions stock_scrap_tier_validation/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 360ERP (<https://www.360erp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class StockPicking(models.Model):
_inherit = "stock.picking"

def button_scrap(self):
"""Fix compatibility with stock_scrap_tier_validation.
The way that super opens the scrap form in a popup window prevents
the tier validation UI elements from being effective. The record is
only saved when closing the popup. Given that it's only possible to
check if the record needs validation after saving, the popup will
always raise the 'validation required' error which blocks saving it.
As a workaround, we open the unsaved scrap record in the main window
so that it can be saved first and then be requested validation for
in the usual way.
"""
action = super().button_scrap()
action.pop("target")
return action
6 changes: 6 additions & 0 deletions stock_scrap_tier_validation/tests/test_tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ def test_validation_stock_scrap(self):
scrap.with_user(self.test_user_1).validate_tier()
scrap.action_validate()
self.assertEqual(scrap.state, "done")

def test_stock_picking_scrap(self):
"""Scrapping from picking does not open in a popup"""
picking = self.env["stock.picking"].search([], limit=1)
action = picking.button_scrap()
self.assertFalse(action.get("target"))
36 changes: 36 additions & 0 deletions stock_scrap_tier_validation/views/stock_scrap_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,40 @@
</xpath>
</field>
</record>
<!--
Boost this minimal view with sheet and header tags,
for compatibility with base_tier_validation's automatic
view manipulation.
-->
<record id="stock_scrap_form_view2" model="ir.ui.view">
<field name="inherit_id" ref="stock.stock_scrap_form_view2" />
<field name="model">stock.scrap</field>
<field name="priority" eval="999" />
<field name="arch" type="xml">
<xpath expr="/form/group" position="before">
<header>
<!-- Include some buttons from the primary form -->
<button
name="action_validate"
attrs="{'invisible': [('state', '!=', 'draft')]}"
string="Validate"
type="object"
class="oe_highlight"
context="{'not_unlink_on_discard': True}"
data-hotkey="v"
/>
<field
name="state"
widget="statusbar"
statusbar_visible="draft,done"
/>
</header>
<sheet />
<footer position="replace" />
</xpath>
<sheet position="inside">
<xpath expr="/form/group" position="move" />
</sheet>
</field>
</record>
</odoo>

0 comments on commit 61c2ddc

Please sign in to comment.