Improve dropping restrictions.

This commit refs #4497
This commit is contained in:
Sergio Morillo 2018-04-26 23:25:34 +02:00
parent 65fac7cdee
commit 14acab6b2b
2 changed files with 23 additions and 7 deletions

View File

@ -34,6 +34,10 @@ msgctxt "error:stock.unit_load:"
msgid "Unit load \"%s\" must be in Done state before moving."
msgstr "Unidad de carga \"%s\" debe estar en estado Realizado para ser movida."
msgctxt "error:stock.unit_load:"
msgid "Cannot drop more quantity (%s) than total quantity (%s) in UL \"%s\"."
msgstr "No puede volcar más cantidad (%s) que la total (%s) en la UdC \%s\"."
msgctxt "error:stock.move:"
msgid "Time in Unit load moves is required."
msgstr "Los movimientos de UdC deben tener Hora efectiva."

View File

@ -216,6 +216,9 @@ class UnitLoad(ModelView, ModelSQL):
'missing_return_location':
'Cannot set location in returning move of product "%s" '
'of UL "%s" during its dropping process.',
'wrong_dropped_qty':
'Cannot drop more quantity (%s) than total quantity (%s) '
'in UL "%s".'
})
cls._buttons.update({
'move_try': {
@ -757,13 +760,13 @@ class UnitLoad(ModelView, ModelSQL):
_grouped_moves, move.uom)
dropped_qty = 0
if location_type == 'storage' and self.drop_moves:
dropped_qty = sum(
Uom.compute_qty(m.uom, m.quantity, move.uom)
for m in self.drop_moves
if m.product.id == move.product.id)
dropped_qty = self._get_dropped_quantity(move.product,
move.uom)
if dropped_qty:
move.quantity -= dropped_qty
moves.append(move)
if move.quantity:
moves.append(move)
return moves
def _get_quantity_to_move(self, _grouped_moves, uom):
@ -967,8 +970,10 @@ class UnitLoad(ModelView, ModelSQL):
if record.dropped and not record.drop_moves:
to_undrop.append(record)
continue
qty = sum(m.quantity for m in record.drop_moves
if m.product.id == record.product.id)
qty = record._get_dropped_quantity()
if qty > record.quantity:
cls.raise_user_error('wrong_dropped_qty', (
qty, record.quantity, record.rec_name))
if qty == record.internal_quantity and not record.dropped:
to_drop.append(record)
elif qty < record.internal_quantity and record.dropped:
@ -978,6 +983,13 @@ class UnitLoad(ModelView, ModelSQL):
if values:
cls.write(values, {'dropped': key})
def _get_dropped_quantity(self, product=None, to_uom=None):
if not self.drop_moves:
return 0.0
_product = product or self.product
return sum(self.uom.compute_qty(m.uom, m.quantity, to_uom or self.uom)
for m in self.drop_moves if m.product.id == _product.id)
@classmethod
def _set_internal_quantity(cls, records):
for record in records: