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 packageSize != (current.packageSize.map { formatAmount($0) } ?? "") { return true }
|
||||||
if packageLabel != (current.packageLabel ?? "") { return true }
|
if packageLabel != (current.packageLabel ?? "") { return true }
|
||||||
if datePrecision != (current.datePrecision == "month" ? "month" : "day") { 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.isObject {
|
||||||
if !current.isIndividual && !current.isBulk, shopId != current.shopId { return true }
|
if !current.isIndividual && !current.isBulk, shopId != current.shopId { return true }
|
||||||
if !current.isBulk, productUrl != (current.productUrl ?? "") { 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 }
|
if fieldValues != Self.stringValues(current.fieldValues) { return true }
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -173,10 +173,10 @@ struct ProductDetailView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mindestbestand nur bei Verbrauchsgegenständen (Charge) – in der
|
// Mindestbestand bei Lebensmitteln UND Verbrauchsgegenständen (Charge) –
|
||||||
// Anzeigeeinheit (z.B. Milliliter), nicht in Packungen. Menge je
|
// in der Anzeigeeinheit (z.B. Gramm/Milliliter), nicht in Packungen.
|
||||||
// Lagerort und Einzelstücke haben keinen Mindestbestand.
|
// Menge je Lagerort und Einzelstücke haben keinen Mindestbestand.
|
||||||
if current.isBulk {
|
if current.foodLike {
|
||||||
Section("Mindestbestand") {
|
Section("Mindestbestand") {
|
||||||
QuantityField(label: "Gesamt (\(current.unitName))", text: $minStock)
|
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() {
|
private func fillForm() {
|
||||||
name = current.name
|
name = current.name
|
||||||
brand = current.brand ?? ""
|
brand = current.brand ?? ""
|
||||||
@@ -293,7 +299,7 @@ struct ProductDetailView: View {
|
|||||||
categoryId = current.categoryId
|
categoryId = current.categoryId
|
||||||
shopId = current.shopId
|
shopId = current.shopId
|
||||||
productUrl = current.productUrl ?? ""
|
productUrl = current.productUrl ?? ""
|
||||||
minStock = current.minStockDisplay.map { formatAmount($0) } ?? ""
|
minStock = minStockFeld
|
||||||
fieldValues = Self.stringValues(current.fieldValues)
|
fieldValues = Self.stringValues(current.fieldValues)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,14 +353,15 @@ struct ProductDetailView: View {
|
|||||||
groupId: groupId,
|
groupId: groupId,
|
||||||
categoryId: categoryId
|
categoryId: categoryId
|
||||||
)
|
)
|
||||||
if current.isObject {
|
// Mindestbestand für Lebensmittel UND Verbrauchsgegenstände.
|
||||||
var fv: [String: String?] = [:]
|
|
||||||
for def in fieldDefs { fv[String(def.id)] = fieldValues[String(def.id)] ?? "" }
|
|
||||||
req.fieldValues = fv
|
|
||||||
req.minStock = minBase
|
req.minStock = minBase
|
||||||
req.minStockInPackages = false
|
req.minStockInPackages = false
|
||||||
req.minStockUnitId = nil
|
req.minStockUnitId = nil
|
||||||
req.sendMinStock = true
|
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
|
||||||
}
|
}
|
||||||
current = try await APIClient.shared.updateProduct(id: current.id, req)
|
current = try await APIClient.shared.updateProduct(id: current.id, req)
|
||||||
if current.isObject { fieldValues = Self.stringValues(current.fieldValues) }
|
if current.isObject { fieldValues = Self.stringValues(current.fieldValues) }
|
||||||
|
|||||||
Reference in New Issue
Block a user