pricing in app

This commit is contained in:
2026-09-03 15:44:09 +05:30
parent 7ed821e8b0
commit 0d17f46fcf
2 changed files with 26 additions and 6 deletions

View File

@@ -1065,11 +1065,15 @@ func (r *productRepository) GetProductByVariant(tenantid, variantid, locationid,
// query just computed, so the entry cannot disagree with the row it
// came from.
self := models.Productvariant{
Tenantid: data[i].Tenantid,
Productid: data[i].Productid,
Variantproductid: data[i].Productid,
Variantname: variantLabelFor(data[i]),
Status: "Active",
Tenantid: data[i].Tenantid,
Productid: data[i].Productid,
Variantproductid: data[i].Productid,
Variantname: variantLabelFor(data[i]),
Status: "Active",
// The parent is one of its own sizes, so its entry has to carry
// money in the same field the others do. Without this the first
// option in every picker read 0 while the rest were priced.
Price: data[i].Price,
Variantproductname: data[i].Productname,
Variantprice: data[i].Price,
Variantstock: data[i].Productstock,

View File

@@ -118,6 +118,17 @@ func (r *productRepository) VariantsForProducts(tenantid, locationid int, produc
return out, nil
}
// `price` is emitted as the EFFECTIVE price, not the raw override.
//
// The column holds an override where 0 means "no override", so a client
// reading the obvious field name got 0 for every size while the real figure
// sat in `variantprice` beside it. Measured on R mart: a grouped product
// whose three sizes are priced 50, 250 and 500 was emitting price 0 on all
// three, so the app showed them as free.
//
// Selected after `v.*` so it overwrites the raw column on the way out — the
// same trick GetProductByVariant uses for `quantity`. The stored override is
// untouched; only what is emitted changes.
var rows []models.Productvariant
err := r.db.
Table("productvariants v").
@@ -126,6 +137,11 @@ func (r *productRepository) VariantsForProducts(tenantid, locationid int, produc
p.productname AS variantproductname,
COALESCE(p.unitvalue, '') AS variantunitvalue,
COALESCE(p.productunit, '') AS variantproductunit,
COALESCE(NULLIF(v.price, 0), NULLIF((
SELECT pl.price FROM productlocations pl
WHERE pl.productid = v.variantproductid AND pl.tenantid = v.tenantid AND pl.locationid = ?
LIMIT 1
), 0), p.retailprice, 0) AS price,
-- The variant’s own override wins, then the outlet’s price, then the
-- master price. The override was being ignored entirely: a size
-- priced differently from its product was sold at the product’s
@@ -142,7 +158,7 @@ func (r *productRepository) VariantsForProducts(tenantid, locationid int, produc
FROM productstocks ps
WHERE ps.productid = v.variantproductid AND ps.tenantid = v.tenantid AND ps.locationid = ?
), 0) AS variantstock
`, locationid, locationid).
`, locationid, locationid, locationid).
// INNER, and that is the intended filter: a variant whose product was
// deleted is not a size a shopper can be offered.
Joins("JOIN products p ON p.productid = v.variantproductid AND p.tenantid = v.tenantid").