Skip to content
Permalink
Browse files

fixup! [IMP] mrp: block usage of duplicate serial number

  • Loading branch information...
Whenrow committed Oct 9, 2019
1 parent ea9fd8c commit c78e19520cea02efd517912d4e87193cc03c453e
Showing with 11 additions and 9 deletions.
  1. +11 −9 addons/mrp/models/mrp_abstract_workorder.py
@@ -309,7 +309,7 @@ def _check_sn_uniquiness(self):
('state', '=', 'done')
])
if sml:
raise UserError(_('This serial number for product %s has already been produced' % self.product_id.name))
raise UserError(_('This serial number for product %s has already been produced') % self.product_id.name)


class MrpAbstractWorkorderLine(models.AbstractModel):
@@ -373,12 +373,6 @@ def _update_move_lines(self):
if self.product_id.tracking != 'none' and not self.lot_id:
raise UserError(_('Please enter a lot or serial number for %s !' % self.product_id.display_name))

if self.lot_id and self.product_id.tracking == 'serial' and self.lot_id in self.move_id.move_line_ids.filtered(lambda ml: ml.qty_done).mapped('lot_id'):
if self[self._get_raw_workorder_inverse_name()]:
raise UserError(_('The serial number used for component %s has already been consumed' % self.product_id.name))
else:
raise UserError(_('The serial number used for byproduct %s has already been produced' % self.product_id.name))

# Update reservation and quantity done
for ml in move_lines:
rounding = ml.product_uom_id.rounding
@@ -473,13 +467,21 @@ def _check_line_sn_uniquiness(self):
# Adapt domain and error message in case of component or byproduct
if self[self._get_raw_workorder_inverse_name()]:
domain.append(('location_dest_id.usage', '=', 'production'))
message = _('The serial number used for component %s has already been consumed' % self.product_id.name)
message = _('The serial number used for component %s has already been consumed') % self.product_id.name
co_prod_move_lines = self._get_production().move_raw_ids.move_line_ids
else:
domain.append(('location_id.usage', '=', 'production'))
message = _('The serial number used for byproduct %s has already been produced' % self.product_id.name)
message = _('The serial number used for byproduct %s has already been produced') % self.product_id.name
co_prod_move_lines = self._get_production().move_finished_ids.move_line_ids.filtered(lambda ml: ml.product_id != self._get_production().product_id)

# Check presence of same sn in previous productions
sml = self.env['stock.move.line'].search_count(domain)
if sml:
raise UserError(message)
# Check presence of same sn in current production
sml = co_prod_move_lines.filtered(lambda ml: ml.qty_done and ml.lot_id == self.lot_id)
if sml:
raise UserError(message)

def _unreserve_order(self):
""" Unreserve line with lower reserved quantity first """

0 comments on commit c78e195

Please sign in to comment.
You can’t perform that action at this time.