refactor(inventory): update stock validation rules and enforce stock_difference requirement
This commit is contained in:
@@ -169,7 +169,7 @@ class AccommodationService
|
||||
'title' => trim($variant['title']),
|
||||
'value' => $this->valueCode($variant['title']),
|
||||
'description' => $variant['description'] ?? null,
|
||||
'stock' => (int) $variant['stock'],
|
||||
...(array_key_exists('stock', $variant) ? ['stock' => (int) $variant['stock']] : []),
|
||||
])->all();
|
||||
}
|
||||
|
||||
@@ -257,8 +257,10 @@ class AccommodationService
|
||||
'descripcion' => $data['description'],
|
||||
'precio' => $data['price'],
|
||||
]);
|
||||
$stockDifference = (int) ($data['stock_difference'] ?? ($data['stock'] - $inventory->availableStock()));
|
||||
$inventory->adjustAvailableStock($stockDifference, idempotencyKey: $stockAdjustmentId);
|
||||
$inventory->adjustAvailableStock(
|
||||
(int) $data['stock_difference'],
|
||||
idempotencyKey: $stockAdjustmentId,
|
||||
);
|
||||
$variant->definitions()->updateOrCreate(
|
||||
['item_attribute_id' => $itemAttribute->id],
|
||||
['value' => $data['value']],
|
||||
|
||||
@@ -141,8 +141,10 @@ class EntryService
|
||||
$catalogItem->itemAttributes()
|
||||
->whereHas('attribute', fn ($query) => $query->where('codigo', 'event_date'))
|
||||
->update(['allow_multi_select' => true]);
|
||||
$stockDifference = (int) ($entry['stock_difference'] ?? ((int) $entry['stock'] - $inventory->availableStock()));
|
||||
$inventory->adjustAvailableStock($stockDifference, idempotencyKey: $stockAdjustmentId);
|
||||
$inventory->adjustAvailableStock(
|
||||
(int) $entry['stock_difference'],
|
||||
idempotencyKey: $stockAdjustmentId,
|
||||
);
|
||||
|
||||
return $catalogItem->load([
|
||||
'variants.inventory',
|
||||
|
||||
@@ -113,7 +113,7 @@ class FoodService
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array{id: int, stock: int}> $variants
|
||||
* @param array<int, array{id: int, stock_difference: int}> $variants
|
||||
*/
|
||||
public function updateHistoricalStock(Tenant $tenant, array $variants, ?string $stockAdjustmentId = null): CatalogItem
|
||||
{
|
||||
@@ -143,8 +143,10 @@ class FoodService
|
||||
}
|
||||
|
||||
$inventory = $this->inventoryForHistoricalStockUpdate($variant);
|
||||
$stockDifference = (int) ($data['stock_difference'] ?? ((int) $data['stock'] - $inventory->availableStock()));
|
||||
$inventory->adjustAvailableStock($stockDifference, idempotencyKey: $stockAdjustmentId);
|
||||
$inventory->adjustAvailableStock(
|
||||
(int) $data['stock_difference'],
|
||||
idempotencyKey: $stockAdjustmentId,
|
||||
);
|
||||
}
|
||||
|
||||
return $this->current($tenant) ?? $food;
|
||||
@@ -294,7 +296,7 @@ class FoodService
|
||||
'schedule' => $schedule->value,
|
||||
'service' => $service->value,
|
||||
'description' => (string) ($variant['description'] ?? ''),
|
||||
'stock' => (int) $variant['stock'],
|
||||
...(array_key_exists('stock', $variant) ? ['stock' => (int) $variant['stock']] : []),
|
||||
];
|
||||
})->all();
|
||||
}
|
||||
@@ -407,8 +409,10 @@ class FoodService
|
||||
'precio' => $data['price'],
|
||||
]);
|
||||
$variant->eventDates()->sync([$data['event_date_id']]);
|
||||
$stockDifference = (int) ($data['stock_difference'] ?? ($data['stock'] - $inventory->availableStock()));
|
||||
$inventory->adjustAvailableStock($stockDifference, idempotencyKey: $stockAdjustmentId);
|
||||
$inventory->adjustAvailableStock(
|
||||
(int) $data['stock_difference'],
|
||||
idempotencyKey: $stockAdjustmentId,
|
||||
);
|
||||
$this->syncDefinitions($variant, $itemAttributes, $data);
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ class MerchandiseService
|
||||
...$variant,
|
||||
'color' => $color->value,
|
||||
'size' => $size->value,
|
||||
'stock' => (int) $variant['stock'],
|
||||
...(array_key_exists('stock', $variant) ? ['stock' => (int) $variant['stock']] : []),
|
||||
];
|
||||
})->all();
|
||||
}
|
||||
@@ -369,8 +369,10 @@ class MerchandiseService
|
||||
->firstOrFail();
|
||||
|
||||
$variant->update(['precio' => $data['price']]);
|
||||
$stockDifference = (int) ($data['stock_difference'] ?? ($data['stock'] - $inventory->availableStock()));
|
||||
$inventory->adjustAvailableStock($stockDifference, idempotencyKey: $stockAdjustmentId);
|
||||
$inventory->adjustAvailableStock(
|
||||
(int) $data['stock_difference'],
|
||||
idempotencyKey: $stockAdjustmentId,
|
||||
);
|
||||
$this->syncDefinitions($variant, $itemAttributes, $data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user