v1.0.176: grouping.py — apply_groups error handling + doc_id null check
This commit is contained in:
@@ -142,16 +142,19 @@ def apply_groups(batch_id, groups_data):
|
||||
counterparty = g.get("counterparty", "")
|
||||
docs = g.get("documents", [])
|
||||
|
||||
# Create contract
|
||||
try:
|
||||
c = db_contracts.insert(contract_number, counterparty)
|
||||
contract_id = c["id"]
|
||||
contract_ids.append(contract_id)
|
||||
|
||||
# Create supplements in order
|
||||
for i, d in enumerate(docs):
|
||||
doc_id = d.get("id")
|
||||
if not doc_id:
|
||||
continue
|
||||
supp_type = "initial" if i == 0 else "additional"
|
||||
db_supplements.insert(contract_id, doc_id, supp_type)
|
||||
created += 1
|
||||
except Exception as e:
|
||||
return {"ok": False, "error": f"apply_groups failed at {contract_number}: {e}"}
|
||||
|
||||
return {"ok": True, "created": created, "contract_ids": contract_ids}
|
||||
|
||||
Reference in New Issue
Block a user