[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 <arm@odoo.com>
Signed-off-by: Tiffany Chang <tic@odoo.com>
This commit is contained in:
Tiffany Chang (tic)
2021-11-03 16:02:07 +00:00
parent 76b556fd3c
commit dd1ea09f34
5 changed files with 40 additions and 8 deletions
@@ -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
@@ -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
@@ -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
+5 -3
View File
@@ -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
+7 -5
View File
@@ -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