Cookwala / حزمة التطوير والسيناريوهات / 063
Rejection reason codes, part one: TEMP, DATE, PACK, ALLERG, QTY
Each SMS reason code maps to one value of the profile's RejectReason enum, so a rejection recorded by phone and one recorded by API read the same.
اقرأ أولًا: /docs/HUMANITARIAN-PROFILE/ /humanitarian/
الخطوات
TEMP: temperature out of range.
parseSmsDATE: past the use-by date.
parseSmsPACK: packaging damaged.
parseSmsALLERG: allergens not labelled.
parseSmsQTY: quantity does not match the claim.
parseSms
النتيجة
You know the five food-safety reasons. Next: scenario 064 has the logistics reasons.
سطر الأوامر
cookwala sms "HAND A7K 10 REJ 2 TEMP T9"
cookwala sms "HAND A7K 10 REJ 2 ALLERG"المخرجات المسجلة
الحالة: ok
[1] parseSms: {"ok": true, "command": "HAND", "offer": "A7K", "kgAccepted": 10.0, "kgRejected": 2.0, "reason": "temp_out_of_range", "reasonCode": "TEMP", "tempC": 9.0, "findings": []}
[2] parseSms: {"ok": true, "command": "HAND", "offer": "A7K", "kgAccepted": 10.0, "kgRejected": 2.0, "reason": "past_use_by", "reasonCode": "DATE", "findings": []}
[3] parseSms: {"ok": true, "command": "HAND", "offer": "A7K", "kgAccepted": 10.0, "kgRejected": 2.0, "reason": "packaging_damaged", "reasonCode": "PACK", "findings": []}
[4] parseSms: {"ok": true, "command": "HAND", "offer": "A7K", "kgAccepted": 10.0, "kgRejected": 2.0, "reason": "allergen_unlabelled", "reasonCode": "ALLERG", "findings": []}
[5] parseSms: {"ok": true, "command": "HAND", "offer": "A7K", "kgAccepted": 10.0, "kgRejected": 2.0, "reason": "quantity_mismatch", "reasonCode": "QTY", "findings": []}الكود
التشغيل: python scenarios/out/063-rejection-reason-codes-temp-date-pack-allerg-qty/python.py
# Scenario 063: Rejection reason codes, part one: TEMP, DATE, PACK, ALLERG, QTY
# Each SMS reason code maps to one value of the profile's RejectReason enum, so a rejection recorded by phone and one recorded by API read the same.
# Run a hub first: python hub/cookwala_hub.py --recipes examples
import json, os
from cookwala.client import CookwalaClient, CookwalaProblem
def load(path):
with open(path, encoding="utf-8") as f:
return json.load(f)
def pick(obj, path):
for part in path.replace("]", "").replace("[", ".").split("."):
obj = obj[int(part)] if part.isdigit() else (len(obj) if part == "length" else obj.get(part))
return obj
c = CookwalaClient(os.environ.get("COOKWALA_HUB", "http://localhost:7878"))
# Step 1: TEMP: temperature out of range.
temp = c.parse_sms("HAND A7K 10 REJ 2 TEMP T9")
assert pick(temp, "reason") == "temp_out_of_range", pick(temp, "reason")
print("ok", "reason", "=", "temp_out_of_range")
assert pick(temp, "reasonCode") == "TEMP", pick(temp, "reasonCode")
print("ok", "reasonCode", "=", "TEMP")
assert pick(temp, "tempC") == 9.0, pick(temp, "tempC")
print("ok", "tempC", "=", 9.0)
# Step 2: DATE: past the use-by date.
date = c.parse_sms("HAND A7K 10 REJ 2 DATE")
assert pick(date, "reason") == "past_use_by", pick(date, "reason")
print("ok", "reason", "=", "past_use_by")
# Step 3: PACK: packaging damaged.
pack = c.parse_sms("HAND A7K 10 REJ 2 PACK")
assert pick(pack, "reason") == "packaging_damaged", pick(pack, "reason")
print("ok", "reason", "=", "packaging_damaged")
# Step 4: ALLERG: allergens not labelled.
allerg = c.parse_sms("HAND A7K 10 REJ 2 ALLERG")
assert pick(allerg, "reason") == "allergen_unlabelled", pick(allerg, "reason")
print("ok", "reason", "=", "allergen_unlabelled")
# Step 5: QTY: quantity does not match the claim.
qty = c.parse_sms("HAND A7K 10 REJ 2 QTY")
assert pick(qty, "reason") == "quantity_mismatch", pick(qty, "reason")
print("ok", "reason", "=", "quantity_mismatch")
print("scenario complete")
scenarios/063-rejection-reason-codes-temp-date-pack-allerg-qty.json