From 97b40869c149417ee4d546268e1d68bc642481ba Mon Sep 17 00:00:00 2001 From: BernatPForgeFlow Date: Wed, 3 Jan 2024 17:00:22 +0100 Subject: [PATCH] [FIX] mrp_unbuild_subcontracting: Adapt logic for partial receipts in 16.0 --- mrp_unbuild_subcontracting/README.rst | 26 +++++++----- mrp_unbuild_subcontracting/__manifest__.py | 2 +- .../models/stock_move.py | 40 +----------------- .../models/stock_picking.py | 17 +------- .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 2 +- .../static/description/index.html | 41 ++++++++++--------- .../tests/test_mrp_unbuild_subcontracting.py | 30 ++++++++------ 8 files changed, 60 insertions(+), 99 deletions(-) diff --git a/mrp_unbuild_subcontracting/README.rst b/mrp_unbuild_subcontracting/README.rst index 531f0e0a2..956c69a9d 100644 --- a/mrp_unbuild_subcontracting/README.rst +++ b/mrp_unbuild_subcontracting/README.rst @@ -2,10 +2,13 @@ Unbuild orders with return subcontracting ========================================= -.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:11f2e6d4a0a7c585038a75213c3ea46945a33fa40ecde95aef22f0cc999c8853 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status @@ -14,18 +17,18 @@ Unbuild orders with return subcontracting :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html :alt: License: LGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github - :target: https://github.com/OCA/manufacture/tree/14.0/mrp_unbuild_subcontracting + :target: https://github.com/OCA/manufacture/tree/16.0/mrp_unbuild_subcontracting :alt: OCA/manufacture .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_unbuild_subcontracting + :target: https://translation.odoo-community.org/projects/manufacture-16-0/manufacture-16-0-mrp_unbuild_subcontracting :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/14.0 - :alt: Try me on Runbot +.. |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 + :alt: Try me on Runboat -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| -This module automatically creates a unbuild in draft state when a subcontracting picking return is created. In addition, when the picking is validated, the unbuild is also validated. +This module automatically creates an unbuild in draft state when a subcontracting picking return is created. In addition, when the picking is validated, the unbuild is also validated. To view the unbuilds created, you have to select the operation Subcontracted Unbuild Orders in debug mode **Table of contents** @@ -38,8 +41,8 @@ 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 `_. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -57,6 +60,7 @@ Contributors * `ForgeFlow `_: * Thiago Mulero + * Bernat Puig Maintainers ~~~~~~~~~~~ @@ -71,6 +75,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_unbuild_subcontracting/__manifest__.py b/mrp_unbuild_subcontracting/__manifest__.py index dfb10e612..ce35007ec 100644 --- a/mrp_unbuild_subcontracting/__manifest__.py +++ b/mrp_unbuild_subcontracting/__manifest__.py @@ -9,7 +9,7 @@ "when is returned a product subcontracted", "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/OCA/manufacture", - "depends": ["mrp_account", "mrp_subcontracting"], + "depends": ["mrp_account", "mrp_subcontracting_purchase"], "data": ["views/mrp_unbuild_views.xml"], "installable": True, } diff --git a/mrp_unbuild_subcontracting/models/stock_move.py b/mrp_unbuild_subcontracting/models/stock_move.py index f447c2eaa..05aa45209 100644 --- a/mrp_unbuild_subcontracting/models/stock_move.py +++ b/mrp_unbuild_subcontracting/models/stock_move.py @@ -1,6 +1,6 @@ from collections import defaultdict -from odoo import _, api, models +from odoo import _, models from odoo.exceptions import UserError from odoo.tools.float_utils import float_is_zero @@ -32,24 +32,6 @@ class StockMove(models.Model): ): raise UserError(_("To subcontract, use a planned transfer.")) subcontract_details_per_picking[move.picking_id].append((move, bom)) - move.write( - { - "is_subcontract": True, - } - ) - # CHECK ME: Partial receipt of subcontracting process - # and refund change move_orig_ids adding all - # subcontracting origin moves, because - # that we try to restore and keep consistent data structure - # https://github.com/odoo/odoo/blob/b57c1332251b1553f98b9ad16b45a47d4101ffb2/addons/stock/wizard/stock_picking_return.py#L151-L153 # noqa: B950 - if ( - len(move.mapped("move_orig_ids.move_orig_ids.production_id")) > 1 - and move.origin_returned_move_id - and move.origin_returned_move_id.id in move.move_orig_ids.ids - ): - move.write( - {"move_orig_ids": [(6, 0, move.origin_returned_move_id.ids)]} - ) move_to_not_merge |= move for picking, subcontract_details in subcontract_details_per_picking.items(): picking._subcontracted_produce_unbuild(subcontract_details) @@ -68,23 +50,3 @@ class StockMove(models.Model): merge=merge, merge_into=merge_into ) return result - - @api.model_create_multi - def create(self, vals_list): - for val in vals_list: - if val.get("move_dest_ids", False) and val.get("production_id", False): - if ( - self.env["mrp.production"] - .browse(val.get("production_id", False)) - .bom_id.type - == "subcontract" - ): - # When we have partial receive move_orig_ids - # keep first subcontracting manufacturing order moves link - # should be avoided this situation, to refund cases - self.browse(val.get("move_dest_ids", False)[0][1]).write( - { - "move_orig_ids": [(5, 0, 0)], - } - ) - return super().create(vals_list) diff --git a/mrp_unbuild_subcontracting/models/stock_picking.py b/mrp_unbuild_subcontracting/models/stock_picking.py index a6ce15893..e387ad09e 100644 --- a/mrp_unbuild_subcontracting/models/stock_picking.py +++ b/mrp_unbuild_subcontracting/models/stock_picking.py @@ -1,7 +1,6 @@ from datetime import timedelta -from odoo import _, fields, models -from odoo.exceptions import UserError +from odoo import fields, models from odoo.osv.expression import OR @@ -15,18 +14,6 @@ class StockPicking(models.Model): def _prepare_subcontract_unbuild_vals(self, subcontract_move, bom): subcontract_move.ensure_one() product = subcontract_move.product_id - mos = subcontract_move.mapped( - "origin_returned_move_id.move_orig_ids.production_id" - ) - if len(mos) > 1: - raise UserError( - _( - "It's not possible to create the subcontracting unbuild order\n" - "The subcontract move %(smn)s is linked with more than " - "one manufacturing order: %(jmm)s" - ) - % {"smn": subcontract_move.name, "jmm": ",".join(mos.mapped("name"))} - ) vals = { "company_id": subcontract_move.company_id.id, "product_id": product.id, @@ -41,7 +28,7 @@ class StockPicking(models.Model): "product_qty": subcontract_move.product_uom_qty, "picking_id": self.id, "is_subcontracted": True, - "mo_id": mos.id, + "mo_id": subcontract_move.move_orig_ids.move_orig_ids.production_id.id, "lot_id": subcontract_move.move_orig_ids.lot_ids.id, } return vals diff --git a/mrp_unbuild_subcontracting/readme/CONTRIBUTORS.rst b/mrp_unbuild_subcontracting/readme/CONTRIBUTORS.rst index da18dd75a..61c70d361 100644 --- a/mrp_unbuild_subcontracting/readme/CONTRIBUTORS.rst +++ b/mrp_unbuild_subcontracting/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * `ForgeFlow `_: * Thiago Mulero + * Bernat Puig diff --git a/mrp_unbuild_subcontracting/readme/DESCRIPTION.rst b/mrp_unbuild_subcontracting/readme/DESCRIPTION.rst index ce4f4d7df..e23d01a2c 100644 --- a/mrp_unbuild_subcontracting/readme/DESCRIPTION.rst +++ b/mrp_unbuild_subcontracting/readme/DESCRIPTION.rst @@ -1,2 +1,2 @@ -This module automatically creates a unbuild in draft state when a subcontracting picking return is created. In addition, when the picking is validated, the unbuild is also validated. +This module automatically creates an unbuild in draft state when a subcontracting picking return is created. In addition, when the picking is validated, the unbuild is also validated. To view the unbuilds created, you have to select the operation Subcontracted Unbuild Orders in debug mode diff --git a/mrp_unbuild_subcontracting/static/description/index.html b/mrp_unbuild_subcontracting/static/description/index.html index f5fef1720..5df0698cd 100644 --- a/mrp_unbuild_subcontracting/static/description/index.html +++ b/mrp_unbuild_subcontracting/static/description/index.html @@ -1,20 +1,20 @@ - + - + Unbuild orders with return subcontracting