"""Synthetic example only. No ERP connection; never writes to a business system.""" import csv,copy from pathlib import Path p=Path(__file__).parent rows=[dict(company="T1",warehouse=w,item="F-17",unit="pc",as_of="2026-12-02T09:00:00+05:00",physical=ph,reserved=res) for w,ph,res in [('ALA',30,22),('KSK',20,2)]] with (p/'reference.csv').open('w',newline='') as f: w=csv.DictWriter(f,rows[0]);w.writeheader();w.writerows(rows) def read(rs): result={} for r in rs: k=tuple(r[t] for t in ('company','warehouse','item','unit','as_of')) if k in result: raise ValueError('duplicate key') result[k]=int(r['physical'])-int(r['reserved']) return result ref=read(rows);wrong=copy.deepcopy(rows) # Instead transfer 6 reservations, leaving both warehouse counts plausible. wrong[0]['reserved'],wrong[1]['reserved']=16,8 bad=read(wrong) assert list(ref.values())==[8,18] and list(bad.values())==[14,12] assert sum(ref.values())==sum(bad.values())==26 and bad!=ref assert ref[next(iter(ref))]<12<=bad[next(iter(bad))] for field,val in [('as_of','2026-12-02T09:05:00+05:00'),('unit','box'),('company','T2')]: t=copy.deepcopy(rows); t[0][field]=val; assert read(t).keys()!=ref.keys() assert read(rows[:1]).keys()!=ref.keys() try: read(rows+rows[:1]) except ValueError: pass else: raise AssertionError('duplicate accepted') print('PASS: expected 8/18 vs 14/12, total 26; order 12; time, unit, company, missing row and duplicate checked.')