Merge pull request 'Fix total_amount to use base price' (#17) from feature/exclusive-summary into main

Reviewed-on: #17
This commit was merged in pull request #17.
This commit is contained in:
2026-06-18 03:18:04 +00:00
+11 -3
View File
@@ -107,7 +107,7 @@ func (p *PurchaseOrderProcessorImpl) CreatePurchaseOrder(ctx context.Context, or
// Calculate total amount
totalAmount := 0.0
for _, item := range req.Items {
totalAmount += item.Amount
totalAmount += calculatePurchaseOrderItemTotal(item.Quantity, item.Amount)
}
// Create purchase order entity
@@ -277,7 +277,7 @@ func (p *PurchaseOrderProcessorImpl) UpdatePurchaseOrder(ctx context.Context, id
UnitID: unitID,
Amount: amount,
}
totalAmount += amount
totalAmount += calculatePurchaseOrderItemTotal(quantity, amount)
}
// 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
unitCost := 0.0
if quantityToAdd > 0 {
unitCost = item.Amount / quantityToAdd
unitCost = calculatePurchaseOrderItemTotal(item.Quantity, item.Amount) / quantityToAdd
}
// Create inventory movement for ingredient purchase
@@ -506,3 +506,11 @@ func (p *PurchaseOrderProcessorImpl) validatePurchaseCategory(ctx context.Contex
return category, nil
}
func calculatePurchaseOrderItemTotal(quantity *float64, amount float64) float64 {
if quantity == nil {
return amount
}
return *quantity * amount
}