Spaces:
Restarting
Restarting
Update main.py
Browse files3628 unmodified lines362936303631363236333634363510 unmodified lines36463647364836493650365136522 unmodified lines365536563657365836593660366111 unmodified lines36733674367536763677367836791 unmodified line36813682368336843685368636871 unmodified line36893690369136923693369436953628 unmodified lines.eq("inventory_id", item_id).eq("batch_number", target_batch_number).maybe_single().execute())existing_batch = batch_query.data if batch_query else Noneexcept Exception as e:10 unmodified lines"updated_at": datetime.now(timezone.utc).isoformat()}).eq("id", existing_batch["id"]).execute())logger.info(f"β Updated batch {target_batch_number} for inventory {item_id}")# If the batch number has changed from the inventory record, update it2 unmodified linesclient.table("inventory").update({"batch_number": target_batch_number}).eq("id", item_id).execute())else:# No batch found β create a new one11 unmodified lines"created_at": datetime.now(timezone.utc).isoformat(),"updated_at": datetime.now(timezone.utc).isoformat()}await run_sync_db_call(client.table("inventory_batches").insert(batch_data).execute())logger.info(f"π Inserted new batch {target_batch_number} for inventory {item_id}")# Also update the inventory record's batch_number to the new oneif target_batch_number != existing.data.get("batch_number"):1 unmodified lineclient.table("inventory").update({"batch_number": target_batch_number}).eq("id", item_id).execute())else:# No expiry date provided β we could optionally delete orphaned batches1 unmodified line# 4. Update inventory recordresult = await run_sync_db_call(client.table("inventory").update(update_data).eq("id", item_id).eq("org_id", org_id).execute3628 unmodified lines362936303631363236333634363510 unmodified lines36463647364836493650365136522 unmodified lines365536563657365836593660366111 unmodified lines367336743675367636773678367936803681368236831 unmodified line36853686368736883689369036911 unmodified line369336943695369636973698369937003628 unmodified lines.eq("inventory_id", item_id).eq("batch_number", target_batch_number).maybe_single().execute)existing_batch = batch_query.data if batch_query else Noneexcept Exception as e:10 unmodified lines"updated_at": datetime.now(timezone.utc).isoformat()}).eq("id", existing_batch["id"]).execute)logger.info(f"β Updated batch {target_batch_number} for inventory {item_id}")# If the batch number has changed from the inventory record, update it2 unmodified linesclient.table("inventory").update({"batch_number": target_batch_number}).eq("id", item_id).execute)else:# No batch found β create a new one11 unmodified lines"created_at": datetime.now(timezone.utc).isoformat(),"updated_at": datetime.now(timezone.utc).isoformat()}await run_sync_db_call(client.table("inventory_batches").insert(batch_data).execute)logger.info(f"π Inserted new batch {target_batch_number} for inventory {item_id}")# Also update the inventory record's batch_number to the new oneif target_batch_number != existing.data.get("batch_number"):1 unmodified lineclient.table("inventory").update({"batch_number": target_batch_number}).eq("id", item_id).execute)else:# No expiry date provided β we could optionally delete orphaned batches1 unmodified line# 4. Update inventory recordresult = await run_sync_db_call(client.table("inventory").update(update_data).eq("id", item_id).eq("org_id", org_id).execute
main.py+11-6