Commit Graph

13 Commits

Author SHA1 Message Date
Mikhail Chusavitin
592d77e30b 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>
2026-03-13 08:09:47 +03:00
Mikhail Chusavitin
f48615e8a9 Modularize Go files, extract JS to static, implement competitor pricelists
Go refactoring:
- Split handlers/pricing.go (2446→291 lines) into 5 focused files
- Split services/stock_import.go (1334→~400 lines) into stock_mappings.go + stock_parse.go
- Split services/sync/service.go (1290→~250 lines) into 3 files

JS extraction:
- Move all inline <script> blocks to web/static/js/ (6 files)
- Templates reduced: admin_pricing 2873→521, lot 1531→304, vendor_mappings 1063→169, etc.

Competitor pricelists (migrations 033-039):
- qt_competitors + partnumber_log_competitors tables
- Excel import with column mapping, dedup, bulk insert
- p/n→lot resolution via weighted_median, discount applied
- Unmapped p/ns written to qt_vendor_partnumber_seen
- Quote counts (unique/total) shown on /admin/competitors
- price_method="weighted_median", price_period_days=0 stored explicitly

Fix price_method/price_period_days for warehouse items:
- warehouse: weighted_avg, period=0
- competitor: weighted_median, period=0
- Removes misleading DB defaults (was: median/90)

Update bible: architecture.md, pricelist.md, history.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-13 07:44:10 +03:00
Mikhail Chusavitin
c0fecde34e Add new items section to price changes modal
Track positions added to a pricelist (not present in the previous one)
and display them in a separate "Новые позиции" section in the price
changes modal on both pricelists and admin_pricing pages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-12 11:39:47 +03:00
Mikhail Chusavitin
3f26a2935a Refactor vendor mappings to canonical PN catalog 2026-03-07 23:11:42 +03:00
Mikhail Chusavitin
63454554c1 Fix vendor mapping delete behavior and update docs 2026-02-25 19:06:28 +03:00
Mikhail Chusavitin
c96a8806c4 Harden pricelist formation and document architecture decisions 2026-02-20 19:01:07 +03:00
Mikhail Chusavitin
b94dd3d015 warehouse: switch stock pricing to weighted_avg 2026-02-18 19:45:32 +03:00
Mikhail Chusavitin
221e414e2f Default lot category to PART_ when missing 2026-02-18 10:32:51 +03:00
Mikhail Chusavitin
c939ce18ad Merge origin/main 2026-02-18 10:12:07 +03:00
f64c4fd6b2 feat: optimize background tasks and fix warehouse pricelist workflow
Optimize task retention from 5 minutes to 30 seconds to reduce polling overhead since toast notifications are shown only once. Add conditional warehouse pricelist creation via checkbox. Fix category storage in warehouse pricelists to properly load from lot table. Replace SSE with task polling for all long operations. Add comprehensive logging for debugging while minimizing noise from polling endpoints.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-16 11:08:10 +03:00
Mikhail Chusavitin
c47c93ab31 fix: потоковая отправка прогресса создания прайслиста и исправление маппинга колонки категории
Две ключевые исправления:

1. Потоковая отправка прогресса создания (SSE):
   - Эндпоинт CreateWithProgress теперь отправляет Server-Sent Events
     вместо возврата JSON с task_id
   - Полирует статус задачи и отправляет обновления прогресса в реальном времени
   - Отправляет финальное событие с данными прайслиста или ошибкой
   - Фронтенд уже ожидал этого формата SSE

2. Исправление маппинга колонки lot_category:
   - Добавлен явный тег column в поле Category модели PricelistItem
     чтобы маппиться на колонку 'lot_category' в БД
   - Категория теперь хранится как снимок в таблице pricelist_items
   - Обновлены запросы репозитория для использования сохраненной
     категории вместо динамических JOIN с таблицей lot

Это исправляет ошибки:
- "Создание прервано: не получен результат" (фронтенд ожидал streaming)
- "Unknown column 'category' in 'INSERT INTO'" (несоответствие схемы БД)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-02-10 15:17:16 +03:00
e97cd5048c feat: implement background task system with notifications
- Added background task manager with goroutine execution and panic recovery
- Replaced SSE streaming with background task execution for:
  * Price recalculation (RecalculateAll)
  * Stock import (ImportStockLog)
  * Pricelist creation (CreateWithProgress)
- Implemented unified polling for task status and DB connection in frontend
- Added task indicator in top bar showing running tasks count
- Added toast notifications for task completion/error
- Tasks automatically cleaned up after 10 minutes
- Tasks show progress (0-100%) with descriptive messages
- Updated handler constructors to receive task manager
- Added API endpoints for task status (/api/tasks, /api/tasks/:id)

Fixes issue with SSE disconnection on slow connections during long-running operations
2026-02-08 20:39:59 +03:00
20309d1f0e Fork from QuoteForge → PriceForge
Renamed module path git.mchus.pro/mchus/quoteforge → git.mchus.pro/mchus/priceforge,
renamed package quoteforge → priceforge, moved binary from cmd/qfs to cmd/pfs.
2026-02-07 21:42:26 +03:00