test_erp.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. token = AccessToken.get_current_token()
  20. print('【2】token:',token)
  21. # 所有同步操作统一入口
  22. inbound_bill = InboundBill.objects.first()
  23. print(f"ERP单号: {inbound_bill.number}")
  24. ProductionInboundAuditsync = ProductionInboundAuditSync(inbound_bill)
  25. PurchaseInboundAuditsync = PurchaseInboundAuditSync(inbound_bill)
  26. OtherInboundAuditsync = OtherInboundAuditSync(inbound_bill)
  27. OtherOutboundAuditsync = OtherOutboundAuditSync(inbound_bill)
  28. ProductionOutboundAuditsync = ProductionOutboundAuditSync(inbound_bill)
  29. PurchaseInboundSavesync = PurchaseInboundSaveSync(inbound_bill)
  30. SaleOutboundSavesync = SaleOutboundSaveSync(inbound_bill)
  31. # 同步生产入库单
  32. success = ProductionInboundAuditsync.execute_sync()
  33. # 同步采购入库单
  34. success = PurchaseInboundAuditsync.execute_sync()
  35. # 同步其它入库单
  36. success = OtherInboundAuditsync.execute_sync()
  37. # 同步其它出库单
  38. success = OtherOutboundAuditsync.execute_sync()
  39. # 同步生产出库单
  40. success = ProductionOutboundAuditsync.execute_sync()
  41. # 同步采购入库单保存
  42. success = PurchaseInboundSavesync.execute_sync()
  43. # 同步销售出库单保存
  44. success = SaleOutboundSavesync.execute_sync()
  45. # 通过模型字段直接访问ERP ID
  46. print(f"ERP审核单号: {inbound_bill.erp_audit_id}")
  47. print(f"ERP采购单号: {inbound_bill.erp_save_id}")
  48. print("✅ 方法生成成功!")
  49. except Exception as e:
  50. print(f"❌ 生成失败:{str(e)}")
  51. import traceback
  52. traceback.print_exc()
  53. if __name__ == "__main__":
  54. setup_django()
  55. main()