154 lines
6.1 KiB
Python
154 lines
6.1 KiB
Python
import os
|
|
import django
|
|
import random
|
|
from datetime import date, timedelta, datetime
|
|
from django.utils import timezone
|
|
|
|
# 设置 Django 环境
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'XH_Digital_Management.settings')
|
|
django.setup()
|
|
|
|
from application.rsc_mgnt.models import (
|
|
ConsumableGoodsCategory, ConsumableGoodsInboundManagement, ConsumableGoodsInventory,
|
|
ConsumableGoodsOutboundRecords, CompanyMobilePhoneUsageRegistry, BusinessVehicleUsageRegistry,
|
|
MembershipAccountsRegistry, MembershipModificationRecord, StoredValueCardRegistration,
|
|
StoredValueCardUseRecord
|
|
)
|
|
|
|
def generate_test_data():
|
|
# 创建消耗品类别管理表
|
|
categories = []
|
|
for i in range(5):
|
|
category = ConsumableGoodsCategory.objects.create(
|
|
category_name=f"类别名称{i}",
|
|
description=f"描述{i}"
|
|
)
|
|
categories.append(category)
|
|
print(f"Created ConsumableGoodsCategory: {category}")
|
|
|
|
# 创建消耗品入库管理表
|
|
inbounds = []
|
|
for i in range(10):
|
|
inbound = ConsumableGoodsInboundManagement.objects.create(
|
|
item_name=f"物品名称{i}",
|
|
category=random.choice(categories),
|
|
specification=f"规格{i}",
|
|
unit="个",
|
|
quantity=random.randint(1, 100),
|
|
date=date.today() - timedelta(days=random.randint(1, 365)),
|
|
checker=f"核对人{i}",
|
|
storage_location=f"库存地{i}"
|
|
)
|
|
inbounds.append(inbound)
|
|
print(f"Created ConsumableGoodsInboundManagement: {inbound}")
|
|
|
|
# 创建消耗品库存表
|
|
for inbound in inbounds:
|
|
inventory = ConsumableGoodsInventory.objects.create(
|
|
item=inbound,
|
|
category=inbound.category,
|
|
specification=inbound.specification,
|
|
unit=inbound.unit,
|
|
current_inventory=inbound.quantity,
|
|
safety_stock=random.randint(10, 50),
|
|
replenishment_alert=False,
|
|
storage_location=inbound.storage_location
|
|
)
|
|
print(f"Created ConsumableGoodsInventory: {inventory}")
|
|
|
|
# 创建消耗品出库记录表
|
|
for i in range(5):
|
|
outbound = ConsumableGoodsOutboundRecords.objects.create(
|
|
item=random.choice(inbounds),
|
|
category=random.choice(categories),
|
|
specification=f"规格{i}",
|
|
unit="个",
|
|
quantity_out=random.randint(1, 50),
|
|
outbound_date=date.today() - timedelta(days=random.randint(1, 365)),
|
|
recipient=f"领用人{i}",
|
|
purpose=f"用途{i}"
|
|
)
|
|
print(f"Created ConsumableGoodsOutboundRecords: {outbound}")
|
|
|
|
# 创建公司手机号使用登记表
|
|
for i in range(5):
|
|
phone_registry = CompanyMobilePhoneUsageRegistry.objects.create(
|
|
mobile_number=f"手机号{i}",
|
|
owner=f"机主{i}",
|
|
current_user=f"现使用人{i}",
|
|
purpose=f"用途{i}"
|
|
)
|
|
print(f"Created CompanyMobilePhoneUsageRegistry: {phone_registry}")
|
|
|
|
# 创建商务车使用登记表
|
|
for i in range(5):
|
|
vehicle_registry = BusinessVehicleUsageRegistry.objects.create(
|
|
license_plate=f"车牌{i}",
|
|
checkout_time=timezone.now() - timedelta(days=random.randint(1, 10)),
|
|
borrower=f"借用人{i}",
|
|
accompanying_personnel=f"同行人员{i}",
|
|
reason=f"事由{i}",
|
|
destination=f"目的地{i}",
|
|
days_of_use=random.randint(1, 10),
|
|
return_time=timezone.now() + timedelta(days=random.randint(1, 10))
|
|
)
|
|
print(f"Created BusinessVehicleUsageRegistry: {vehicle_registry}")
|
|
|
|
# 创建会员账号登记表
|
|
memberships = []
|
|
for i in range(5):
|
|
membership = MembershipAccountsRegistry.objects.create(
|
|
platform_name=f"平台名称{i}",
|
|
purpose=f"用途{i}",
|
|
price=random.uniform(100, 1000),
|
|
manager=f"管理人{i}",
|
|
account=f"账号{i}",
|
|
password=f"密码{i}",
|
|
effective_date=date.today() - timedelta(days=random.randint(1, 365)),
|
|
expiration_date=date.today() + timedelta(days=random.randint(1, 365)),
|
|
status=random.choice(['正常', '过期'])
|
|
)
|
|
memberships.append(membership)
|
|
print(f"Created MembershipAccountsRegistry: {membership}")
|
|
|
|
# 创建会员账号变更记录表
|
|
for membership in memberships:
|
|
modification = MembershipModificationRecord.objects.create(
|
|
account_record=membership,
|
|
modification_date=date.today() - timedelta(days=random.randint(1, 365)),
|
|
modification_reason=f"修改原因{membership.platform_name}",
|
|
previous_expiration_date=membership.effective_date + timedelta(days=random.randint(1, 365)),
|
|
new_expiration_date=membership.expiration_date + timedelta(days=random.randint(1, 365))
|
|
)
|
|
print(f"Created MembershipModificationRecord: {modification}")
|
|
|
|
# 创建储值卡登记表
|
|
stored_value_cards = []
|
|
for i in range(5):
|
|
card = StoredValueCardRegistration.objects.create(
|
|
merchant_name=f"商家名称{i}",
|
|
merchant_type=f"商家类型{i}",
|
|
balance=random.uniform(1000, 10000),
|
|
usage_records=f"使用记录{i}"
|
|
)
|
|
stored_value_cards.append(card)
|
|
print(f"Created StoredValueCardRegistration: {card}")
|
|
|
|
# 创建储值卡使用记录表
|
|
for card in stored_value_cards:
|
|
for i in range(3):
|
|
usage_record = StoredValueCardUseRecord.objects.create(
|
|
stored_value_card=card,
|
|
transaction_date=date.today() - timedelta(days=random.randint(1, 365)),
|
|
transaction_amount=random.uniform(100, 1000),
|
|
transaction_type=random.choice(['充值', '消费']),
|
|
current_balance=card.balance - random.uniform(100, 500),
|
|
consumer=f"消费人{i}",
|
|
primary_department=f"一级部门{i}",
|
|
purpose=f"用途{i}"
|
|
)
|
|
print(f"Created StoredValueCardUseRecord: {usage_record}")
|
|
|
|
if __name__ == "__main__":
|
|
generate_test_data()
|