Files
37duAutomation/plugins/XQ0001-0100/XQ0031_XQ0032 物料收发与采购订单导出/data/k3_report_api.py
T
puddy fb1e662b81 feat(plugin): XQ0031_XQ0032 1.1.4 改为 ERP WebAPI 接口版
- 物料收发汇总表改走 StockReportQueryService.GetReportData 分页取数,
  采购订单列表改走 ExecuteBillQuery;一次账密登录两张报表共用会话,不再起浏览器
- 新增 data/k3_report_api.py 适配层(组织内码、过滤方案、仓库条件),底层调 erpsdk
- 导出格式与 K3 引出保持一致(说明行/表头行/合计行、新旧版列差异),前端产物重建
- 需求单开发文档同步
2026-11-16 11:27:43 +08:00

60 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""物料收发汇总表 —— 报表取数的插件内适配层(底层能力在 erpsdk)。
本模块只保留「插件口径」相关的部分(组织编码→内码、过滤方案、仓库条件、插件日志),
登录/会话/分页/接口协议全部交给 erpsdk(公共库,SDK 下发)。
实测口径(2026-11,与人工「引出」逐行一致):
- 时间范围:快捷条件 BeginDate / EndDate;
- 库存组织:快捷条件 StockOrgId,值必须是组织**内码**;
- 仓库:高级条件 FSTOCKNUMBER(编码列,多条 OR);
- 过滤方案必须是有元数据的方案(系统默认方案返回 0 行)。
"""
from erpsdk import ErpClient, ErpError
from .. import config
# 内网 ERP 是自签/内部证书,requests 默认会因 verify=False 抛 InsecureRequestWarning,
# 写 stderr 被壳子记成 [ERROR]。这里统一压掉(erpsdk 0.1.1 起也内置了同样的处理)。
import urllib3
from urllib3.exceptions import InsecureRequestWarning
urllib3.disable_warnings(InsecureRequestWarning)
TAG = '[物料收发汇总表-接口]'
def org_id(erp, org_text):
"""组织显示名(如「99.01 重庆金七象供应链管理有限公司」)→ 接口所需内码。"""
code = str(org_text or '').strip().split(' ')[0].split('\u3000')[0]
mapping = config.REPORT_ORG_ID.get(erp, {})
if code in mapping:
return mapping[code]
raise ErpError(f'查询组织「{org_text}」没有配置内码({erp}),'
f'请在 config.REPORT_ORG_ID 补充:{code} → <组织内码>')
def login(erp, username, password):
"""账密登录,返回可复用的 ErpClient。"""
client = ErpClient(erp, timeout=60, logger=config.log, retry=config.RETRY_MAX)
client.login(username, password)
return client
def session_alive(client, erp=None):
return bool(client and client.session_alive())
def fetch(erp, username, password, begin, end, org_text, stock_codes,
progress=None, session=None):
"""取一档日期的报表数据,返回 (rows, client);client 可在多档之间复用。"""
if session is None or not session.session_alive():
session = login(erp, username, password)
rows = session.report_query(
config.REPORT_FORM_ID, config.REPORT_SCHEME[erp], begin, end,
org_id=org_id(erp, org_text), stock_codes=stock_codes,
limit=config.REPORT_API_PAGE, progress=progress)
if not rows:
config.log(f'{TAG} {begin}~{end} 无数据(组织/仓库/日期或方案口径可能不匹配)')
return rows, session