[FIX] stock: avoid duplicate picking type seqs
Fixes 2 bugs: - Users were confused when creating a picking type with a duplicated prefix name. Because of it, they were unable to distinguish between the 2 auto-generated ir_sequences since they default to the same name https://github.com/odoo/odoo/blob/fe29860b22563bcae58a2e118b2a5ea79637589e/addons/stock/models/stock_picking.py#L102-L115 Therefore we add a warning when they try to reuse an existing prefix (within a company), but not reuse the same seq id. We do not want to completely block duplicated prefixes in case the user really wants it and/or it is duplicated programmatically by accident (e.g. doing uninstall + reinstall of a module). - When users duplicate an existing picking type, the auto-generated ir_sequence could result in duplicated picking names, which can result in a block due to the constraint: https://github.com/odoo/odoo/blob/fe29860b22563bcae58a2e118b2a5ea79637589e/addons/stock/models/stock_picking.py#L440C1-L441 A previous solution involved linking the existing sequence_id to the duplicated picking type, but this was NOT a good solution because it could lead to an inconsistency between the prefix used by the picking types due to one being changed and the other not, i.e. https://github.com/odoo/odoo/blob/fe29860b22563bcae58a2e118b2a5ea79637589e/addons/stock/models/stock_picking.py#L123-L136 would be applied, but the user may not see that it auto-changes it for the other picking type Note that there are some other bugs that still exist related to these bugs, but there's only so much time in the world to fix this mechanism, so posterity (i.e. if someone else wants to fix them) they are: - Previous fix: odoo/odoo#138471 ensures that the company of a picking type correctly matches its sequence_id's company. Unfortunately it does not take into account if the prefix has been changed (i.e. the picking type prefix WON'T match its sequence's prefix). This mismatch can also occur if the name of the warehouse is changed. - Previous fix: odoo/odoo#139277 ensures that the sequence names are unique so that they are more easily noticed/fixed, but the prefix is left unchanged. Therefore there can still be issues with duplicate prefixes leading to the sql_constraints being triggered for pickings that use both the existing and the new sequence value. Part-of: odoo/odoo#146362
This commit is contained in:
@@ -8829,6 +8829,17 @@ msgstr ""
|
||||
msgid "This report cannot be used for done and not done %s at the same time"
|
||||
msgstr ""
|
||||
|
||||
#. module: stock
|
||||
#. odoo-python
|
||||
#: code:addons/stock/models/stock_picking.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"This sequence prefix is already being used by another operation type. It is "
|
||||
"recommended that you select a unique prefix to avoid issues and/or repeated "
|
||||
"reference values or assign the existing reference sequence to this operation"
|
||||
" type."
|
||||
msgstr ""
|
||||
|
||||
#. module: stock
|
||||
#: model:ir.model.fields,help:stock.field_product_product__property_stock_production
|
||||
#: model:ir.model.fields,help:stock.field_product_template__property_stock_production
|
||||
|
||||
@@ -171,6 +171,8 @@ class PickingType(models.Model):
|
||||
default = dict(default or {})
|
||||
if 'name' not in default:
|
||||
default['name'] = _("%s (copy)", self.name)
|
||||
if 'sequence_code' not in default and 'sequence_id' not in default:
|
||||
default.update(sequence_code=_("%s (copy)") % self.sequence_code)
|
||||
return super().copy(default=default)
|
||||
|
||||
def write(self, vals):
|
||||
@@ -298,6 +300,23 @@ class PickingType(models.Model):
|
||||
if picking_type.code != 'incoming':
|
||||
picking_type.show_reserved = True
|
||||
|
||||
@api.onchange('sequence_code')
|
||||
def _onchange_sequence_code(self):
|
||||
if not self.sequence_code:
|
||||
return
|
||||
domain = [('sequence_code', '=', self.sequence_code), '|', ('company_id', '=', self.company_id.id), ('company_id', '=', False)]
|
||||
if self._origin.id:
|
||||
domain += [('id', '!=', self._origin.id)]
|
||||
picking_type = self.env['stock.picking.type'].search(domain, limit=1)
|
||||
if picking_type and picking_type.sequence_id != self.sequence_id:
|
||||
return {
|
||||
'warning': {
|
||||
'message': _(
|
||||
"This sequence prefix is already being used by another operation type. It is recommended that you select a unique prefix "
|
||||
"to avoid issues and/or repeated reference values or assign the existing reference sequence to this operation type.")
|
||||
}
|
||||
}
|
||||
|
||||
@api.constrains('default_location_dest_id')
|
||||
def _check_default_location(self):
|
||||
for record in self:
|
||||
|
||||
Reference in New Issue
Block a user