Skip to content

Commit

Permalink
[ADD] stock_scrap_tier_validation_mrp
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanRijnhart committed Nov 25, 2024
1 parent 95f46ad commit 7e9edd7
Show file tree
Hide file tree
Showing 18 changed files with 726 additions and 4 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
11 changes: 7 additions & 4 deletions stock_scrap_tier_validation/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -446,7 +447,9 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
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"
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>
85 changes: 85 additions & 0 deletions stock_scrap_tier_validation_mrp/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
==============================================
Stock Scrap Tier Validation: MRP compatibility
==============================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:8e028a44ccdc9c18c36539e20b6e2b73f20b0f6a2cde7b40609c5c8cd19f08a7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-workflow/tree/17.0/stock_scrap_tier_validation_mrp
:alt: OCA/stock-logistics-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-17-0/stock-logistics-workflow-17-0-stock_scrap_tier_validation_mrp
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module fixes compatibility between ``stock_scrap_tier_validation``
and the ``mrp`` module from Odoo. When scrapping products directly from
the production order form, the scrap record will open in the main window
rather than in a popup form.

This solves a technical issue with the validation flow: it is only after
saving a record that validation can be requested, whereas in the case of
a popup window the record is only saved when closing the window. If
validation is required, this attempt to save the record will raise an
exception.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_scrap_tier_validation_mrp%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* 360ERP

Contributors
------------

- Stefan Rijnhart [email protected]

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/17.0/stock_scrap_tier_validation_mrp>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions stock_scrap_tier_validation_mrp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024 360ERP (<https://www.360erp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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

{
"name": "Stock Scrap Tier Validation: MRP compatibility",
"version": "17.0.1.0.0",
"category": "Stock",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "360ERP, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"auto_install": True,
"depends": [
"mrp",
"stock_scrap_tier_validation",
],
"data": [],
}
5 changes: 5 additions & 0 deletions stock_scrap_tier_validation_mrp/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2024 360ERP (<https://www.360erp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import mrp_production
from . import mrp_workorder
25 changes: 25 additions & 0 deletions stock_scrap_tier_validation_mrp/models/mrp_production.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 MrpProduction(models.Model):
_inherit = "mrp.production"

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
14 changes: 14 additions & 0 deletions stock_scrap_tier_validation_mrp/models/mrp_workorder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 360ERP (<https://www.360erp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class MrpWorkorder(models.Model):
_inherit = "mrp.workorder"

def button_scrap(self):
"""Fix compatibility with stock_scrap_tier_validation"""
action = super().button_scrap()
action.pop("target")
return action
3 changes: 3 additions & 0 deletions stock_scrap_tier_validation_mrp/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions stock_scrap_tier_validation_mrp/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Stefan Rijnhart <[email protected]>

9 changes: 9 additions & 0 deletions stock_scrap_tier_validation_mrp/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This module fixes compatibility between `stock_scrap_tier_validation` and the
`mrp` module from Odoo. When scrapping products directly from the production
order form, the scrap record will open in the main window rather than in a
popup form.

This solves a technical issue with the validation flow: it is only
after saving a record that validation can be requested, whereas in the case
of a popup window the record is only saved when closing the window. If
validation is required, this attempt to save the record will raise an exception.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7e9edd7

Please sign in to comment.