changes
This commit is contained in:
@@ -109,6 +109,21 @@ func (s *productService) CreateProductStock(stocks []models.Productstock) error
|
||||
// column on products cannot express it anyway: the same product can be
|
||||
// stocked at one outlet and empty at another.
|
||||
if len(locRefs) > 0 {
|
||||
// Shelve before deriving availability, and in that order.
|
||||
//
|
||||
// Stock arriving at an outlet that has no productlocations row is the
|
||||
// case this exists for: the ledger was written, the console showed the
|
||||
// balance climbing, and the customer app never saw the product because
|
||||
// its query joins productlocations and filters on the outlet. The whole
|
||||
// request-approve-receive path ended in an invisible product.
|
||||
//
|
||||
// SyncProductLocationStatus cannot do this itself — it is an UPDATE,
|
||||
// and with no row it changes nothing and reports success. Running it
|
||||
// second means the row created here immediately gets its real status
|
||||
// derived from the ledger rather than keeping the seeded one.
|
||||
if err := s.repo.EnsureProductLocation(locRefs); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.repo.SyncProductLocationStatus(locRefs); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -271,6 +286,29 @@ func (s *productService) ImportCatalogueProduct(reqs []models.ImportCataloguePro
|
||||
if err := s.repo.UpdateProductPricing(productID, req.Retailprice, req.Productcost, req.Taxpercent); err != nil {
|
||||
return err
|
||||
}
|
||||
// Re-importing corrects the CATEGORY too, not just the price.
|
||||
//
|
||||
// This branch used to update pricing alone, which made a product
|
||||
// imported without a category permanently unreachable: the customer
|
||||
// app’s endpoint rejects categoryid 0, UpdateProduct writes only
|
||||
// productlocations.status, and re-importing — the obvious repair —
|
||||
// silently changed nothing. There was no path back.
|
||||
//
|
||||
// UpdateProductCategory ignores a zero, so an import that does not
|
||||
// carry a category still cannot erase one that is already right.
|
||||
if err := s.repo.UpdateProductCategory(productID, req.Categoryid, req.Subcategoryid); err != nil {
|
||||
return err
|
||||
}
|
||||
// Re-importing corrects the CATEGORY too, not just the price.
|
||||
//
|
||||
// This branch used to update pricing alone, which made a product
|
||||
// imported without a category permanently unreachable: the customer
|
||||
// app's endpoint rejects categoryid 0, `UpdateProduct` writes only
|
||||
// productlocations.status, and re-importing — the obvious repair —
|
||||
// silently changed nothing. There was no path back.
|
||||
//
|
||||
// UpdateProductCategory ignores a zero, so an import that does not
|
||||
// carry a category still cannot erase one that is already right.
|
||||
} else {
|
||||
snapshot := models.Products{
|
||||
Tenantid: req.Tenantid,
|
||||
|
||||
Reference in New Issue
Block a user