Sync stock status on restock and expose live stock on getproductbyvariant
Two gaps found while auditing the order/stock flow: - Receiving stock via an approved stock request only updated products.productstatus (a global per-product flag). A location flagged outofstock by CreateOrder never got reactivated, since nothing touched productlocations.status on the way back in. CreateProductStock now reactivates the specific (tenant, location, product) row to "available" for every "in" entry, the counterpart to how it gets flagged out. - getproductbyvariant returned no stock info at all, so the app could only find out a product was unavailable from the 409 at order time. It now accepts an optional locationid and, when passed, returns live productstock (same SUM(in)-SUM(out) formula the order check uses) and locationstatus per product. Omitting locationid keeps the old response shape. Added MOBILE_ORDER_VERIFICATION.md as a handoff doc for the mobile team covering the expected request/response shapes and how to verify their integration. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -83,6 +83,13 @@ type Products struct {
|
||||
Othercost float64 `json:"othercost,omitempty"`
|
||||
Approve int `json:"approve"`
|
||||
Productstatus string `json:"productstatus" `
|
||||
// Populated only by queries scoped to a specific location (e.g.
|
||||
// GetProductByVariant when locationid is passed): Productstock becomes
|
||||
// the live SUM(in)-SUM(out) balance from productstocks — the same
|
||||
// formula CreateOrder's stock check uses — and Locationstatus mirrors
|
||||
// productlocations.status ("outofstock"/"available") for that store.
|
||||
// Left at zero values for callers that don't scope to a location.
|
||||
Locationstatus string `json:"locationstatus,omitempty" gorm:"->"`
|
||||
// Status string `json:"status" gorm:"default:InActive"`
|
||||
// Status string `json:"status" gorm:"-"`
|
||||
}
|
||||
@@ -306,6 +313,15 @@ type Productlocations struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// ProductLocationRef identifies a single (tenant, location, product) row in
|
||||
// productlocations — used to reactivate it after new stock arrives, the
|
||||
// per-location counterpart to CreateOrder's outofstock flag.
|
||||
type ProductLocationRef struct {
|
||||
Tenantid int
|
||||
Locationid int
|
||||
Productid int
|
||||
}
|
||||
|
||||
type ProductSubcategory struct {
|
||||
Subcatid int `json:"subcatid"`
|
||||
Categoryid int `json:"categoryid"`
|
||||
|
||||
Reference in New Issue
Block a user