From 592d77e30b60bb7645f8c947c31bd5da18ca2de3 Mon Sep 17 00:00:00 2001 From: Mikhail Chusavitin Date: Fri, 13 Mar 2026 08:09:47 +0300 Subject: [PATCH] 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 --- internal/services/pricelist/service.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/services/pricelist/service.go b/internal/services/pricelist/service.go index 3ce7e8d..2aa57cb 100644 --- a/internal/services/pricelist/service.go +++ b/internal/services/pricelist/service.go @@ -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 {