Improve the frontend and repository layer
This commit is contained in:
@@ -126,6 +126,27 @@ async def create_stock_batches_for_ingredient(
|
||||
stocks = []
|
||||
num_batches = random.randint(1, 2) # Reduced from 3-5 for faster demo loading
|
||||
|
||||
# Calculate target total stock for this ingredient
|
||||
# Use 40-80% of max_stock_level to allow for realistic variation
|
||||
# If max_stock_level is not set, use reorder_point * 3 as a reasonable target
|
||||
if ingredient.max_stock_level:
|
||||
target_total_stock = float(ingredient.max_stock_level) * random.uniform(0.4, 0.8)
|
||||
else:
|
||||
target_total_stock = float(ingredient.reorder_point or 50.0) * 3.0
|
||||
|
||||
# Distribute total stock across batches
|
||||
batch_quantities = []
|
||||
remaining = target_total_stock
|
||||
for i in range(num_batches):
|
||||
if i == num_batches - 1:
|
||||
# Last batch gets whatever is remaining
|
||||
batch_quantities.append(remaining)
|
||||
else:
|
||||
# Earlier batches get a random portion of remaining
|
||||
portion = remaining * random.uniform(0.3, 0.7)
|
||||
batch_quantities.append(portion)
|
||||
remaining -= portion
|
||||
|
||||
for i in range(num_batches):
|
||||
# Calculate expiration days offset
|
||||
days_offset = calculate_expiration_distribution()
|
||||
@@ -146,17 +167,11 @@ async def create_stock_batches_for_ingredient(
|
||||
quality_status = "good"
|
||||
is_available = True
|
||||
|
||||
# Generate quantities
|
||||
if ingredient.unit_of_measure.value in ['kg', 'l']:
|
||||
current_quantity = round(random.uniform(5.0, 50.0), 2)
|
||||
reserved_quantity = round(random.uniform(0.0, current_quantity * 0.3), 2) if is_available else 0.0
|
||||
elif ingredient.unit_of_measure.value in ['g', 'ml']:
|
||||
current_quantity = round(random.uniform(500.0, 5000.0), 2)
|
||||
reserved_quantity = round(random.uniform(0.0, current_quantity * 0.3), 2) if is_available else 0.0
|
||||
else: # units, pieces, etc.
|
||||
current_quantity = float(random.randint(10, 200))
|
||||
reserved_quantity = float(random.randint(0, int(current_quantity * 0.3))) if is_available else 0.0
|
||||
# Use pre-calculated batch quantity
|
||||
current_quantity = round(batch_quantities[i], 2)
|
||||
|
||||
# Reserve 0-30% of current quantity if available
|
||||
reserved_quantity = round(random.uniform(0.0, current_quantity * 0.3), 2) if is_available else 0.0
|
||||
available_quantity = current_quantity - reserved_quantity
|
||||
|
||||
# Calculate costs with variation
|
||||
|
||||
Reference in New Issue
Block a user