diff --git a/stock_ux/models/stock_move.py b/stock_ux/models/stock_move.py index c7210c662..44a3aec8f 100644 --- a/stock_ux/models/stock_move.py +++ b/stock_ux/models/stock_move.py @@ -54,6 +54,7 @@ def _compute_origin_description(self): @api.constrains("quantity") def _check_quantity(self): precision = self.env["decimal.precision"].precision_get("Product Unit of Measure") +<<<<<<< a840f3e45961f91a06c77aa8b6aab07e736611a4 if any(self.filtered(lambda x: x.location_dest_usage == "inventory")): return elif any( @@ -63,6 +64,57 @@ def _check_quantity(self): ) ): raise ValidationError(_("You can not transfer more than the initial demand!")) +||||||| 0efa3b521a955f439752b8d54faa6d70d8d5fd92 + if any(self.filtered(lambda x: x.scrapped)): + return + moves = self.filtered( + lambda x: x.picking_id.picking_type_id.block_additional_quantity + and float_compare(x.product_uom_qty, x.quantity, precision_digits=precision) == -1 + ) + if not moves: + return + + # Si lo ejecuta el superusuario (scheduler), revertir el cambio y loguear + if self.env.is_superuser(): + for move in moves: + # Revertir el cambio de quantity + move.quantity = move.product_uom_qty + move.picking_id.message_post( + body=_( + "Se intentó transferir una cantidad mayor a la demanda inicial en el movimiento %s durante la ejecución automática (scheduler). El sistema ignoró el cambio y mantuvo la cantidad original." + ) + % move.display_name + ) + return + + # Comportamiento normal: raise si corresponde + raise ValidationError(_("You can not transfer more than the initial demand!")) +======= + if any(self.filtered(lambda x: x.scrapped)): + return super()._check_quantity() + moves = self.filtered( + lambda x: x.picking_id.picking_type_id.block_additional_quantity + and float_compare(x.product_uom_qty, x.quantity, precision_digits=precision) == -1 + ) + if not moves: + return super()._check_quantity() + + # Si lo ejecuta el superusuario (scheduler), revertir el cambio y loguear + if self.env.is_superuser(): + for move in moves: + # Revertir el cambio de quantity + move.quantity = move.product_uom_qty + move.picking_id.message_post( + body=_( + "Se intentó transferir una cantidad mayor a la demanda inicial en el movimiento %s durante la ejecución automática (scheduler). El sistema ignoró el cambio y mantuvo la cantidad original." + ) + % move.display_name + ) + return super()._check_quantity() + + # Comportamiento normal: raise si corresponde + raise ValidationError(_("You can not transfer more than the initial demand!")) +>>>>>>> f9e6a688e71c027eb81740ccbbb0d2795de426dd def action_view_linked_record(self): """This function returns an action that display existing sales order