1
📥
Fetch product dataRetail database — name, base price, promo rules
2
🧮
Apply pricing rulesDiscount percent, bundle offers, member price
3
📟
Generate barcodeEAN-13 format with check-digit validation
4
🖨️
Format print tagPrint-ready label — product, price, barcode, size
import json, math
products = [
{"name":"Kemeja Cotton","price":49.90,"discount":0},
{"name":"Kasut Sukan","price":159.00,"discount":"20%"},
{"name":"Jam Tangan","price":89.00,"discount":"15%"},
{"name":"Set PROMO","price":199.00,"discount":"Bundle 30%"}
]
def calc_discount(price, disc):
if disc == 0 or disc == "0": return price
pct = float(str(disc).replace("Bundle ","").replace("%",""))
return round(price * (1 - pct/100), 2)
def gen_barcode(prefix, idx):
raw = prefix + str(idx).zfill(3)
chk = sum(int(d)*3 if i%2 else int(d) for i,d in enumerate(raw))%10
chk = (10-chk)%10
return raw + str(chk)
def format_tag(p, idx):
final = calc_discount(p["price"], p["discount"])
barcode = gen_barcode("955100", idx+1)
return {"product": p["name"], "price": p["price"],
"final": final, "barcode": barcode}
tags = [format_tag(p,i) for i,p in enumerate(products)]
print(json.dumps(tags, indent=2))