Update Auto Generate SKU

This commit is contained in:
2025-06-27 13:34:54 +07:00
parent f8798a53a4
commit 9b1f58d783
5 changed files with 62 additions and 2 deletions
@@ -3,6 +3,8 @@ package repository
import (
"BE-MiniERP/modules/inventory/models"
"fmt"
"gorm.io/gorm"
)
@@ -36,3 +38,24 @@ func (r *ProductRepository) Update(id uint, product *models.Product) error {
func (r *ProductRepository) Delete(id uint) error {
return r.DB.Delete(&models.Product{}, id).Error
}
func (r *ProductRepository) PreloadRelations(product *models.Product) error {
// Collection
if err := r.DB.First(&product.Collection, product.CollectionID).Error; err != nil {
return fmt.Errorf("collection not found: %w", err)
}
// Category
if err := r.DB.First(&product.Category, product.CategoryID).Error; err != nil {
return fmt.Errorf("category not found: %w", err)
}
// Colour
if err := r.DB.First(&product.Colour, product.ColourID).Error; err != nil {
return fmt.Errorf("colour not found: %w", err)
}
// Size
if err := r.DB.First(&product.Size, product.SizeID).Error; err != nil {
return fmt.Errorf("size not found: %w", err)
}
return nil
}