diff --git a/mrp_subcontracting_skip_no_negative/README.rst b/mrp_subcontracting_skip_no_negative/README.rst new file mode 100644 index 000000000..a6bd4982e --- /dev/null +++ b/mrp_subcontracting_skip_no_negative/README.rst @@ -0,0 +1,91 @@ +=================================== +MRP Subcontracting Skip No Negative +=================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/16.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 + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/129/16.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module skips the negative quantity check, provided by stock_no_negative, for +subcontracting receipts. + +Background: +~~~~~~~~~~~ + +Odoo processes subcontracting receipt in the order of: + +1. Transfer of the subcontracted product from the subcontractor location to the internal +location. +2. Production of the subcontracted product in the subcontractor location. + +This sequence does not represent the reality where production is done before transfer, and therefore +the above Step 1 would fail with negative stock in the subcontractor location, when stock_no_negative +is installed, unless the product/location is configured to allow negative stock. + +ref. https://github.com/odoo/odoo/pull/75065 + +**Table of contents** + +.. contents:: + :local: + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Quartile Limited + +Contributors +~~~~~~~~~~~~ + +* `Quartile `__: + + * Aung Ko Ko Lin + +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/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/__init__.py b/mrp_subcontracting_skip_no_negative/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mrp_subcontracting_skip_no_negative/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_subcontracting_skip_no_negative/__manifest__.py b/mrp_subcontracting_skip_no_negative/__manifest__.py new file mode 100644 index 000000000..2053ab7b5 --- /dev/null +++ b/mrp_subcontracting_skip_no_negative/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +{ + "name": "MRP Subcontracting Skip No Negative", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Quartile Limited, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "category": "Manufacturing", + "depends": ["mrp_subcontracting", "stock_no_negative"], + "installable": True, + "auto_install": True, +} diff --git a/mrp_subcontracting_skip_no_negative/models/__init__.py b/mrp_subcontracting_skip_no_negative/models/__init__.py new file mode 100644 index 000000000..6bda2d242 --- /dev/null +++ b/mrp_subcontracting_skip_no_negative/models/__init__.py @@ -0,0 +1 @@ +from . import stock_move diff --git a/mrp_subcontracting_skip_no_negative/models/stock_move.py b/mrp_subcontracting_skip_no_negative/models/stock_move.py new file mode 100644 index 000000000..9a08a15c5 --- /dev/null +++ b/mrp_subcontracting_skip_no_negative/models/stock_move.py @@ -0,0 +1,30 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo import models + + +class StockMove(models.Model): + _inherit = "stock.move" + + def _action_done(self, cancel_backorder=False): + moves_with_no_check = self.filtered(lambda x: x.is_subcontract).with_context( + skip_negative_qty_check=True + ) + # For rather unlikely occassions where linked production is not in the right + # state. + for move in moves_with_no_check: + production_move = self.search([("move_dest_ids", "=", move.id)]) + production = production_move.production_id + if production.reservation_state != "assigned": + production.action_assign() + if production.reservation_state == "assigned": + continue + moves_with_no_check -= move + res = super(StockMove, self - moves_with_no_check)._action_done( + cancel_backorder=cancel_backorder + ) + res += super(StockMove, moves_with_no_check)._action_done( + cancel_backorder=cancel_backorder + ) + return res diff --git a/mrp_subcontracting_skip_no_negative/readme/CONTRIBUTORS.rst b/mrp_subcontracting_skip_no_negative/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..cd4e44ca9 --- /dev/null +++ b/mrp_subcontracting_skip_no_negative/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Quartile `__: + + * Aung Ko Ko Lin diff --git a/mrp_subcontracting_skip_no_negative/readme/DESCRIPTION.rst b/mrp_subcontracting_skip_no_negative/readme/DESCRIPTION.rst new file mode 100644 index 000000000..0b6109705 --- /dev/null +++ b/mrp_subcontracting_skip_no_negative/readme/DESCRIPTION.rst @@ -0,0 +1,17 @@ +This module skips the negative quantity check, provided by stock_no_negative, for +subcontracting receipts. + +Background: +~~~~~~~~~~~ + +Odoo processes subcontracting receipt in the order of: + +1. Transfer of the subcontracted product from the subcontractor location to the internal +location. +2. Production of the subcontracted product in the subcontractor location. + +This sequence does not represent the reality where production is done before transfer, and therefore +the above Step 1 would fail with negative stock in the subcontractor location, when stock_no_negative +is installed, unless the product/location is configured to allow negative stock. + +ref. https://github.com/odoo/odoo/pull/75065 diff --git a/mrp_subcontracting_skip_no_negative/static/description/icon.png b/mrp_subcontracting_skip_no_negative/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_subcontracting_skip_no_negative/static/description/icon.png differ diff --git a/mrp_subcontracting_skip_no_negative/static/description/index.html b/mrp_subcontracting_skip_no_negative/static/description/index.html new file mode 100644 index 000000000..384babb2d --- /dev/null +++ b/mrp_subcontracting_skip_no_negative/static/description/index.html @@ -0,0 +1,429 @@ + + + + + + +MRP Subcontracting Skip No Negative + + + +
+

MRP Subcontracting Skip No Negative

+ + +

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

+

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

+
+

Background:

+

Odoo processes subcontracting receipt in the order of:

+

1. Transfer of the subcontracted product from the subcontractor location to the internal +location. +2. Production of the subcontracted product in the subcontractor location.

+

This sequence does not represent the reality where production is done before transfer, and therefore +the above Step 1 would fail with negative stock in the subcontractor location, when stock_no_negative +is installed, unless the product/location is configured to allow negative stock.

+

ref. https://github.com/odoo/odoo/pull/75065

+

Table of contents

+ +
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+ +
+
+

Authors

+
    +
  • Quartile Limited
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

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/__init__.py b/mrp_subcontracting_skip_no_negative/tests/__init__.py new file mode 100644 index 000000000..7e62122f1 --- /dev/null +++ b/mrp_subcontracting_skip_no_negative/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_subcontracting_skip_no_negative 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 new file mode 100644 index 000000000..46e6aa97c --- /dev/null +++ b/mrp_subcontracting_skip_no_negative/tests/test_mrp_subcontracting_skip_no_negative.py @@ -0,0 +1,50 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo.exceptions import ValidationError +from odoo.tests import Form + +from odoo.addons.mrp_subcontracting.tests.common import TestMrpSubcontractingCommon + + +class TestMrpSubcontractingSkipNoNegative(TestMrpSubcontractingCommon): + 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") + picking_form.partner_id = self.subcontractor_partner1 + with picking_form.move_ids_without_package.new() as move: + 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() + self.assertEqual(immediate_wizard.get("res_model"), "stock.immediate.transfer") + immediate_wizard_form = Form( + self.env[immediate_wizard["res_model"]].with_context( + **immediate_wizard["context"] + ) + ).save() + with self.assertRaises(ValidationError): + immediate_wizard_form.process() + + # Create component stock, and subcontracting receipt should now be successful. + self.env["stock.quant"].create( + { + "product_id": self.comp1.id, + "location_id": self.subcontractor_partner1.property_stock_subcontractor.id, + "quantity": 10, + } + ) + self.env["stock.quant"].create( + { + "product_id": self.comp2.id, + "location_id": self.subcontractor_partner1.property_stock_subcontractor.id, + "quantity": 10, + } + ) + immediate_wizard_form.process() + self.assertEqual(subcontracting_receipt.state, "done")