ERP/init_reconciliations.py
2025-11-25 10:35:02 +08:00

125 lines
3.9 KiB
Python
Raw Permalink 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 os
from datetime import datetime, timezone, timedelta
# 数据库路径
DB_PATH = os.path.join(os.path.dirname(__file__), 'server', 'data.db')
def get_beijing_time():
"""获取北京时间UTC+8的ISO格式字符串"""
beijing_tz = timezone(timedelta(hours=8))
return datetime.now(beijing_tz).isoformat()
def init_reconciliations():
"""初始化对账单示例数据"""
conn = sqlite3.connect(DB_PATH)
c = conn.cursor()
# 示例数据(根据图片中的数据)
sample_data = [
{
'order_date': '2025/10/31',
'contract_no': 'CGDD002876',
'material_name': '扩产-9988 红黑线',
'spec_model': 'PCXK0P0NSNT_1_2.54*1C14TE',
'transport_no': '快递上门',
'quantity': 45,
'unit': 'pcs',
'unit_price': 239.2,
'total_amount': 10764,
'delivery_date': '2025/11/3',
'shipment_date': '2025/11/3'
},
{
'order_date': '2025/9/20',
'contract_no': 'CGDD004562',
'material_name': '扩产-9988 红黑线',
'spec_model': 'M1H0EM0N511 PCXK0P0NSNT_1_2.54*1C14TE',
'transport_no': '快递上门',
'quantity': 355,
'unit': 'pcs',
'unit_price': 1.1,
'total_amount': 390.5,
'delivery_date': '2025/11/3',
'shipment_date': '2025/11/3'
},
{
'order_date': '2025/9/20',
'contract_no': 'CGDD004562',
'material_name': '扩产-9988 红黑线',
'spec_model': 'ETAP05-01',
'transport_no': '快递上门',
'quantity': 2,
'unit': 'pcs',
'unit_price': 245.46,
'total_amount': 490.92,
'delivery_date': '2025/11/3',
'shipment_date': '2025/11/3'
},
{
'order_date': '2025/9/20',
'contract_no': 'CGDD004562',
'material_name': 'M1H0EM0N511 红黑线',
'spec_model': 'PCXK0P0NSNT_1_2.54*1C14TE',
'transport_no': '快递上门',
'quantity': 6,
'unit': 'pcs',
'unit_price': 1.1,
'total_amount': 6.6,
'delivery_date': '2025/11/3',
'shipment_date': '2025/11/3'
},
{
'order_date': '2025/10/11',
'contract_no': 'CGDD002717',
'material_name': '扩产-9988 红黑线',
'spec_model': 'ETAP05-01',
'transport_no': '快递上门',
'quantity': 500,
'unit': 'pcs',
'unit_price': 228.45,
'total_amount': 114225,
'delivery_date': '2025/11/3',
'shipment_date': '2025/11/3'
}
]
now = get_beijing_time()
for data in sample_data:
c.execute('''
INSERT INTO reconciliations(
order_date, contract_no, material_name, spec_model, transport_no,
quantity, unit, unit_price, total_amount, delivery_date, shipment_date,
created_by, created_at, updated_at
) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)
''', (
data['order_date'],
data['contract_no'],
data['material_name'],
data['spec_model'],
data['transport_no'],
data['quantity'],
data['unit'],
data['unit_price'],
data['total_amount'],
data['delivery_date'],
data['shipment_date'],
'admin',
now,
now
))
conn.commit()
count = len(sample_data)
conn.close()
print(f'✅ 成功初始化 {count} 条对账单示例数据')
if __name__ == '__main__':
init_reconciliations()