changes fixed in the catalogue
This commit is contained in:
@@ -30,13 +30,20 @@ import (
|
||||
// Idempotent: publishing an already-published product re-prices it and leaves
|
||||
// the original `publishedat` alone, so "when did this go live" survives a
|
||||
// second click.
|
||||
func (r *productRepository) PublishProduct(tenantID, productID int, price float64) (int, error) {
|
||||
func (r *productRepository) PublishProduct(tenantID, productID int, price, taxPercent float64) (int, error) {
|
||||
if tenantID <= 0 || productID <= 0 {
|
||||
return 0, fmt.Errorf("tenantid and productid are required")
|
||||
}
|
||||
if price <= 0 {
|
||||
return 0, fmt.Errorf("set a price before publishing — a product with no price cannot be sold at a till")
|
||||
}
|
||||
// Zero is a legitimate rate — plenty of staples are zero-rated — so it
|
||||
// cannot double as "not specified". Negative is refused rather than stored:
|
||||
// three products already carry taxpercent -1, which yields negative tax
|
||||
// under either convention.
|
||||
if taxPercent < 0 {
|
||||
return 0, fmt.Errorf("tax percentage cannot be negative")
|
||||
}
|
||||
|
||||
var affected int
|
||||
err := r.db.Transaction(func(tx *gorm.DB) error {
|
||||
@@ -93,9 +100,9 @@ func (r *productRepository) PublishProduct(tenantID, productID int, price float6
|
||||
// The master price follows, so an outlet that has no row of its own
|
||||
// still reads the right figure through the COALESCE fallback in
|
||||
// GetProducts.
|
||||
return tx.Exec(`UPDATE products SET retailprice = ?, updated = NOW()
|
||||
return tx.Exec(`UPDATE products SET retailprice = ?, taxpercent = ?, updated = NOW()
|
||||
WHERE productid = ? AND tenantid = ?`,
|
||||
price, productID, tenantID).Error
|
||||
price, taxPercent, productID, tenantID).Error
|
||||
})
|
||||
|
||||
return affected, err
|
||||
|
||||
Reference in New Issue
Block a user