From f9cdc192e14506d8800df5a94ae27cbd3319f4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Fri, 30 Aug 2024 16:51:16 +0200 Subject: [PATCH] [MIG] mrp_subcontracting_skip_no_negative: Migration to 14.0 TT50668 --- .../README.rst | 10 ++++----- .../__manifest__.py | 2 +- .../models/__init__.py | 1 - .../models/stock_move.py | 4 ++++ .../models/stock_picking.py | 22 ------------------- .../static/description/index.html | 6 ++--- ...est_mrp_subcontracting_skip_no_negative.py | 16 +++++++++----- .../mrp_subcontracting_skip_no_negative | 1 + .../setup.py | 6 +++++ 9 files changed, 31 insertions(+), 37 deletions(-) delete mode 100644 mrp_subcontracting_skip_no_negative/models/stock_picking.py create mode 120000 setup/mrp_subcontracting_skip_no_negative/odoo/addons/mrp_subcontracting_skip_no_negative create mode 100644 setup/mrp_subcontracting_skip_no_negative/setup.py diff --git a/mrp_subcontracting_skip_no_negative/README.rst b/mrp_subcontracting_skip_no_negative/README.rst index 527110e6e..2a7232281 100644 --- a/mrp_subcontracting_skip_no_negative/README.rst +++ b/mrp_subcontracting_skip_no_negative/README.rst @@ -17,13 +17,13 @@ MRP Subcontracting Skip No Negative :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github - :target: https://github.com/OCA/manufacture/tree/16.0/mrp_subcontracting_skip_no_negative + :target: https://github.com/OCA/manufacture/tree/14.0/mrp_subcontracting_skip_no_negative :alt: OCA/manufacture .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/manufacture-16-0/manufacture-16-0-mrp_subcontracting_skip_no_negative + :target: https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_subcontracting_skip_no_negative :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/manufacture&target_branch=16.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=14.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -57,7 +57,7 @@ Bug Tracker Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -89,6 +89,6 @@ 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/manufacture `_ project on GitHub. +This module is part of the `OCA/manufacture `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_subcontracting_skip_no_negative/__manifest__.py b/mrp_subcontracting_skip_no_negative/__manifest__.py index 3d624be50..d52868eee 100644 --- a/mrp_subcontracting_skip_no_negative/__manifest__.py +++ b/mrp_subcontracting_skip_no_negative/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) { "name": "MRP Subcontracting Skip No Negative", - "version": "16.0.1.0.1", + "version": "14.0.1.0.0", "license": "AGPL-3", "author": "Quartile Limited, Odoo Community Association (OCA)", "website": "https://github.com/OCA/manufacture", diff --git a/mrp_subcontracting_skip_no_negative/models/__init__.py b/mrp_subcontracting_skip_no_negative/models/__init__.py index a33bde1e8..6bda2d242 100644 --- a/mrp_subcontracting_skip_no_negative/models/__init__.py +++ b/mrp_subcontracting_skip_no_negative/models/__init__.py @@ -1,2 +1 @@ from . import stock_move -from . import stock_picking diff --git a/mrp_subcontracting_skip_no_negative/models/stock_move.py b/mrp_subcontracting_skip_no_negative/models/stock_move.py index 35a108879..60057dfdd 100644 --- a/mrp_subcontracting_skip_no_negative/models/stock_move.py +++ b/mrp_subcontracting_skip_no_negative/models/stock_move.py @@ -8,6 +8,10 @@ class StockMove(models.Model): _inherit = "stock.move" def _action_done(self, cancel_backorder=False): + # It is necessary to apply the key context to skip the error in the + # subcontracting process + if self.env.context.get("subcontract_move_id"): + self = self.with_context(skip_negative_qty_check=True) moves_with_no_check = self.filtered(lambda x: x.is_subcontract).with_context( skip_negative_qty_check=True ) diff --git a/mrp_subcontracting_skip_no_negative/models/stock_picking.py b/mrp_subcontracting_skip_no_negative/models/stock_picking.py deleted file mode 100644 index 015c8554a..000000000 --- a/mrp_subcontracting_skip_no_negative/models/stock_picking.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2023 Quartile Limited -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) - -from odoo import models - - -class StockPicking(models.Model): - _inherit = "stock.picking" - - def _action_done(self): - res = super()._action_done() - self._check_negative_quants_after_process() - return res - - def _check_negative_quants_after_process(self): - product_ids = self.mapped("move_ids.product_id.id") - quants = self.env["stock.quant"].search( - [ - ("product_id", "in", product_ids), - ] - ) - quants.check_negative_qty() diff --git a/mrp_subcontracting_skip_no_negative/static/description/index.html b/mrp_subcontracting_skip_no_negative/static/description/index.html index cde0c7112..3894fa59d 100644 --- a/mrp_subcontracting_skip_no_negative/static/description/index.html +++ b/mrp_subcontracting_skip_no_negative/static/description/index.html @@ -368,7 +368,7 @@ ul.auto-toc { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:be1748f4d86ee601f04fee6c3ecec9db99e0aff2f2628d99f01406f1a1e20cf5 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runboat

This module skips the negative quantity check, provided by stock_no_negative, for subcontracting receipts.

@@ -393,7 +393,7 @@ is installed, unless the product/location is configured to allow negative stock.

Bugs are tracked on GitHub 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.

+feedback.

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

@@ -422,7 +422,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

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/manufacture project on GitHub.

+

This module is part of the OCA/manufacture project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/mrp_subcontracting_skip_no_negative/tests/test_mrp_subcontracting_skip_no_negative.py b/mrp_subcontracting_skip_no_negative/tests/test_mrp_subcontracting_skip_no_negative.py index 46e6aa97c..4c298db12 100644 --- a/mrp_subcontracting_skip_no_negative/tests/test_mrp_subcontracting_skip_no_negative.py +++ b/mrp_subcontracting_skip_no_negative/tests/test_mrp_subcontracting_skip_no_negative.py @@ -8,6 +8,16 @@ from odoo.addons.mrp_subcontracting.tests.common import TestMrpSubcontractingCom class TestMrpSubcontractingSkipNoNegative(TestMrpSubcontractingCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + test_stock_no_negative=True, + ) + ) + def test_mrp_subcontracting_skip_no_negative(self): picking_form = Form(self.env["stock.picking"]) picking_form.picking_type_id = self.env.ref("stock.picking_type_in") @@ -16,12 +26,9 @@ class TestMrpSubcontractingSkipNoNegative(TestMrpSubcontractingCommon): move.product_id = self.finished move.product_uom_qty = 1 subcontracting_receipt = picking_form.save() - subcontracting_receipt = subcontracting_receipt.with_context( - test_stock_no_negative=True - ) subcontracting_receipt.action_confirm() self.assertEqual(subcontracting_receipt.state, "assigned") - immediate_wizard = subcontracting_receipt.button_validate() + immediate_wizard = subcontracting_receipt.sudo().button_validate() self.assertEqual(immediate_wizard.get("res_model"), "stock.immediate.transfer") immediate_wizard_form = Form( self.env[immediate_wizard["res_model"]].with_context( @@ -30,7 +37,6 @@ class TestMrpSubcontractingSkipNoNegative(TestMrpSubcontractingCommon): ).save() with self.assertRaises(ValidationError): immediate_wizard_form.process() - # Create component stock, and subcontracting receipt should now be successful. self.env["stock.quant"].create( { diff --git a/setup/mrp_subcontracting_skip_no_negative/odoo/addons/mrp_subcontracting_skip_no_negative b/setup/mrp_subcontracting_skip_no_negative/odoo/addons/mrp_subcontracting_skip_no_negative new file mode 120000 index 000000000..36e603e2b --- /dev/null +++ b/setup/mrp_subcontracting_skip_no_negative/odoo/addons/mrp_subcontracting_skip_no_negative @@ -0,0 +1 @@ +../../../../mrp_subcontracting_skip_no_negative \ No newline at end of file diff --git a/setup/mrp_subcontracting_skip_no_negative/setup.py b/setup/mrp_subcontracting_skip_no_negative/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_subcontracting_skip_no_negative/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)