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,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// Default snapshot source for estimate and backward compatibility.
|
||||
} else if source == string(models.PricelistSourceEstimate) {
|
||||
// Estimate snapshot: read current prices from qt_lot_metadata.
|
||||
type LotMetadataWithCategory struct {
|
||||
models.LotMetadata
|
||||
LotCategory string
|
||||
@@ -315,6 +315,10 @@ func (s *Service) CreateForSourceWithProgress(createdBy, source string, sourceIt
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user