swt23w23/src/main/java/catering/catalog/CatalogDataInitializer.java
Simon Bruder 7365b384e3
Make metric variable
This was somehow overlooked, but it should work.

This needs to change how the InventoryMutateForm handles quantities, as
the amount has to be split from the metric for addition to work.
2024-01-09 10:53:12 +01:00

65 lines
1.8 KiB
Java

// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-FileCopyrightText: 2023-2024 swt23w23
package catering.catalog;
import static org.salespointframework.core.Currencies.EURO;
import java.util.Set;
import java.util.Optional;
import org.javamoney.moneta.Money;
import org.salespointframework.core.DataInitializer;
import org.salespointframework.quantity.Metric;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import catering.order.OrderType;
@Component
@Order(20)
class CatalogDataInitializer implements DataInitializer {
private final CateringCatalog cateringCatalog;
CatalogDataInitializer(CateringCatalog cateringCatalog) {
Assert.notNull(cateringCatalog, "CateringCatalog must not be null!");
this.cateringCatalog = cateringCatalog;
}
@Override
public void initialize() {
if (cateringCatalog.findAll().iterator().hasNext()) {
return;
}
// !!! These need to be kept in sync with CatalogUnitTests
cateringCatalog.save(new Consumable(
"Brötchen Vollkorn",
Money.of(1, EURO),
Money.of(0.5, EURO),
Optional.of(Money.of(0.75, EURO)),
Set.of(OrderType.EVENT_CATERING, OrderType.MOBILE_BREAKFAST),
Metric.UNIT));
cateringCatalog.save(new Consumable(
"Tafelwasser",
Money.of(5, EURO),
Money.of(0.01, EURO),
Optional.empty(),
Set.of(OrderType.PARTY_SERVICE, OrderType.EVENT_CATERING),
Metric.LITER));
cateringCatalog.save(new Rentable(
"Kerze Rot",
Money.of(2, EURO),
Money.of(1.5, EURO),
Set.of(OrderType.EVENT_CATERING, OrderType.MOBILE_BREAKFAST),
Metric.UNIT));
cateringCatalog.save(new Rentable(
"Brotschneidemaschine Power X 3000",
Money.of(25, EURO),
Money.of(10000, EURO),
Set.of(OrderType.EVENT_CATERING, OrderType.MOBILE_BREAKFAST),
Metric.UNIT));
}
}