- tags
- #shop
shop-stock¶
Low stock. When a stock level drops below its reorder point, whoever runs the shop hears about it, with the supplier to call and how long they take to deliver. It runs when a stock level is changed by hand (the trigger in Init) and after every reservation (shop-orders).
$when shop.checkStock (id: String) {
s = dom.find(cls = "StockLevel", key = id)
if (s.qty < s.reorderAt) {
products = dom.list(cls = "Product").data filter (p => p.variants exists (v => v.sku is s.sku))
sup = dom.find(cls = "Supplier", key = products[0].supplier)
shop.notify(to = "admins", text = "Low stock: ${s.sku} in ${s.warehouse} is down to ${s.qty} (reorder at ${s.reorderAt}); ${sup.name} delivers in ${sup.leadDays} days")
payload = "low"
} else {
payload = "ok"
}
}
Putting stock back¶
$when shop.restock (sku: String, qty) {
levels = dom.list(cls = "StockLevel").data filter (x => x.sku is sku)
s = levels[0]
payload = dom.upsert(cls = "StockLevel", entity = s + {qty: s.qty + qty})
}