修改时间时区问题

This commit is contained in:
dxc
2026-02-05 14:36:36 +08:00
parent 0bc47d306d
commit 4f90e02dcf
4 changed files with 40 additions and 16 deletions

View File

@ -2,7 +2,7 @@
from app.extensions import db
from app.models.base import MaterialBase
from app.models.outbound import TransOutbound
from datetime import datetime
from datetime import datetime, timedelta, timezone # [修改]
from sqlalchemy import or_, func, text, and_
import traceback
import json
@ -33,7 +33,7 @@ class ProductInboundService:
return []
# ============================================================
# 2. 新增入库逻辑 (修改:精确到时间)
# 2. 新增入库逻辑 (强制北京时间)
# ============================================================
@staticmethod
def handle_inbound(data):
@ -45,8 +45,10 @@ class ProductInboundService:
material = MaterialBase.query.get(base_id)
if not material: raise ValueError("物料不存在")
# [核心修改] 处理 production_date包含时分秒
current_time = datetime.now()
# [核心修改] 强制北京时间
beijing_tz = timezone(timedelta(hours=8))
current_time = datetime.now(beijing_tz).replace(tzinfo=None)
in_date_val = current_time
if data.get('in_date'):