Compare commits

...

2 Commits

View File

@ -107,7 +107,7 @@ func (p *PurchaseOrderProcessorImpl) CreatePurchaseOrder(ctx context.Context, or
// Calculate total amount // Calculate total amount
totalAmount := 0.0 totalAmount := 0.0
for _, item := range req.Items { for _, item := range req.Items {
totalAmount += item.Amount totalAmount += calculatePurchaseOrderItemTotal(item.Quantity, item.Amount)
} }
// Create purchase order entity // Create purchase order entity
@ -277,7 +277,7 @@ func (p *PurchaseOrderProcessorImpl) UpdatePurchaseOrder(ctx context.Context, id
UnitID: unitID, UnitID: unitID,
Amount: amount, Amount: amount,
} }
totalAmount += amount totalAmount += calculatePurchaseOrderItemTotal(quantity, amount)
} }
// Delete and recreate only after all replacement items are valid. // Delete and recreate only after all replacement items are valid.
@ -447,7 +447,7 @@ func (p *PurchaseOrderProcessorImpl) UpdatePurchaseOrderStatus(ctx context.Conte
// Calculate unit cost in ingredient's base unit // Calculate unit cost in ingredient's base unit
unitCost := 0.0 unitCost := 0.0
if quantityToAdd > 0 { if quantityToAdd > 0 {
unitCost = item.Amount / quantityToAdd unitCost = calculatePurchaseOrderItemTotal(item.Quantity, item.Amount) / quantityToAdd
} }
// Create inventory movement for ingredient purchase // Create inventory movement for ingredient purchase
@ -506,3 +506,11 @@ func (p *PurchaseOrderProcessorImpl) validatePurchaseCategory(ctx context.Contex
return category, nil return category, nil
} }
func calculatePurchaseOrderItemTotal(quantity *float64, amount float64) float64 {
if quantity == nil {
return amount
}
return *quantity * amount
}