Fix estimate data leaking into competitor/warehouse pricelists
The else branch in CreateForSourceWithProgress was reading from qt_lot_metadata (estimate snapshot) for any source when no items were provided. This caused estimate prices, coefficients, manual prices and meta_prices to be copied verbatim into competitor/warehouse pricelists when called with empty item list. Fix: else branch is now guarded to source=="estimate" only. Any other source with no items returns an explicit error instead of silently falling back to estimate data. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -248,8 +248,8 @@ func (s *Service) CreateForSourceWithProgress(createdBy, source string, sourceIt
|
|||||||
PricePeriodDays: srcItem.PricePeriodDays,
|
PricePeriodDays: srcItem.PricePeriodDays,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else if source == string(models.PricelistSourceEstimate) {
|
||||||
// Default snapshot source for estimate and backward compatibility.
|
// Estimate snapshot: read current prices from qt_lot_metadata.
|
||||||
type LotMetadataWithCategory struct {
|
type LotMetadataWithCategory struct {
|
||||||
models.LotMetadata
|
models.LotMetadata
|
||||||
LotCategory string
|
LotCategory string
|
||||||
@@ -315,6 +315,10 @@ func (s *Service) CreateForSourceWithProgress(createdBy, source string, sourceIt
|
|||||||
MetaPrices: m.MetaPrices,
|
MetaPrices: m.MetaPrices,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Non-estimate source with no items provided — refuse to fall back to estimate snapshot.
|
||||||
|
_ = s.repo.Delete(pricelist.ID)
|
||||||
|
return nil, fmt.Errorf("no items provided for source %q: explicit item list required", source)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(items) == 0 {
|
if len(items) == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user