Competitor pricelist: aggregate all competitors, rebuild without re-import

- Add GetLatestQuotesAllCompetitors() repo method: latest quote per
  (competitor_id, partnumber) across all active competitors
- Add RebuildPricelist() service method: loads all quotes, applies each
  competitor's discount, aggregates with weighted_median per lot,
  creates single combined competitor pricelist
- Add POST /api/competitors/pricelist handler + route
- JS: "Создать прайслист" on competitor tab calls new endpoint instead
  of the generic one that required explicit items

This allows recreating the competitor pricelist after new lot mappings
are added, without requiring a new file upload.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mikhail Chusavitin
2026-03-13 08:17:44 +03:00
parent 592d77e30b
commit ec182abe99
5 changed files with 182 additions and 1 deletions

View File

@@ -1769,7 +1769,10 @@ async function createPricelist() {
progressStats.textContent = '';
// Start background task
const resp = await fetch('/api/pricelists/create-with-progress', {
const url = currentPricelistSource === 'competitor'
? '/api/competitors/pricelist'
: '/api/pricelists/create-with-progress';
const resp = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ source: currentPricelistSource })