From dd1ea09f34cffe40a6ae5b751525cad102494e7b Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Thu, 21 Oct 2021 12:38:44 +0000 Subject: [PATCH] [FIX] mrp_subcontracting, stock: don't change loc when dupe SN Previous task: odoo/odoo#61287 improved warnings for when using a duplicate SN, including an auto-update of the source location when appropriate. Unfortunately the auto-update is too risky when registering a subcontracting SN tracked components. Instead, we no longer update the source location when in a subcontracting situation and update the warning message to match the expected flow to fix the issue. closes odoo/odoo#79334 Task: 2669180 X-original-commit: a430c4d7d6e2a02ef9b3905b554a779fc1643bcf Signed-off-by: Arnold Moyaux Signed-off-by: Tiffany Chang --- .../i18n/mrp_subcontracting.pot | 7 +++++++ addons/mrp_subcontracting/models/__init__.py | 1 + .../models/stock_move_line.py | 20 +++++++++++++++++++ addons/stock/i18n/stock.pot | 8 +++++--- addons/stock/models/stock_quant.py | 12 ++++++----- 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 addons/mrp_subcontracting/models/stock_move_line.py diff --git a/addons/mrp_subcontracting/i18n/mrp_subcontracting.pot b/addons/mrp_subcontracting/i18n/mrp_subcontracting.pot index 31bea2e6a94..47fd203201c 100644 --- a/addons/mrp_subcontracting/i18n/mrp_subcontracting.pot +++ b/addons/mrp_subcontracting/i18n/mrp_subcontracting.pot @@ -107,6 +107,13 @@ msgstr "" msgid "Mandatory" msgstr "" +#. module: stock +#: code:addons/mrp_subcontracting/models/stock_move_line.py:0 +#, python-format +msgid "" +"Make sure you validate or adapt the related resupply picking to your subcontractor in order to avoid inconsistencies in your stock." +msgstr "" + #. module: mrp_subcontracting #: code:addons/mrp_subcontracting/models/stock_picking.py:0 #, python-format diff --git a/addons/mrp_subcontracting/models/__init__.py b/addons/mrp_subcontracting/models/__init__.py index 7e7c3993a14..fc944c6b955 100644 --- a/addons/mrp_subcontracting/models/__init__.py +++ b/addons/mrp_subcontracting/models/__init__.py @@ -5,6 +5,7 @@ from . import product from . import res_company from . import res_partner from . import stock_move +from . import stock_move_line from . import stock_picking from . import stock_quant from . import stock_rule diff --git a/addons/mrp_subcontracting/models/stock_move_line.py b/addons/mrp_subcontracting/models/stock_move_line.py new file mode 100644 index 00000000000..91def171cf0 --- /dev/null +++ b/addons/mrp_subcontracting/models/stock_move_line.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + + +from odoo import _, api, models + + +class StockMoveLine(models.Model): + _inherit = 'stock.move.line' + + @api.onchange('lot_name', 'lot_id') + def _onchange_serial_number(self): + current_location_id = self.location_id + res = super()._onchange_serial_number() + if res and not self.lot_name and self.company_id.subcontracting_location_id == current_location_id: + # we want to avoid auto-updating source location in this case + change the warning message + self.location_id = current_location_id + res['warning']['message'] = res['warning']['message'].split("\n\n", 1)[0] + "\n\n" + \ + _("Make sure you validate or adapt the related resupply picking to your subcontractor in order to avoid inconsistencies in your stock.") + return res diff --git a/addons/stock/i18n/stock.pot b/addons/stock/i18n/stock.pot index 78cfd7ce0d8..98f5f128daa 100644 --- a/addons/stock/i18n/stock.pot +++ b/addons/stock/i18n/stock.pot @@ -6503,7 +6503,8 @@ msgstr "" #: code:addons/stock/models/stock_quant.py:0 #, python-format msgid "" -"Serial number (%s) is not located in %s, but is located in location(s): %s. " +"Serial number (%s) is not located in %s, but is located in location(s): %s.\n" +"\n" "Please correct this to prevent inconsistent data." msgstr "" @@ -6511,7 +6512,8 @@ msgstr "" #: code:addons/stock/models/stock_quant.py:0 #, python-format msgid "" -"Serial number (%s) is not located in %s, but is located in location(s): %s. " +"Serial number (%s) is not located in %s, but is located in location(s): %s.\n" +"\n" "Source location for this move will be changed to %s" msgstr "" @@ -7209,7 +7211,7 @@ msgstr "" msgid "" "The Serial Number (%s) is already used in these location(s): %s.\n" "\n" -"Is this expected? For example this can occur if a delivery operation is validated before its corresponding receipt operation is validated. In this case the issue will be solved automatically once all steps are completed. Otherwise, the serial numbershould be corrected to prevent inconsistent data." +"Is this expected? For example this can occur if a delivery operation is validated before its corresponding receipt operation is validated. In this case the issue will be solved automatically once all steps are completed. Otherwise, the serial number should be corrected to prevent inconsistent data." msgstr "" #. module: stock diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index e56decce594..5645493bbea 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -924,7 +924,7 @@ class StockQuant(models.Model): message = _('The Serial Number (%s) is already used in these location(s): %s.\n\n' 'Is this expected? For example this can occur if a delivery operation is validated ' 'before its corresponding receipt operation is validated. In this case the issue will be solved ' - 'automatically once all steps are completed. Otherwise, the serial numbershould be corrected to ' + 'automatically once all steps are completed. Otherwise, the serial number should be corrected to ' 'prevent inconsistent data.', lot_id.name, ', '.join(sn_locations.mapped('display_name'))) @@ -942,11 +942,13 @@ class StockQuant(models.Model): recommended_location = location break if recommended_location: - message = _('Serial number (%s) is not located in %s, but is located in location(s): %s. Source location for this move will be changed to %s', - lot_id.name, source_location_id.display_name, ', '.join(sn_locations.mapped('display_name')), recommended_location.display_name) + message = _('Serial number (%s) is not located in %s, but is located in location(s): %s.\n\n' + 'Source location for this move will be changed to %s', + lot_id.name, source_location_id.display_name, ', '.join(sn_locations.mapped('display_name')), recommended_location.display_name) else: - message = _('Serial number (%s) is not located in %s, but is located in location(s): %s. Please correct this to prevent inconsistent data.', - lot_id.name, source_location_id.display_name, ', '.join(sn_locations.mapped('display_name'))) + message = _('Serial number (%s) is not located in %s, but is located in location(s): %s.\n\n' + 'Please correct this to prevent inconsistent data.', + lot_id.name, source_location_id.display_name, ', '.join(sn_locations.mapped('display_name'))) return message, recommended_location