Wire competitor models, task type, usage count fix, and Competitors page handler
- Register Competitor + CompetitorQuote in AllModels() - Add TaskTypeCompetitorImport task type constant - CountUsage now checks pricelist_id, warehouse_pricelist_id, competitor_pricelist_id - WebHandler: load competitors.html template, add Competitors() page handler Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -68,7 +68,7 @@ func NewWebHandler(templatesPath string, componentService *services.ComponentSer
|
||||
}
|
||||
|
||||
// Load each page template with base
|
||||
simplePages := []string{"admin_pricing.html", "pricelists.html", "pricelist_detail.html", "lot.html", "vendor_mappings.html"}
|
||||
simplePages := []string{"admin_pricing.html", "pricelists.html", "pricelist_detail.html", "lot.html", "vendor_mappings.html", "competitors.html"}
|
||||
for _, page := range simplePages {
|
||||
pagePath := filepath.Join(templatesPath, page)
|
||||
var tmpl *template.Template
|
||||
@@ -143,6 +143,10 @@ func (h *WebHandler) VendorMappings(c *gin.Context) {
|
||||
h.render(c, "vendor_mappings.html", gin.H{"ActivePage": "vendor_mappings"})
|
||||
}
|
||||
|
||||
func (h *WebHandler) Competitors(c *gin.Context) {
|
||||
h.render(c, "competitors.html", gin.H{"ActivePage": "competitors"})
|
||||
}
|
||||
|
||||
func (h *WebHandler) Pricelists(c *gin.Context) {
|
||||
h.render(c, "pricelists.html", gin.H{"ActivePage": "pricelists"})
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ func AllModels() []interface{} {
|
||||
&PartnumberBook{},
|
||||
&PartnumberBookItem{},
|
||||
&VendorPartnumberSeen{},
|
||||
&Competitor{},
|
||||
&CompetitorQuote{},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -459,10 +459,12 @@ func (r *PricelistRepository) DecrementUsageCount(id uint) error {
|
||||
UpdateColumn("usage_count", gorm.Expr("GREATEST(usage_count - 1, 0)")).Error
|
||||
}
|
||||
|
||||
// CountUsage returns number of configurations referencing pricelist.
|
||||
// CountUsage returns number of configurations referencing pricelist across all source columns.
|
||||
func (r *PricelistRepository) CountUsage(id uint) (int64, error) {
|
||||
var count int64
|
||||
if err := r.db.Table("qt_configurations").Where("pricelist_id = ?", id).Count(&count).Error; err != nil {
|
||||
if err := r.db.Table("qt_configurations").
|
||||
Where("pricelist_id = ? OR warehouse_pricelist_id = ? OR competitor_pricelist_id = ?", id, id, id).
|
||||
Count(&count).Error; err != nil {
|
||||
return 0, fmt.Errorf("counting configurations for pricelist %d: %w", id, err)
|
||||
}
|
||||
return count, nil
|
||||
|
||||
@@ -19,6 +19,7 @@ const (
|
||||
TaskTypeStockImport TaskType = "stock_import"
|
||||
TaskTypePricelistCreate TaskType = "pricelist_create"
|
||||
TaskTypePartnumberBookCreate TaskType = "partnumber_book_create"
|
||||
TaskTypeCompetitorImport TaskType = "competitor_import"
|
||||
)
|
||||
|
||||
// Task represents a background task with progress tracking
|
||||
|
||||
Reference in New Issue
Block a user