test_erp.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # generate_locations.py
  2. import os
  3. import django
  4. import sys
  5. def setup_django():
  6. # 使用原始字符串处理Windows路径
  7. project_path = "D:/Document/code/vue/greater_wms"
  8. sys.path.append(project_path)
  9. # 根据实际目录名设置(注意下划线)
  10. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'greaterwms.settings')
  11. django.setup()
  12. def main():
  13. try:
  14. # 从正确的应用导入模型
  15. from erp.views import AccessToken ,ProductionInboundAuditSync,PurchaseInboundAuditSync,OtherInboundAuditSync,OtherOutboundAuditSync,ProductionOutboundAuditSync,PurchaseInboundSaveSync,SaleOutboundSaveSync
  16. from erp.models import InboundBill
  17. token = AccessToken.get_current_token()
  18. print('【1】token:',token)
  19. # 所有同步操作统一入口
  20. inbound_bill = InboundBill.objects.first()
  21. print(f"ERP单号: {inbound_bill.number}")
  22. ProductionInboundAuditsync = ProductionInboundAuditSync(inbound_bill)
  23. PurchaseInboundAuditsync = PurchaseInboundAuditSync(inbound_bill)
  24. OtherInboundAuditsync = OtherInboundAuditSync(inbound_bill)
  25. OtherOutboundAuditsync = OtherOutboundAuditSync(inbound_bill)
  26. ProductionOutboundAuditsync = ProductionOutboundAuditSync(inbound_bill)
  27. PurchaseInboundSavesync = PurchaseInboundSaveSync(inbound_bill)
  28. SaleOutboundSavesync = SaleOutboundSaveSync(inbound_bill)
  29. # 同步生产入库单
  30. success = ProductionInboundAuditsync.execute_sync()
  31. # 同步采购入库单
  32. success = PurchaseInboundAuditsync.execute_sync()
  33. # 同步其它入库单
  34. success = OtherInboundAuditsync.execute_sync()
  35. # 同步其它出库单
  36. success = OtherOutboundAuditsync.execute_sync()
  37. # 同步生产出库单
  38. success = ProductionOutboundAuditsync.execute_sync()
  39. # 同步采购入库单保存
  40. success = PurchaseInboundSavesync.execute_sync()
  41. # 同步销售出库单保存
  42. success = SaleOutboundSavesync.execute_sync()
  43. # 通过模型字段直接访问ERP ID
  44. print(f"ERP审核单号: {inbound_bill.erp_audit_id}")
  45. print(f"ERP采购单号: {inbound_bill.erp_save_id}")
  46. print("✅ 方法生成成功!")
  47. except Exception as e:
  48. print(f"❌ 生成失败:{str(e)}")
  49. import traceback
  50. traceback.print_exc()
  51. if __name__ == "__main__":
  52. setup_django()
  53. main()