fix on stocks on store catalogue

This commit is contained in:
2026-08-31 16:26:06 +05:30
parent d55f101834
commit bc10b589cd
4 changed files with 172 additions and 11 deletions

View File

@@ -415,14 +415,21 @@ func (s *productService) ImportCatalogueProduct(reqs []models.ImportCataloguePro
// column — not products.retailprice — is what the store catalogue, the
// customer app and each order line read. The result was a catalogue
// where nothing had a price and every order booked an amount of 0.
// `publishedat` is deliberately absent — the field is `<-:false`, so
// this row is created unpublished and belongs to the admin catalogue
// only. Releasing it to the shops is PublishProduct, which refuses
// without a price.
// `publishedat` is not written HERE — the field is `<-:false` — but the
// row does not stay unpublished. PublishPricedLocations below releases
// the ones that arrived with a price, which is every row of a
// spreadsheet import.
//
// Importing used to be publication: this row existed, and membership of
// this table was the whole test, so a product reached every shop the
// moment it was imported and before anyone had priced it.
// The gate exists to stop an UNPRICED product reaching a till that would
// ring it up at zero. An import that carries a price has already met that
// condition, so demanding a second manual release protected nothing and
// cost a great deal: nothing in the backend filters on `publishedat`, so
// the products were on sale in the customer app while the merchant's own
// store catalogue — the one screen that does read it — showed nothing.
//
// Importing used to be publication unconditionally, which was the
// opposite error: a product reached every shop the moment it was
// imported and before anyone had priced it.
locations = append(locations, models.Productlocations{
Tenantid: req.Tenantid,
Locationid: req.Locationid,
@@ -434,7 +441,24 @@ func (s *productService) ImportCatalogueProduct(reqs []models.ImportCataloguePro
})
}
return s.repo.CreateProductLocation(locations)
if err := s.repo.CreateProductLocation(locations); err != nil {
return err
}
// Release what arrived priced.
//
// After the rows exist, not before: publishing addresses
// (tenantid, locationid, productid), and the productid of a brand-new
// snapshot is only known once it has been written.
refs := make([]models.ProductLocationRef, 0, len(locations))
for _, location := range locations {
refs = append(refs, models.ProductLocationRef{
Tenantid: location.Tenantid,
Locationid: location.Locationid,
Productid: location.Productid,
})
}
return s.repo.PublishPricedLocations(refs)
}
func (s *productService) GetImportedCatalogueRefs(tenantid int, brand string) ([]models.ImportedCatalogueRef, error) {