test_erp.py 2.7 KB

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