Fix product performance grouped JSON build
This commit is contained in:
@@ -6129,6 +6129,10 @@ func productPerformanceMapVariantKey(row map[string]any) string {
|
||||
|
||||
func deriveProductPerformanceGroupMetrics(out map[string]any, groupField string) {
|
||||
normalizeProductPerformanceCostFields(out)
|
||||
isGroup := strings.TrimSpace(groupField) != ""
|
||||
if isGroup {
|
||||
out["group_field"] = groupField
|
||||
}
|
||||
preservedCustomerScores := map[string]float64{}
|
||||
preservedProductScores := map[string]float64{}
|
||||
for _, suffix := range productPerformancePeriodSuffixes() {
|
||||
@@ -6149,7 +6153,7 @@ func deriveProductPerformanceGroupMetrics(out map[string]any, groupField string)
|
||||
qty := floatFromMap(out, "sales_qty_"+suffix)
|
||||
stockQty := floatFromMap(out, "stock_qty")
|
||||
turnoverBase := floatFromMap(out, "avg_stock_"+suffix)
|
||||
if turnoverBase <= 0 {
|
||||
if turnoverBase <= 0 && !isGroup {
|
||||
turnoverBase = stockQty
|
||||
}
|
||||
days := productPerformancePeriodDays(out, suffix)
|
||||
@@ -6381,7 +6385,7 @@ func productPerformanceSalesPeriodScore(row map[string]any, suffix string) float
|
||||
stockTurnover := floatFromMap(row, "stock_turnover_"+suffix)
|
||||
if stockTurnover == 0 {
|
||||
avgStock := floatFromMap(row, "avg_stock_"+suffix)
|
||||
if avgStock <= 0 {
|
||||
if avgStock <= 0 && strings.TrimSpace(stringFromMap(row, "group_field")) == "" {
|
||||
avgStock = floatFromMap(row, "stock_qty")
|
||||
}
|
||||
if avgStock > 0 {
|
||||
|
||||
Reference in New Issue
Block a user