Skip to content

Commit

Permalink
[FIX] mrp_subcontracting: record components
Browse files Browse the repository at this point in the history
Before this commit, for a subcontracted product with reserved available
tracked components, if at least one component is recorded but not all,
the "Record components" button isn't available anymore.

How to reproduce:
  - Create a product and create a subcontracting BOM for this product;
  - Add a tracked component for this product;
  - Add some qty. for the tracked component in the subcontracting loc.;
  - Create a receipt for the subcontracted product (for demand qty. more
    than 1) with the subcontractor as partner and confirm it:
    => The "Record components" button should be visible.
  - Record a part of the demand qty. then click on "Continue", then on
    "Discard":
    => The "Record components" button is now hidden.

It's because the button is hidden if all the MO are done or to close
(they are) and if all the tracked move lines have a SN/LN (they have as
they are reserved).

task-2604728

closes odoo#73780

Related: odoo/enterprise#19686
Signed-off-by: Arnold Moyaux <[email protected]>
  • Loading branch information
svs-odoo committed Jul 19, 2021
1 parent d3a0d2c commit 392bc27
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
20 changes: 13 additions & 7 deletions addons/mrp_subcontracting/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ def action_show_details(self):
subcontracted product. Otherwise use standard behavior.
"""
self.ensure_one()
if self.is_subcontract:
rounding = self.product_uom.rounding
production = self.move_orig_ids.production_id[-1:]
if self._has_tracked_subcontract_components() and\
float_compare(production.qty_produced, production.product_uom_qty, precision_rounding=rounding) < 0 and\
float_compare(self.quantity_done, self.product_uom_qty, precision_rounding=rounding) < 0:
return self._action_record_components()
if self._has_components_to_record():
return self._action_record_components()
action = super(StockMove, self).action_show_details()
if self.is_subcontract and self._has_tracked_subcontract_components():
action['views'] = [(self.env.ref('stock.view_stock_move_operations').id, 'form')]
Expand Down Expand Up @@ -167,6 +162,17 @@ def _get_subcontract_bom(self):
)
return bom

def _has_components_to_record(self):
""" Returns true if the move has still some tracked components to record. """
self.ensure_one()
if not self.is_subcontract:
return False
rounding = self.product_uom.rounding
production = self.move_orig_ids.production_id[-1:]
return self._has_tracked_subcontract_components() and\
float_compare(production.qty_produced, production.product_uom_qty, precision_rounding=rounding) < 0 and\
float_compare(self.quantity_done, self.product_uom_qty, precision_rounding=rounding) < 0

def _has_tracked_subcontract_components(self):
self.ensure_one()
return any(m.has_tracking != 'none' for m in self.move_orig_ids.production_id.move_raw_ids)
Expand Down
28 changes: 6 additions & 22 deletions addons/mrp_subcontracting/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import timedelta

from odoo import api, fields, models
from odoo.tools.float_utils import float_compare, float_is_zero
from odoo.tools.float_utils import float_compare


class StockPicking(models.Model):
Expand All @@ -22,19 +22,9 @@ def _compute_display_action_record_components(self):
if not picking._is_subcontract():
picking.display_action_record_components = False
continue
# Hide if no components are track
subcontracted_productions = picking._get_subcontracted_productions()
component_sub_moves = subcontracted_productions.mapped('move_raw_ids')
if all(subcontracted_move.has_tracking == 'none' for subcontracted_move in component_sub_moves):
picking.display_action_record_components = False
continue
# Hide if all tracked product move line have a lot and all productions are in rigth state
tracked_move_line = component_sub_moves.filtered(lambda sm: sm.has_tracking != 'none').move_line_ids
if all(sub_mo.state in ('to_close', 'done') for sub_mo in subcontracted_productions)\
and all(sub_sml.lot_id for sub_sml in tracked_move_line):
picking.display_action_record_components = False
continue
picking.display_action_record_components = True
# Hide if all tracked product move lines are already recorded.
picking.display_action_record_components = any(
move._has_components_to_record() for move in picking.move_lines)

# -------------------------------------------------------------------------
# Action methods
Expand Down Expand Up @@ -88,14 +78,8 @@ def _action_done(self):
def action_record_components(self):
self.ensure_one()
for move in self.move_lines:
if not move._has_tracked_subcontract_components():
continue
productions = move.move_orig_ids.production_id
productions_to_done = productions._subcontracting_filter_to_done()
production = (productions - productions_to_done)[-1:]
if not production:
continue
return move._action_record_components()
if move._has_components_to_record():
return move._action_record_components()

# -------------------------------------------------------------------------
# Subcontract helpers
Expand Down
1 change: 0 additions & 1 deletion addons/mrp_subcontracting/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

from . import test_subcontracting

2 changes: 2 additions & 0 deletions addons/mrp_subcontracting/tests/test_subcontracting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from odoo.tests import tagged


@tagged('post_install', '-at_install')
class TestSubcontractingBasic(TransactionCase):
def test_subcontracting_location_1(self):
Expand All @@ -17,6 +18,7 @@ def test_subcontracting_location_1(self):
self.assertTrue(company2.subcontracting_location_id)
self.assertTrue(self.env.company.subcontracting_location_id != company2.subcontracting_location_id)


class TestSubcontractingFlows(TestMrpSubcontractingCommon):
def test_flow_1(self):
""" Don't tick any route on the components and trigger the creation of the subcontracting
Expand Down

0 comments on commit 392bc27

Please sign in to comment.