ERP/check_total_amount.py
2026-02-03 13:27:32 +08:00

99 lines
3.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.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
检查对账单含税金额是否正确更新
"""
import sqlite3
import sys
import os
def check_total_amount():
"""检查含税金额更新情况"""
# 连接数据库
conn = sqlite3.connect('server/data.db')
c = conn.cursor()
print("=== 检查对账单含税金额更新情况 ===\n")
# 查询所有对账单记录
c.execute('SELECT id, contract_no, material_name, quantity, unit_price, total_amount FROM reconciliations ORDER BY id DESC LIMIT 20')
records = c.fetchall()
print("最近20条对账单记录")
print("-" * 80)
print(f"{'ID':<5} {'合同号':<15} {'物料名称':<30} {'数量':<8} {'单价':<8} {'含税金额':<10} {'应计算金额':<10}")
print("-" * 80)
incorrect_count = 0
for record in records:
recon_id, contract_no, material_name, quantity, unit_price, total_amount = record
# 计算应有的含税金额
calculated_amount = quantity * unit_price
# 检查是否一致(考虑浮点数精度)
if abs(total_amount - calculated_amount) > 0.01:
incorrect_count += 1
status = ""
else:
status = ""
print(f"{recon_id:<5} {contract_no:<15} {material_name[:28]:<30} {quantity:<8} {unit_price:<8} {total_amount:<10} {calculated_amount:<10} {status}")
print("-" * 80)
print(f"\n发现 {incorrect_count} 条记录的含税金额不正确")
# 修复不正确的记录
if incorrect_count > 0:
print("\n正在修复不正确的记录...")
c.execute('SELECT id, quantity, unit_price FROM reconciliations')
all_records = c.fetchall()
fixed_count = 0
for record in all_records:
recon_id, quantity, unit_price = record
correct_amount = quantity * unit_price
# 更新含税金额
c.execute('UPDATE reconciliations SET total_amount=? WHERE id=?', (correct_amount, recon_id))
fixed_count += 1
conn.commit()
print(f"已修复 {fixed_count} 条记录的含税金额")
# 测试刷新单价功能
print("\n\n=== 测试刷新单价功能 ===")
# 找一个有客户订单的合同号进行测试
c.execute("SELECT DISTINCT contract_no FROM reconciliations LIMIT 1")
test_contract = c.fetchone()
if test_contract:
test_contract_no = test_contract[0]
print(f"测试合同号: {test_contract_no}")
# 查看该合同号的对账单记录
c.execute('SELECT id, material_name, unit_price, total_amount, quantity FROM reconciliations WHERE contract_no=?', (test_contract_no,))
test_records = c.fetchall()
print("\n刷新前的记录:")
for record in test_records:
recon_id, material_name, unit_price, total_amount, quantity = record
print(f" ID={recon_id}, 物料={material_name[:30]}..., 单价={unit_price}, 金额={total_amount}, 数量={quantity}")
# 模拟刷新单价(这里只是检查逻辑)
print("\n注意实际的刷新单价功能需要通过API调用")
conn.close()
print("\n=== 建议检查事项 ===")
print("1. 确认后端刷新单价的SQL语句是否正确")
print("2. 检查前端是否正确调用了calculateTotal函数")
print("3. 验证数据库中的total_amount字段是否被正确更新")
print("4. 查看浏览器控制台是否有JavaScript错误")
if __name__ == '__main__':
check_total_amount()