|
|
@@ -9,7 +9,7 @@ from datetime import datetime, timedelta
|
|
|
|
|
|
def setup_django():
|
|
|
"""设置Django环境"""
|
|
|
- project_path = "D:/code/vue/greater_wms"
|
|
|
+ project_path = "D:/Document/code/vue/greater_wms"
|
|
|
sys.path.append(project_path)
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'greaterwms.settings')
|
|
|
django.setup()
|
|
|
@@ -42,27 +42,32 @@ def reconcile_material_history():
|
|
|
|
|
|
# 从后往前处理每个历史记录
|
|
|
for i, record in enumerate(history_records):
|
|
|
- if record.count_time >= 1:
|
|
|
+ if record.count_time >= 0:
|
|
|
# 最后一个记录:使用当前库存作为期末数量
|
|
|
if i == 0:
|
|
|
record.closing_quantity = current_quantity
|
|
|
+
|
|
|
+
|
|
|
else:
|
|
|
# 前一个记录的期末数量就是当前记录的期初数量
|
|
|
record.closing_quantity = history_records[i-1].opening_quantity
|
|
|
|
|
|
# 计算期初数量(期末 + 出库 - 入库)
|
|
|
+ record.in_quantity = record.batch_log.goods_in_qty
|
|
|
+ record.out_quantity = record.batch_log.goods_out_qty
|
|
|
record.opening_quantity = (
|
|
|
record.closing_quantity
|
|
|
+ record.out_quantity
|
|
|
- record.in_quantity
|
|
|
)
|
|
|
- print(f"更新记录 {record.id},条目时间{record.change_time}: 期初 {record.opening_quantity}, 期末 {record.closing_quantity}, 入库 {record.in_quantity}, 出库 {record.out_quantity}")
|
|
|
- # 更新记录
|
|
|
- record.count_time = 1
|
|
|
- record.save()
|
|
|
-
|
|
|
# 更新当前数量为当前记录的期初数量(用于下一个记录)
|
|
|
current_quantity = record.opening_quantity
|
|
|
+ print(f"更新记录 {record.id},条目时间{record.change_time}: 期初 {record.opening_quantity}, 期末 {record.closing_quantity}, 入库 {record.in_quantity}, 出库 {record.out_quantity}")
|
|
|
+ # 更新记录
|
|
|
+ record.count_time = 1
|
|
|
+ record.save()
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
# 验证第一个记录的期初数量是否合理
|