mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 14:55:42 +00:00
FIC[BE]Use qty column for warehouse updates
This commit is contained in:
@@ -294,7 +294,7 @@ func (s *transferLayingService) CreateOne(c *fiber.Ctx, req *validation.Create)
|
|||||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to reduce project flock population")
|
return fiber.NewError(fiber.StatusInternalServerError, "Failed to reduce project flock population")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := productWarehouseRepoTx.PatchOne(c.Context(), productWarehouseId, map[string]any{"quantity": gorm.Expr("quantity - ?", sourceDetail.Quantity)}, nil); err != nil {
|
if err := productWarehouseRepoTx.PatchOne(c.Context(), productWarehouseId, map[string]any{"quantity": gorm.Expr("qty - ?", sourceDetail.Quantity)}, nil); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to update source warehouse quantity")
|
return fiber.NewError(fiber.StatusInternalServerError, "Failed to update source warehouse quantity")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,7 +388,7 @@ func (s transferLayingService) UpdateOne(c *fiber.Ctx, req *validation.Update, i
|
|||||||
if oldSource.ProductWarehouseId != nil && oldSource.Qty > 0 {
|
if oldSource.ProductWarehouseId != nil && oldSource.Qty > 0 {
|
||||||
|
|
||||||
if err := productWarehouseRepoTx.PatchOne(c.Context(), *oldSource.ProductWarehouseId, map[string]any{
|
if err := productWarehouseRepoTx.PatchOne(c.Context(), *oldSource.ProductWarehouseId, map[string]any{
|
||||||
"quantity": gorm.Expr("quantity + ?", oldSource.Qty),
|
"quantity": gorm.Expr("qty + ?", oldSource.Qty),
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to restore warehouse quantity")
|
return fiber.NewError(fiber.StatusInternalServerError, "Failed to restore warehouse quantity")
|
||||||
}
|
}
|
||||||
@@ -466,7 +466,7 @@ func (s transferLayingService) UpdateOne(c *fiber.Ctx, req *validation.Update, i
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := productWarehouseRepoTx.PatchOne(c.Context(), productWarehouseId, map[string]any{"quantity": gorm.Expr("quantity - ?", sourceDetail.Quantity)}, nil); err != nil {
|
if err := productWarehouseRepoTx.PatchOne(c.Context(), productWarehouseId, map[string]any{"quantity": gorm.Expr("qty - ?", sourceDetail.Quantity)}, nil); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to update source warehouse quantity")
|
return fiber.NewError(fiber.StatusInternalServerError, "Failed to update source warehouse quantity")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -544,7 +544,7 @@ func (s transferLayingService) DeleteOne(c *fiber.Ctx, id uint) error {
|
|||||||
if source.ProductWarehouseId != nil && source.Qty > 0 {
|
if source.ProductWarehouseId != nil && source.Qty > 0 {
|
||||||
|
|
||||||
if err := productWarehouseRepoTx.PatchOne(c.Context(), *source.ProductWarehouseId, map[string]any{
|
if err := productWarehouseRepoTx.PatchOne(c.Context(), *source.ProductWarehouseId, map[string]any{
|
||||||
"quantity": gorm.Expr("quantity + ?", source.Qty),
|
"quantity": gorm.Expr("qty + ?", source.Qty),
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to restore source warehouse quantity")
|
return fiber.NewError(fiber.StatusInternalServerError, "Failed to restore source warehouse quantity")
|
||||||
}
|
}
|
||||||
@@ -766,7 +766,7 @@ func (s *transferLayingService) getOrCreateProductWarehouse(ctx context.Context,
|
|||||||
existing, err := productWarehouseRepoTx.GetProductWarehouseByProductAndWarehouseID(ctx, productID, warehouseID)
|
existing, err := productWarehouseRepoTx.GetProductWarehouseByProductAndWarehouseID(ctx, productID, warehouseID)
|
||||||
if err == nil && existing != nil {
|
if err == nil && existing != nil {
|
||||||
|
|
||||||
if err := productWarehouseRepoTx.PatchOne(ctx, existing.Id, map[string]any{"quantity": gorm.Expr("quantity + ?", quantity)}, nil); err != nil {
|
if err := productWarehouseRepoTx.PatchOne(ctx, existing.Id, map[string]any{"quantity": gorm.Expr("qty + ?", quantity)}, nil); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return existing, nil
|
return existing, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user