1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| from audit import connect,dump,P
| import json
| r=json.loads((P/'result-applied.json').read_text(encoding='utf-8'))
| c=connect();data={}
| def take(table,field,ids):
| ids=list(set(ids))
| with c.cursor() as q:
| q.execute('select * from `'+table+'` where `'+field+'` in ('+','.join(['%s']*len(ids))+')',ids)
| data[table]=q.fetchall()
| try:
| root={'crm_sale_quotation':[x['quotation_id'] for x in r['groups'].values()],'crm_contract':[x['contract_id'] for x in r['groups'].values()],'erp_sale_order':[x['order_id'] for x in r['groups'].values()],'crm_receivable_plan':[x['receivable_plan_id'] for x in r['groups'].values()],'mes_pro_work_order':[x['wo_id'] for x in r['links']],'mes_pro_mps':[x['mps_id'] for x in r['links']]}
| for t,ids in root.items():take(t,'id',ids)
| for t,f,parent in [('crm_sale_quotation_product','quotation_id','crm_sale_quotation'),('crm_contract_product','contract_id','crm_contract'),('erp_sale_order_items','order_id','erp_sale_order'),('mes_pro_work_order_process','work_order_id','mes_pro_work_order'),('mes_pro_work_order_bom','work_order_id','mes_pro_work_order'),('mes_pro_task','work_order_id','mes_pro_work_order'),('mes_pro_feedback','work_order_id','mes_pro_work_order'),('mes_pro_work_order_param_record','work_order_id','mes_pro_work_order'),('mes_pro_task_assignee','task_id','mes_pro_task'),('mes_pro_work_order_param_record_detail','record_id','mes_pro_work_order_param_record')]:take(t,f,[x['id'] for x in data[parent]])
| take('crm_permission','biz_id',root['crm_sale_quotation']+root['crm_contract']+root['crm_receivable_plan'])
| expected={(9,i) for i in root['crm_sale_quotation']}|{(5,i) for i in root['crm_contract']}|{(8,i) for i in root['crm_receivable_plan']}
| data['crm_permission']=[x for x in data['crm_permission'] if (x['biz_type'],x['biz_id']) in expected]
| ids=[x['mdm_id'] for x in r['links']];take('mdm_item','id',ids);take('mes_md_item','mdm_item_id',ids)
| take('mes_pro_route','code',['RT-FLOWER-BOTTLE-PACK']);take('mes_pro_route_process','route_id',[x['id'] for x in data['mes_pro_route']])
| with c.cursor() as q:
| q.execute('select * from mes_pro_route_product where deleted=0 and item_id in ('+','.join(['%s']*len(ids))+') and remark=%s',ids+['按10月15日计划产品配置;配方及投料沿用产品自身BOM,不套用其他规格。']);data['mes_pro_route_product']=q.fetchall()
| codes=[x['code'] for t in ['mes_pro_work_order','mes_pro_mps','mes_pro_task','mes_pro_feedback'] for x in data[t]]
| q.execute('select * from mes_md_auto_code_record where result in ('+','.join(['%s']*len(codes))+')',codes);data['mes_md_auto_code_record']=q.fetchall()
| refs={}
| for t in ['mes_pro_route','mes_pro_process','mes_md_workstation','mes_dv_machinery','mes_pd_process_param_template','mdm_unit_measure','mes_md_unit_measure','mes_md_auto_code_rule','mdm_item','mes_md_item']:
| q.execute('select * from `'+t+'` where deleted=0');refs[t]=q.fetchall()
| q.execute('select id,nickname,status from system_users where deleted=0');refs['system_users']=q.fetchall()
| q.execute('select id,name from crm_customer where deleted=0');refs['crm_customer']=q.fetchall()
| dump('sync-export.json',{'data':data,'references':refs,'local_result':r})
| print({t:len(v) for t,v in data.items()})
| finally:c.rollback();c.close()
|
|