iOS: Mindestbestand auch bei Lebensmitteln verwalten
Das Gesamt-Mindestbestand-Feld erschien nur beim Verbrauchsgegenstand; bei Lebensmitteln fehlte es und save() schickte ihn nicht. Jetzt fuer alle foodLike (Lebensmittel + Verbrauchsgegenstand) - in der Anzeigeeinheit, robust aus den Basiseinheiten umgerechnet. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -57,12 +57,12 @@ struct ProductDetailView: View {
|
||||
if packageSize != (current.packageSize.map { formatAmount($0) } ?? "") { return true }
|
||||
if packageLabel != (current.packageLabel ?? "") { return true }
|
||||
if datePrecision != (current.datePrecision == "month" ? "month" : "day") { return true }
|
||||
// Mindestbestand gibt es bei Lebensmitteln und Verbrauchsgegenständen.
|
||||
if minStock != minStockFeld { return true }
|
||||
}
|
||||
if current.isObject {
|
||||
if !current.isIndividual && !current.isBulk, shopId != current.shopId { return true }
|
||||
if !current.isBulk, productUrl != (current.productUrl ?? "") { return true }
|
||||
// Mindestbestand gibt es nur beim Verbrauchsgegenstand.
|
||||
if current.isBulk, minStock != (current.minStockDisplay.map { formatAmount($0) } ?? "") { return true }
|
||||
if fieldValues != Self.stringValues(current.fieldValues) { return true }
|
||||
}
|
||||
return false
|
||||
@@ -173,10 +173,10 @@ struct ProductDetailView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// Mindestbestand nur bei Verbrauchsgegenständen (Charge) – in der
|
||||
// Anzeigeeinheit (z.B. Milliliter), nicht in Packungen. Menge je
|
||||
// Lagerort und Einzelstücke haben keinen Mindestbestand.
|
||||
if current.isBulk {
|
||||
// Mindestbestand bei Lebensmitteln UND Verbrauchsgegenständen (Charge) –
|
||||
// in der Anzeigeeinheit (z.B. Gramm/Milliliter), nicht in Packungen.
|
||||
// Menge je Lagerort und Einzelstücke haben keinen Mindestbestand.
|
||||
if current.foodLike {
|
||||
Section("Mindestbestand") {
|
||||
QuantityField(label: "Gesamt (\(current.unitName))", text: $minStock)
|
||||
}
|
||||
@@ -283,6 +283,12 @@ struct ProductDetailView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gesamt-Mindestbestand in der Anzeigeeinheit (Gramm/Milliliter/Stück) – aus
|
||||
/// den Basiseinheiten umgerechnet, unabhängig davon, wie er erfasst wurde.
|
||||
private var minStockFeld: String {
|
||||
current.minStock.map { formatAmount($0 / max(current.unitFactor, 1)) } ?? ""
|
||||
}
|
||||
|
||||
private func fillForm() {
|
||||
name = current.name
|
||||
brand = current.brand ?? ""
|
||||
@@ -293,7 +299,7 @@ struct ProductDetailView: View {
|
||||
categoryId = current.categoryId
|
||||
shopId = current.shopId
|
||||
productUrl = current.productUrl ?? ""
|
||||
minStock = current.minStockDisplay.map { formatAmount($0) } ?? ""
|
||||
minStock = minStockFeld
|
||||
fieldValues = Self.stringValues(current.fieldValues)
|
||||
}
|
||||
|
||||
@@ -347,14 +353,15 @@ struct ProductDetailView: View {
|
||||
groupId: groupId,
|
||||
categoryId: categoryId
|
||||
)
|
||||
// Mindestbestand für Lebensmittel UND Verbrauchsgegenstände.
|
||||
req.minStock = minBase
|
||||
req.minStockInPackages = false
|
||||
req.minStockUnitId = nil
|
||||
req.sendMinStock = true
|
||||
if current.isObject {
|
||||
var fv: [String: String?] = [:]
|
||||
for def in fieldDefs { fv[String(def.id)] = fieldValues[String(def.id)] ?? "" }
|
||||
req.fieldValues = fv
|
||||
req.minStock = minBase
|
||||
req.minStockInPackages = false
|
||||
req.minStockUnitId = nil
|
||||
req.sendMinStock = true
|
||||
}
|
||||
current = try await APIClient.shared.updateProduct(id: current.id, req)
|
||||
if current.isObject { fieldValues = Self.stringValues(current.fieldValues) }
|
||||
|
||||
Reference in New Issue
Block a user