mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[FIX] mrp_unbuild_subcontracting: Cannot unbuild subcontracting orders with many links
From version 16.0, when we create backorders we are not splitting the Origin Moves. For that reason, when we try to unbuild a subcontracting order that has more than origin move we cannot know which is the real origin. There has been a PR to fix this in Odoo here: https://github.com/odoo/odoo/pull/148262, but it was reverted after some time due to some problems on the splitting. If we want to allow this, we would need to propose a PR in Odoo that completely fixes this problem.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from odoo import fields, models
|
from odoo import _, fields, models
|
||||||
|
from odoo.exceptions import UserError
|
||||||
from odoo.osv.expression import OR
|
from odoo.osv.expression import OR
|
||||||
|
|
||||||
|
|
||||||
@@ -14,6 +15,18 @@ class StockPicking(models.Model):
|
|||||||
def _prepare_subcontract_unbuild_vals(self, subcontract_move, bom):
|
def _prepare_subcontract_unbuild_vals(self, subcontract_move, bom):
|
||||||
subcontract_move.ensure_one()
|
subcontract_move.ensure_one()
|
||||||
product = subcontract_move.product_id
|
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 = {
|
vals = {
|
||||||
"company_id": subcontract_move.company_id.id,
|
"company_id": subcontract_move.company_id.id,
|
||||||
"product_id": product.id,
|
"product_id": product.id,
|
||||||
@@ -28,7 +41,7 @@ class StockPicking(models.Model):
|
|||||||
"product_qty": subcontract_move.product_uom_qty,
|
"product_qty": subcontract_move.product_uom_qty,
|
||||||
"picking_id": self.id,
|
"picking_id": self.id,
|
||||||
"is_subcontracted": True,
|
"is_subcontracted": True,
|
||||||
"mo_id": subcontract_move.move_orig_ids.move_orig_ids.production_id.id,
|
"mo_id": mos.id,
|
||||||
"lot_id": subcontract_move.move_orig_ids.lot_ids.id,
|
"lot_id": subcontract_move.move_orig_ids.lot_ids.id,
|
||||||
}
|
}
|
||||||
return vals
|
return vals
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from odoo.exceptions import UserError
|
||||||
from odoo.tests import Form, TransactionCase
|
from odoo.tests import Form, TransactionCase
|
||||||
|
|
||||||
|
|
||||||
@@ -207,17 +208,21 @@ class TestSubcontractingPurchaseFlows(TransactionCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
return_wizard._onchange_picking_id()
|
return_wizard._onchange_picking_id()
|
||||||
return_id, _ = return_wizard._create_returns()
|
with self.assertRaises(UserError):
|
||||||
|
return_id, _ = return_wizard._create_returns()
|
||||||
|
|
||||||
return_picking = self.env["stock.picking"].browse(return_id)
|
# This part cannot be tested since we cannot unbuild
|
||||||
return_picking.move_ids.quantity_done = 3
|
# subcontracting orders with more than one origin.
|
||||||
return_picking.button_validate()
|
#
|
||||||
|
# return_picking = self.env["stock.picking"].browse(return_id)
|
||||||
self.assertEqual(po.order_line.qty_received, 6)
|
# return_picking.move_ids.quantity_done = 3
|
||||||
|
# return_picking.button_validate()
|
||||||
mo = picking_to_return.mapped("move_ids.move_orig_ids.production_id")
|
#
|
||||||
unbuild = self.env["mrp.unbuild"].search([("mo_id", "in", mo.ids)])
|
# self.assertEqual(po.order_line.qty_received, 6)
|
||||||
self.assertTrue(unbuild.exists())
|
#
|
||||||
|
# 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())
|
||||||
|
|
||||||
|
|
||||||
class TestSubcontractingTracking(TransactionCase):
|
class TestSubcontractingTracking(TransactionCase):
|
||||||
|
|||||||
Reference in New Issue
Block a user