refactor lot matching into shared module
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"git.mchus.pro/mchus/quoteforge/internal/models"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/repository"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/services/pricing"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/warehouse"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -132,6 +133,22 @@ func (s *Service) CreateForSourceWithProgress(createdBy, source string, sourceIt
|
||||
}
|
||||
|
||||
items := make([]models.PricelistItem, 0)
|
||||
if len(sourceItems) == 0 && source == string(models.PricelistSourceWarehouse) {
|
||||
warehouseItems, err := warehouse.ComputePricelistItemsFromStockLog(s.db)
|
||||
if err != nil {
|
||||
_ = s.repo.Delete(pricelist.ID)
|
||||
return nil, fmt.Errorf("building warehouse pricelist from stock_log: %w", err)
|
||||
}
|
||||
sourceItems = make([]CreateItemInput, 0, len(warehouseItems))
|
||||
for _, item := range warehouseItems {
|
||||
sourceItems = append(sourceItems, CreateItemInput{
|
||||
LotName: item.LotName,
|
||||
Price: item.Price,
|
||||
PriceMethod: item.PriceMethod,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if len(sourceItems) > 0 {
|
||||
items = make([]models.PricelistItem, 0, len(sourceItems))
|
||||
for _, srcItem := range sourceItems {
|
||||
|
||||
Reference in New Issue
Block a user