This commit is contained in:
512song committed 2025-08-24 19:10:51 +08:00
1 parent a029e8b3a6
commit 5bd40c3755
1 file changed
+523
+523
View File
@@ -0,0 +1,523 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "7b8c910e-dc62-4710-a40e-044e8d9b32ca",
"metadata": {},
"source": [
"## 获取科目表信息"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23a33174-3522-4a4e-b0ec-fde8ab0e6277",
"metadata": {},
"outputs": [],
"source": [
"import pymysql\n",
"db = pymysql.connect(host = \"172.19.0.10\",user = \"songyi\",password = \"yylzs\",database = \"_5e5899d8398b5f7b\" )\n",
"cursor = db.cursor()\n",
"sql = 'select account_name,account_number,parent_account from tabAccount where company= %s'\n",
"cursor.execute(sql, {'北京运动一百体育文化发展有限公司'})\n",
"data = cursor.fetchall()\n",
"for item in data:\n",
" print(item)\n",
"print(type(data))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b91b590d-3761-4da9-842c-2109d63a8279",
"metadata": {},
"outputs": [],
"source": [
"import pymysql\n",
"db = pymysql.connect(host = \"172.19.0.10\",user = \"songyi\",password = \"yylzs\",database = \"_5e5899d8398b5f7b\" )\n",
"cursor = db.cursor()\n",
"\n",
"dict1 = {}\n",
"\n",
"sql = 'select account_name,account_number,parent_account from tabAccount where company= %s and parent_account is null'\n",
"cursor.execute(sql, {'北京运动一百体育文化发展有限公司'})\n",
"data = cursor.fetchall()\n",
"for item in data:\n",
" dict1.setdefault(item[1],{})\n",
" dict1[item[1]]['name'] = item[0]\n",
"# 获得科目分类\n",
"#print(dict1)\n",
"sql = 'select account_name,account_number,parent_account from tabAccount where company= %s and parent_account is not null and account_number is not null'\n",
"cursor.execute(sql, {'北京运动一百体育文化发展有限公司'})\n",
"data = cursor.fetchall()\n",
"dict2 = {}\n",
"for k, v in dict1.items():\n",
" for item in data:\n",
" parent = item[2].split(' - ')[0]\n",
" if parent == k:\n",
" dict2.setdefault(item[1],{})\n",
" dict2[item[1]]['name'] = item[0]\n",
"# 获得科目明细\n",
"dict3 = {}\n",
"\n",
"for item in data:\n",
" parent = item[2].split(' - ')[0]\n",
" if len(item[1]) == 4 and parent in dict2.keys():\n",
" dict3.setdefault(item[1],{})\n",
" dict3[item[1]]['name'] = item[0]\n",
" dict3[item[1]]['category'] = dict2[parent]['name']\n",
" dict3[item[1]]['level'] = 1\n",
" dict3[item[1]]['parent'] = ''\n",
"for item in data:\n",
" parent = item[2].split(' - ')[0]\n",
" if len(item[1]) == 6 and parent in dict3.keys():\n",
" dict3.setdefault(item[1],{})\n",
" dict3[item[1]]['name'] = item[0]\n",
" dict3[item[1]]['category'] = dict3[parent]['category']\n",
" dict3[item[1]]['level'] = 2\n",
" dict3[item[1]]['parent'] = parent \n",
"for item in data:\n",
" parent = item[2].split(' - ')[0]\n",
" if len(item[1]) == 8 and parent in dict3.keys():\n",
" dict3.setdefault(item[1],{})\n",
" dict3[item[1]]['name'] = item[0]\n",
" dict3[item[1]]['category'] = dict3[parent]['category']\n",
" dict3[item[1]]['level'] = 3\n",
" dict3[item[1]]['parent'] = parent \n",
" \n",
"for k, v in dict3.items():\n",
" print(k,v['name'],v['category'],v['level'],v['parent'])"
]
},
{
"cell_type": "markdown",
"id": "56e2b3b7-3c5d-4f42-afe3-bcf83b96ab2b",
"metadata": {},
"source": [
"## 获取结账余额表"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "38c9169d-4dcb-44b1-b821-2b9a1fb55ec8",
"metadata": {},
"outputs": [],
"source": [
"import pymysql\n",
"db = pymysql.connect(host = \"172.19.0.10\",user = \"songyi\",password = \"yylzs\",database = \"_5e5899d8398b5f7b\" )\n",
"cursor = db.cursor()\n",
"\n",
"dict1 = {}\n",
"\n",
"sql = 'select account,debit,credit,period_closing_voucher from `tabAccount Closing Balance` where company= %s and closing_date = %s'\n",
"cursor.execute(sql, ('北京运动一百体育文化发展有限公司','2023-03-31'))\n",
"data = cursor.fetchall()\n",
"for item in data:\n",
" print(item)"
]
},
{
"cell_type": "markdown",
"id": "cfcca083-582e-430c-a2d8-bacffbe028de",
"metadata": {},
"source": [
"## 获取凭证"
]
},
{
"cell_type": "code",
"execution_count": 73,
"id": "8e62fbda-69b2-47f1-8bdd-e0a594b27d59",
"metadata": {
"execution": {
"iopub.execute_input": "2025-08-24T10:56:13.901078Z",
"iopub.status.busy": "2025-08-24T10:56:13.900708Z",
"iopub.status.idle": "2025-08-24T10:56:13.923083Z",
"shell.execute_reply": "2025-08-24T10:56:13.920738Z",
"shell.execute_reply.started": "2025-08-24T10:56:13.901045Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('ACC-JV-2025-00001-1', '2023年开账', 534627.6, 534627.6)\n",
"('ACC-JV-2025-00002-1', '计提:1月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00003', '收:1季度银行存款利息', 0.0, 0.0)\n",
"('ACC-JV-2025-00004', '付:网银服务费', 100.0, 100.0)\n",
"('ACC-JV-2025-00005', '付:残联招标服务费及手续费', 204.5, 204.5)\n",
"('ACC-JV-2025-00006-1', '计提:6月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00007', '付:发放6月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00008', '付:网银服务费', 5.0, 5.0)\n",
"('ACC-JV-2025-00009', '收:2季度银行存款利息', 0.0, 0.0)\n",
"('ACC-JV-2025-00010-1', '计提:7月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00011', '付:发放7月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00012-1', '计提:8月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00013', '付:发放8月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00014', '付:办公通讯服务费', 3268.0, 3268.0)\n",
"('ACC-JV-2025-00015-1', '计提:9月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00016', '付:发放9月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00017', '收入:北京海友健康档案管理费', 30000.0, 30000.0)\n",
"('ACC-JV-2025-00018', '收入:北京坤铭教育科技档案管理费', 30000.0, 30000.0)\n",
"('ACC-JV-2025-00019', '收:3季度银行存款利息', 0.0, 0.0)\n",
"('ACC-JV-2025-00020-2', '计提:10月份工资', 20000.0, 20000.0)\n",
"('ACC-JV-2025-00021', '计提:应交个人所得税', 450.0, 450.0)\n",
"('ACC-JV-2025-00022', '扣划:个人所得税', 450.0, 450.0)\n",
"('ACC-JV-2025-00023', '付:发放10月份工资', 19550.0, 19550.0)\n",
"('ACC-JV-2025-00024', '收入:服务费收入', 5500.0, 5500.0)\n",
"('ACC-JV-2025-00025', '计提:11月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00026', '扣划:应交个人所得税', 150.0, 150.0)\n",
"('ACC-JV-2025-00027', '付:发放11月份工资', 9850.0, 9850.0)\n",
"('ACC-JV-2025-00028', '付:办公用房服务费', 15300.0, 15300.0)\n",
"('ACC-JV-2025-00029', '计提:12月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00030', '付:发放12月工资、扣划个人所得税', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00031', '收:4季度银行存款利息', 0.0, 0.0)\n",
"('ACC-JV-2025-00032', '付:网银手续费', 5.0, 5.0)\n",
"('ACC-JV-2025-00033', '结转:2023年本年利润', 43921.48, 43921.48)\n",
"('ACC-JV-2025-00034', '计提:1月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00035', '收:个人所得税代理电子退库', 15.0, 15.0)\n",
"('ACC-JV-2025-00036', '扣划:应交个人所得税', 150.0, 150.0)\n",
"('ACC-JV-2025-00037', '付:发放1月份工资', 9850.0, 9850.0)\n",
"('ACC-JV-2025-00038', '计提:2月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00039', '扣划:应交个人所得税', 150.0, 150.0)\n",
"('ACC-JV-2025-00040', '计提:3月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00041', '扣划:应交个人所得税', 150.0, 150.0)\n",
"('ACC-JV-2025-00042', '收入:北京海友健康管理档案管理费', 20000.0, 20000.0)\n",
"('ACC-JV-2025-00043', '收入:北京海友健康管理体质检测服务费', 53830.0, 53830.0)\n",
"('ACC-JV-2025-00044', '付:发放计提未发放工资', 29700.0, 29700.0)\n",
"('ACC-JV-2025-00045', '收:2季度银行存款利息', 0.0, 0.0)\n",
"('ACC-JV-2025-00046', '计提:4月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00047', '付:网银服务费', 100.0, 100.0)\n",
"('ACC-JV-2025-00048', '扣划:应交个人所得税', 150.0, 150.0)\n",
"('ACC-JV-2025-00049', '付:发放4月份工资', 9850.0, 9850.0)\n",
"('ACC-JV-2025-00050', '收入:北京海友健康管理体质检测服务费', 77270.0, 77270.0)\n",
"('ACC-JV-2025-00051', '付:归还法人其他应付款', 40000.0, 40000.0)\n",
"('ACC-JV-2025-00052', '计提:5月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00053', '扣划:应交个人所得税', 150.0, 150.0)\n",
"('ACC-JV-2025-00054', '付:发放5月份工资', 9850.0, 9850.0)\n",
"('ACC-JV-2025-00055', '计提:6月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00056', '扣划:应交个人所得税', 150.0, 150.0)\n",
"('ACC-JV-2025-00057', '付:发放6月份工资', 9850.0, 9850.0)\n",
"('ACC-JV-2025-00058', '收:2季度银行存款利息', 0.0, 0.0)\n",
"('ACC-JV-2025-00059', '付:网银服务费', 5.0, 5.0)\n",
"('ACC-JV-2025-00060', '计提:7月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00061', '扣划:应交个人所得税', 150.0, 150.0)\n",
"('ACC-JV-2025-00062', '付:发放7月份工资', 9850.0, 9850.0)\n",
"('ACC-JV-2025-00063', '计提:8月份工资', 20000.0, 20000.0)\n",
"('ACC-JV-2025-00064', '付:发放8月份工资,扣划个人所得税', 20000.0, 20000.0)\n",
"('ACC-JV-2025-00065', '收:3季度银行存款利息', 0.0, 0.0)\n",
"('ACC-JV-2025-00066', '计提:10月份工资', 20000.0, 20000.0)\n",
"('ACC-JV-2025-00067-1', '付:发放10月工资(部分),扣划个人所得税', 11000.0, 11000.0)\n",
"('ACC-JV-2025-00068', '计提:11月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00069', '收入:北体武术运营管理公司专家服务费', 60000.0, 60000.0)\n",
"('ACC-JV-2025-00070', '扣划:应交个人所得税', 500.0, 500.0)\n",
"('ACC-JV-2025-00071', '付:发放10、11月工资', 18500.0, 18500.0)\n",
"('ACC-JV-2025-00072', '计提:12月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00073', '扣划:应交个人所得税', 500.0, 500.0)\n",
"('ACC-JV-2025-00074', '付:发放12月工资', 9500.0, 9500.0)\n",
"('ACC-JV-2025-00075-1', '收:4季度银行存款利息', 0.0, 0.0)\n",
"('ACC-JV-2025-00076', '付:网银手续费', 5.0, 5.0)\n",
"('ACC-JV-2025-00077-2', '收入:中国石油国际勘探开发公司培训费', 35000.0, 35000.0)\n",
"('ACC-JV-2025-00078', '转:增值税减免转营业外收入', 3085.15, 3085.15)\n",
"('ACC-JV-2025-00079-1', '转:结转2024年度本年利润', 116723.63, 116723.63)\n",
"('ACC-JV-2025-00080', '计提:1月份工资', 20000.0, 20000.0)\n",
"('ACC-JV-2025-00081', '付:发放1月份工资,扣划个人所得税', 20000.0, 20000.0)\n",
"('ACC-JV-2025-00082', '计提:2月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00083', '付:发放2月份工资,扣划个人所得税', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00084', '计提:3月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00085', '扣划:应交个人所得税', 150.0, 150.0)\n",
"('ACC-JV-2025-00086', '付:发放3月份工资', 9850.0, 9850.0)\n",
"('ACC-JV-2025-00087', '应收:北京新越公益基金会培训费', 2000.0, 2000.0)\n",
"('ACC-JV-2025-00088', '收:1季度银行存款利息', 0.0, 0.0)\n",
"('ACC-JV-2025-00089', '收:北京新越公益基金会应收款', 2000.0, 2000.0)\n",
"('ACC-JV-2025-00090', '付:网银手续费', 100.0, 100.0)\n",
"('ACC-JV-2025-00091', '计提:4月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00092', '付:发放4月份工资,扣划个人所得税', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00093', '计提:5月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00094', '付:发放5月份工资,扣划个人所得税', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00095', '收入:中国石油国际勘探开发公司培训费', 34000.0, 34000.0)\n",
"('ACC-JV-2025-00096', '收入:北京海友健康管理公司服务费', 81610.0, 81610.0)\n",
"('ACC-JV-2025-00097', '计提:6月份工资', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00098', '付:发放6月份工资,扣划个人所得税', 10000.0, 10000.0)\n",
"('ACC-JV-2025-00099', '收:2季度银行存款利息', 0.0, 0.0)\n",
"('ACC-JV-2025-00100', '付:网银手续费', 5.0, 5.0)\n"
]
}
],
"source": [
"import pymysql\n",
"db = pymysql.connect(host = \"172.19.0.10\",user = \"songyi\",password = \"yylzs\",database = \"_5e5899d8398b5f7b\" )\n",
"cursor = db.cursor()\n",
"\n",
"\n",
"sql = 'select name,title,total_debit,total_credit from `tabJournal Entry` where company= %s and docstatus = %s'\n",
"cursor.execute(sql, ('北京运动一百体育文化发展有限公司',1))\n",
"data = cursor.fetchall()\n",
"for item in data:\n",
" print(item)\n"
]
},
{
"cell_type": "markdown",
"id": "610ce516-e2f8-4955-9da0-323cbb0368cd",
"metadata": {},
"source": [
"## 获取分录"
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "489a83ab-4f5e-402a-abe2-4458acb414f4",
"metadata": {
"execution": {
"iopub.execute_input": "2025-08-24T11:05:01.364050Z",
"iopub.status.busy": "2025-08-24T11:05:01.363771Z",
"iopub.status.idle": "2025-08-24T11:05:01.370341Z",
"shell.execute_reply": "2025-08-24T11:05:01.369803Z",
"shell.execute_reply.started": "2025-08-24T11:05:01.364026Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('ACC-JV-2025-00099', '100201 - 银行存款 - 运动一百', 11.56, 0.0, '')\n",
"('ACC-JV-2025-00099', '560301 - 利息费用 - 运动一百', -11.56, 0.0, None)\n"
]
}
],
"source": [
"import pymysql\n",
"from pymysql import converters, FIELD_TYPE\n",
"\n",
"conv = converters.conversions\n",
"conv[FIELD_TYPE.NEWDECIMAL] = float\n",
"db = pymysql.connect(host = \"172.19.0.10\",user = \"songyi\",password = \"yylzs\",database = \"_5e5899d8398b5f7b\" )\n",
"cursor = db.cursor()\n",
"\n",
"\n",
"sql = 'select parent,account,debit,credit,against_account from `tabJournal Entry Account` where docstatus = %s and parent = %s'\n",
"cursor.execute(sql, (1,'ACC-JV-2025-00099'))\n",
"data = cursor.fetchall()\n",
"for item in data:\n",
" print(item)\n"
]
},
{
"cell_type": "markdown",
"id": "5d6c1b37-d475-4762-b54d-2ad6e79c3945",
"metadata": {},
"source": [
"## 获取总账"
]
},
{
"cell_type": "code",
"execution_count": 74,
"id": "02129d62-ea3e-4492-89d0-bb023f746ff4",
"metadata": {
"execution": {
"iopub.execute_input": "2025-08-24T10:58:22.279830Z",
"iopub.status.busy": "2025-08-24T10:58:22.279052Z",
"iopub.status.idle": "2025-08-24T10:58:22.306848Z",
"shell.execute_reply": "2025-08-24T10:58:22.304482Z",
"shell.execute_reply.started": "2025-08-24T10:58:22.279762Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('ACC-GLE-2025-00338', '100201 - 银行存款 - 运动一百', '', 'ACC-JV-2025-00075', 10.99, 0.0)\n",
"('ACC-GLE-2025-00339', '560301 - 利息费用 - 运动一百', None, 'ACC-JV-2025-00075', 0.0, 10.99)\n",
"('ACC-GLE-2025-00345', '100201 - 银行存款 - 运动一百', '', 'ACC-JV-2025-00075', 0.0, 10.99)\n",
"('ACC-GLE-2025-00346', '560301 - 利息费用 - 运动一百', None, 'ACC-JV-2025-00075', 0.0, -10.99)\n",
"('ACC-GLE-2025-00424', '560101 - 工资 - 运动一百', '221101 - 工资 - 运动一百, 222112 - 应交个人所得税 - 运动一百', 'ACC-JV-2025-00080', 20000.0, 0.0)\n",
"('ACC-GLE-2025-00425', '221101 - 工资 - 运动一百', '560101 - 工资 - 运动一百', 'ACC-JV-2025-00080', 0.0, 18500.0)\n",
"('ACC-GLE-2025-00426', '222112 - 应交个人所得税 - 运动一百', '560101 - 工资 - 运动一百', 'ACC-JV-2025-00080', 0.0, 1500.0)\n",
"('ACC-GLE-2025-00427', '221101 - 工资 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00081', 18500.0, 0.0)\n",
"('ACC-GLE-2025-00428', '222112 - 应交个人所得税 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00081', 1500.0, 0.0)\n",
"('ACC-GLE-2025-00429', '100201 - 银行存款 - 运动一百', '221101 - 工资 - 运动一百, 222112 - 应交个人所得税 - 运动一百', 'ACC-JV-2025-00081', 0.0, 20000.0)\n",
"('ACC-GLE-2025-00430', '560101 - 工资 - 运动一百', '221101 - 工资 - 运动一百, 222112 - 应交个人所得税 - 运动一百', 'ACC-JV-2025-00082', 10000.0, 0.0)\n",
"('ACC-GLE-2025-00431', '221101 - 工资 - 运动一百', '560101 - 工资 - 运动一百', 'ACC-JV-2025-00082', 0.0, 9850.0)\n",
"('ACC-GLE-2025-00432', '222112 - 应交个人所得税 - 运动一百', '560101 - 工资 - 运动一百', 'ACC-JV-2025-00082', 0.0, 150.0)\n",
"('ACC-GLE-2025-00433', '221101 - 工资 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00083', 9850.0, 0.0)\n",
"('ACC-GLE-2025-00434', '222112 - 应交个人所得税 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00083', 150.0, 0.0)\n",
"('ACC-GLE-2025-00435', '100201 - 银行存款 - 运动一百', '221101 - 工资 - 运动一百, 222112 - 应交个人所得税 - 运动一百', 'ACC-JV-2025-00083', 0.0, 10000.0)\n",
"('ACC-GLE-2025-00436', '560101 - 工资 - 运动一百', '221101 - 工资 - 运动一百, 222112 - 应交个人所得税 - 运动一百', 'ACC-JV-2025-00084', 10000.0, 0.0)\n",
"('ACC-GLE-2025-00437', '221101 - 工资 - 运动一百', '560101 - 工资 - 运动一百', 'ACC-JV-2025-00084', 0.0, 9850.0)\n",
"('ACC-GLE-2025-00438', '222112 - 应交个人所得税 - 运动一百', '560101 - 工资 - 运动一百', 'ACC-JV-2025-00084', 0.0, 150.0)\n",
"('ACC-GLE-2025-00439', '221101 - 工资 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00086', 9850.0, 0.0)\n",
"('ACC-GLE-2025-00440', '100201 - 银行存款 - 运动一百', '221101 - 工资 - 运动一百', 'ACC-JV-2025-00086', 0.0, 9850.0)\n",
"('ACC-GLE-2025-00441', '600102 - 培训费 - 运动一百', '112210 - 北京新越公益基金会 - 运动一百', 'ACC-JV-2025-00087', 0.0, 1980.2)\n",
"('ACC-GLE-2025-00442', '222101 - 应交增值税 - 运动一百', '112210 - 北京新越公益基金会 - 运动一百', 'ACC-JV-2025-00087', 0.0, 19.8)\n",
"('ACC-GLE-2025-00443', '112210 - 北京新越公益基金会 - 运动一百', '222101 - 应交增值税 - 运动一百, 600102 - 培训费 - 运动一百', 'ACC-JV-2025-00087', 2000.0, 0.0)\n",
"('ACC-GLE-2025-00444', '100201 - 银行存款 - 运动一百', '', 'ACC-JV-2025-00088', 15.19, 0.0)\n",
"('ACC-GLE-2025-00445', '560301 - 利息费用 - 运动一百', None, 'ACC-JV-2025-00088', 0.0, 15.19)\n",
"('ACC-GLE-2025-00446', '222112 - 应交个人所得税 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00085', 150.0, 0.0)\n",
"('ACC-GLE-2025-00447', '100201 - 银行存款 - 运动一百', '222112 - 应交个人所得税 - 运动一百', 'ACC-JV-2025-00085', 0.0, 150.0)\n",
"('ACC-GLE-2025-00448', '560101 - 工资 - 运动一百', None, 'ACC-PCV-2025-00009', 0.0, 40000.0)\n",
"('ACC-GLE-2025-00449', '560301 - 利息费用 - 运动一百', None, 'ACC-PCV-2025-00009', 15.19, 0.0)\n",
"('ACC-GLE-2025-00450', '600102 - 培训费 - 运动一百', None, 'ACC-PCV-2025-00009', 1980.2, 0.0)\n",
"('ACC-GLE-2025-00451', '4103 - 本年利润 - 运动一百', None, 'ACC-PCV-2025-00009', 38004.61, 0.0)\n",
"('ACC-GLE-2025-00452', '100201 - 银行存款 - 运动一百', '112210 - 北京新越公益基金会 - 运动一百', 'ACC-JV-2025-00089', 2000.0, 0.0)\n",
"('ACC-GLE-2025-00453', '112210 - 北京新越公益基金会 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00089', 0.0, 2000.0)\n",
"('ACC-GLE-2025-00454', '560302 - 手续费 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00090', 100.0, 0.0)\n",
"('ACC-GLE-2025-00455', '100201 - 银行存款 - 运动一百', '560302 - 手续费 - 运动一百', 'ACC-JV-2025-00090', 0.0, 100.0)\n",
"('ACC-GLE-2025-00456', '560101 - 工资 - 运动一百', '221101 - 工资 - 运动一百, 222112 - 应交个人所得税 - 运动一百', 'ACC-JV-2025-00091', 10000.0, 0.0)\n",
"('ACC-GLE-2025-00457', '221101 - 工资 - 运动一百', '560101 - 工资 - 运动一百', 'ACC-JV-2025-00091', 0.0, 9850.0)\n",
"('ACC-GLE-2025-00458', '222112 - 应交个人所得税 - 运动一百', '560101 - 工资 - 运动一百', 'ACC-JV-2025-00091', 0.0, 150.0)\n",
"('ACC-GLE-2025-00459', '221101 - 工资 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00092', 9850.0, 0.0)\n",
"('ACC-GLE-2025-00460', '222112 - 应交个人所得税 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00092', 150.0, 0.0)\n",
"('ACC-GLE-2025-00461', '100201 - 银行存款 - 运动一百', '221101 - 工资 - 运动一百, 222112 - 应交个人所得税 - 运动一百', 'ACC-JV-2025-00092', 0.0, 10000.0)\n",
"('ACC-GLE-2025-00462', '560101 - 工资 - 运动一百', '221101 - 工资 - 运动一百, 222112 - 应交个人所得税 - 运动一百', 'ACC-JV-2025-00093', 10000.0, 0.0)\n",
"('ACC-GLE-2025-00463', '221101 - 工资 - 运动一百', '560101 - 工资 - 运动一百', 'ACC-JV-2025-00093', 0.0, 9850.0)\n",
"('ACC-GLE-2025-00464', '222112 - 应交个人所得税 - 运动一百', '560101 - 工资 - 运动一百', 'ACC-JV-2025-00093', 0.0, 150.0)\n",
"('ACC-GLE-2025-00465', '221101 - 工资 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00094', 9850.0, 0.0)\n",
"('ACC-GLE-2025-00466', '222112 - 应交个人所得税 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00094', 150.0, 0.0)\n",
"('ACC-GLE-2025-00467', '100201 - 银行存款 - 运动一百', '221101 - 工资 - 运动一百, 222112 - 应交个人所得税 - 运动一百', 'ACC-JV-2025-00094', 0.0, 10000.0)\n",
"('ACC-GLE-2025-00468', '600102 - 培训费 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00095', 0.0, 33663.37)\n",
"('ACC-GLE-2025-00469', '222101 - 应交增值税 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00095', 0.0, 336.63)\n",
"('ACC-GLE-2025-00470', '100201 - 银行存款 - 运动一百', '222101 - 应交增值税 - 运动一百, 600102 - 培训费 - 运动一百', 'ACC-JV-2025-00095', 34000.0, 0.0)\n",
"('ACC-GLE-2025-00471', '600101 - 服务费 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00096', 0.0, 80801.98)\n",
"('ACC-GLE-2025-00472', '222101 - 应交增值税 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00096', 0.0, 808.02)\n",
"('ACC-GLE-2025-00473', '100201 - 银行存款 - 运动一百', '222101 - 应交增值税 - 运动一百, 600101 - 服务费 - 运动一百', 'ACC-JV-2025-00096', 81610.0, 0.0)\n",
"('ACC-GLE-2025-00474', '560101 - 工资 - 运动一百', '221101 - 工资 - 运动一百, 222112 - 应交个人所得税 - 运动一百', 'ACC-JV-2025-00097', 10000.0, 0.0)\n",
"('ACC-GLE-2025-00475', '221101 - 工资 - 运动一百', '560101 - 工资 - 运动一百', 'ACC-JV-2025-00097', 0.0, 9850.0)\n",
"('ACC-GLE-2025-00476', '222112 - 应交个人所得税 - 运动一百', '560101 - 工资 - 运动一百', 'ACC-JV-2025-00097', 0.0, 150.0)\n",
"('ACC-GLE-2025-00477', '221101 - 工资 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00098', 9850.0, 0.0)\n",
"('ACC-GLE-2025-00478', '222112 - 应交个人所得税 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00098', 150.0, 0.0)\n",
"('ACC-GLE-2025-00479', '100201 - 银行存款 - 运动一百', '221101 - 工资 - 运动一百, 222112 - 应交个人所得税 - 运动一百', 'ACC-JV-2025-00098', 0.0, 10000.0)\n",
"('ACC-GLE-2025-00480', '560302 - 手续费 - 运动一百', '100201 - 银行存款 - 运动一百', 'ACC-JV-2025-00100', 5.0, 0.0)\n",
"('ACC-GLE-2025-00481', '100201 - 银行存款 - 运动一百', '560302 - 手续费 - 运动一百', 'ACC-JV-2025-00100', 0.0, 5.0)\n",
"('ACC-GLE-2025-00482', '100201 - 银行存款 - 运动一百', '', 'ACC-JV-2025-00099', 11.56, 0.0)\n",
"('ACC-GLE-2025-00483', '560301 - 利息费用 - 运动一百', None, 'ACC-JV-2025-00099', 0.0, 11.56)\n",
"('ACC-GLE-2025-00484', '560302 - 手续费 - 运动一百', None, 'ACC-PCV-2025-00010', 0.0, 105.0)\n",
"('ACC-GLE-2025-00485', '560101 - 工资 - 运动一百', None, 'ACC-PCV-2025-00010', 0.0, 30000.0)\n",
"('ACC-GLE-2025-00486', '600102 - 培训费 - 运动一百', None, 'ACC-PCV-2025-00010', 33663.37, 0.0)\n",
"('ACC-GLE-2025-00487', '600101 - 服务费 - 运动一百', None, 'ACC-PCV-2025-00010', 80801.98, 0.0)\n",
"('ACC-GLE-2025-00488', '560301 - 利息费用 - 运动一百', None, 'ACC-PCV-2025-00010', 11.56, 0.0)\n",
"('ACC-GLE-2025-00489', '4103 - 本年利润 - 运动一百', None, 'ACC-PCV-2025-00010', 0.0, 84371.91)\n"
]
}
],
"source": [
"import pymysql\n",
"from pymysql import converters, FIELD_TYPE\n",
"\n",
"conv = converters.conversions\n",
"conv[FIELD_TYPE.NEWDECIMAL] = float\n",
"db = pymysql.connect(host = \"172.19.0.10\",user = \"songyi\",password = \"yylzs\",database = \"_5e5899d8398b5f7b\" )\n",
"cursor = db.cursor()\n",
"\n",
"\n",
"sql = 'select name,account,against,voucher_no,debit,credit from `tabGL Entry` where fiscal_year = %s'\n",
"cursor.execute(sql, ('2025'))\n",
"data = cursor.fetchall()\n",
"for item in data:\n",
" print(item)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9607f40c-e393-4e04-81b4-4cf309a8cee2",
"metadata": {},
"outputs": [],
"source": [
"## 使用模板生成凭证"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "5a5828c7-9679-4694-9f4e-357ea71a5618",
"metadata": {
"execution": {
"iopub.execute_input": "2025-08-24T10:30:09.127710Z",
"iopub.status.busy": "2025-08-24T10:30:09.127415Z",
"iopub.status.idle": "2025-08-24T10:30:09.172276Z",
"shell.execute_reply": "2025-08-24T10:30:09.171346Z",
"shell.execute_reply.started": "2025-08-24T10:30:09.127685Z"
}
},
"outputs": [],
"source": [
"import pymysql\n",
"from pymysql import converters, FIELD_TYPE\n",
"import openpyxl\n",
"from docxtpl import DocxTemplate,InlineImage\n",
"\n",
"conv = converters.conversions\n",
"conv[FIELD_TYPE.NEWDECIMAL] = float\n",
"db = pymysql.connect(host = \"172.19.0.10\",user = \"songyi\",password = \"yylzs\",database = \"_5e5899d8398b5f7b\" )\n",
"cursor = db.cursor()\n",
"\n",
"list1 = []\n",
"tpl = DocxTemplate(\"data/tpl_pingzheng.docx\")\n",
"sql = 'select parent,account,debit,credit,against_account from `tabJournal Entry Account` where docstatus = %s and parent = %s'\n",
"cursor.execute(sql, (1,'ACC-JV-2025-00002-1'))\n",
"data = cursor.fetchall()\n",
"sum_debit = 0.00\n",
"sum_credit = 0.00\n",
"for item in data:\n",
" dict1 = {}\n",
" dict1['zhaiyao'] = item[0]\n",
" dict1['kemu'] = item[1]\n",
" if item[2] == 0.0:\n",
" dict1['debit'] = '' \n",
" else:\n",
" dict1['debit'] = '{:.2f}'.format(item[2])\n",
" sum_debit+= item[2]\n",
" if item[3] == 0.0:\n",
" dict1['credit'] = '' \n",
" else:\n",
" dict1['credit'] = '{:.2f}'.format(item[3])\n",
" sum_credit+= item[3]\n",
" list1.append(dict1) \n",
"\n",
"\n",
"context = {}\n",
"context['fenlu'] = list1\n",
"context['sum_debit'] = '{:.2f}'.format(sum_debit)\n",
"context['sum_credit'] = '{:.2f}'.format(sum_credit)\n",
"tpl.render(context)\n",
"tpl.save('data/test1.docx')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1a8d4bd0-8242-48c4-947c-fd0ec872207c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}