[FIX] mrp_unbuild_subcontracting: Adapt logic for partial receipts in 16.0

This commit is contained in:
BernatPForgeFlow
2024-01-03 17:00:22 +01:00
parent 5d27a4a29d
commit 97b40869c1
8 changed files with 60 additions and 99 deletions

View File

@@ -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 <https://github.com/OCA/manufacture/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 <https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_unbuild_subcontracting%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_unbuild_subcontracting%0Aversion:%2016.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.
@@ -57,6 +60,7 @@ Contributors
* `ForgeFlow <https://www.forgeflow.com>`_:
* Thiago Mulero <thiago.mulero@forgeflow.com>
* Bernat Puig <bernat.puig@forgeflow.com>
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 <https://github.com/OCA/manufacture/tree/14.0/mrp_unbuild_subcontracting>`_ project on GitHub.
This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/16.0/mrp_unbuild_subcontracting>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -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,
}

View File

@@ -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)

View File

@@ -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

View File

@@ -1,3 +1,4 @@
* `ForgeFlow <https://www.forgeflow.com>`_:
* Thiago Mulero <thiago.mulero@forgeflow.com>
* Bernat Puig <bernat.puig@forgeflow.com>

View File

@@ -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

View File

@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Unbuild orders with return subcontracting</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
@@ -366,55 +366,58 @@ ul.auto-toc {
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:11f2e6d4a0a7c585038a75213c3ea46945a33fa40ecde95aef22f0cc999c8853
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/manufacture/tree/14.0/mrp_unbuild_subcontracting"><img alt="OCA/manufacture" src="https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_unbuild_subcontracting"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/129/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>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.
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/manufacture/tree/16.0/mrp_unbuild_subcontracting"><img alt="OCA/manufacture" src="https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/manufacture-16-0/manufacture-16-0-mrp_unbuild_subcontracting"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/manufacture&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>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</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#bug-tracker" id="id1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id5">Maintainers</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/manufacture/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_unbuild_subcontracting%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_unbuild_subcontracting%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id2">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id3">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<ul class="simple">
<li>ForgeFlow</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id4">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.forgeflow.com">ForgeFlow</a>:<ul>
<li>Thiago Mulero &lt;<a class="reference external" href="mailto:thiago.mulero&#64;forgeflow.com">thiago.mulero&#64;forgeflow.com</a>&gt;</li>
<li>Bernat Puig &lt;<a class="reference external" href="mailto:bernat.puig&#64;forgeflow.com">bernat.puig&#64;forgeflow.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">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>
<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>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/manufacture/tree/14.0/mrp_unbuild_subcontracting">OCA/manufacture</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/manufacture/tree/16.0/mrp_unbuild_subcontracting">OCA/manufacture</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>

View File

@@ -133,7 +133,7 @@ class TestSubcontractingPurchaseFlows(TransactionCase):
# Call the action to view the layers associated to the pickings
result1 = return_picking.action_view_stock_valuation_layers()
result2 = receipt.action_view_stock_valuation_layers()
layers1 = result1["domain"][4][2]
layers1 = result1["domain"][2][2]
layers2 = result2["domain"][2][2]
self.assertTrue(
layers1,
@@ -176,7 +176,7 @@ class TestSubcontractingPurchaseFlows(TransactionCase):
self.assertEqual(po.order_line.qty_received, 3)
receipt = po.picking_ids.filtered(lambda x: x.state != "done")
receipt.move_lines.quantity_done = 3
receipt.move_ids.quantity_done = 3
picking_to_return = receipt
result_dict = receipt.button_validate()
self.env["stock.backorder.confirmation"].with_context(
@@ -185,7 +185,7 @@ class TestSubcontractingPurchaseFlows(TransactionCase):
self.assertEqual(po.order_line.qty_received, 6)
receipt = po.picking_ids.filtered(lambda x: x.state != "done")
receipt.move_lines.quantity_done = 3
receipt.move_ids.quantity_done = 3
result_dict = receipt.button_validate()
self.env["stock.backorder.confirmation"].with_context(
**result_dict["context"]
@@ -194,25 +194,29 @@ class TestSubcontractingPurchaseFlows(TransactionCase):
self.assertEqual(len(po.picking_ids), 4)
return_form = Form(
self.env["stock.return.picking"].with_context(
active_id=picking_to_return.id, active_model="stock.picking"
return_wizard = (
self.env["stock.return.picking"]
.with_context(
active_id=picking_to_return.id, active_ids=picking_to_return.ids
)
.create(
{
"location_id": picking_to_return.location_id.id,
"picking_id": picking_to_return.id,
}
)
)
with return_form.product_return_moves.edit(0) as line:
line.quantity = 3
line.to_refund = True
return_wizard = return_form.save()
return_wizard._onchange_picking_id()
return_id, _ = return_wizard._create_returns()
return_picking = self.env["stock.picking"].browse(return_id)
return_picking.move_lines.quantity_done = 3
return_picking.move_ids.quantity_done = 3
return_picking.button_validate()
self.assertEqual(po.order_line.qty_received, 6)
mo = picking_to_return.mapped("move_lines.move_orig_ids.production_id")
unbuild = self.env["mrp.unbuild"].search([("mo_id", "=", mo.id)])
mo = picking_to_return.mapped("move_ids.move_orig_ids.production_id")
unbuild = self.env["mrp.unbuild"].search([("mo_id", "in", mo.ids)])
self.assertTrue(unbuild.exists())