feat: sflog获取年月日优化
This commit is contained in:
parent
13382171de
commit
b634bac616
|
@ -4,7 +4,6 @@ from apps.utils.constants import EXCLUDE_FIELDS
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from apps.mtm.models import Mgroup
|
from apps.mtm.models import Mgroup
|
||||||
from rest_framework.exceptions import ParseError
|
from rest_framework.exceptions import ParseError
|
||||||
from django.utils.timezone import localtime
|
|
||||||
|
|
||||||
|
|
||||||
class MpointSerializer(CustomModelSerializer):
|
class MpointSerializer(CustomModelSerializer):
|
||||||
|
@ -67,8 +66,8 @@ class MpointStatSerializer(CustomModelSerializer):
|
||||||
if mpoint.material and mpoint.is_auto is False and 'sflog' in attrs and attrs['sflog']:
|
if mpoint.material and mpoint.is_auto is False and 'sflog' in attrs and attrs['sflog']:
|
||||||
attrs['type'] = 'sflog'
|
attrs['type'] = 'sflog'
|
||||||
sflog = attrs['sflog']
|
sflog = attrs['sflog']
|
||||||
end_time_local = localtime(sflog.end_time)
|
attrs['year_s'], attrs['month_s'], attrs['day_s'] = sflog.get_ymd
|
||||||
attrs['year_s'], attrs['month_s'], attrs['day_s'], attrs['mgroup'] = end_time_local.year, end_time_local.month, end_time_local.day, sflog.mgroup
|
attrs['mgroup'] = sflog.mgroup
|
||||||
else:
|
else:
|
||||||
raise ParseError('该数据不支持手工录入')
|
raise ParseError('该数据不支持手工录入')
|
||||||
# if 'sflog' in attrs and attrs['sflog']:
|
# if 'sflog' in attrs and attrs['sflog']:
|
||||||
|
|
|
@ -11,7 +11,6 @@ import datetime
|
||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
from dateutil import tz
|
from dateutil import tz
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.timezone import localtime
|
|
||||||
from apps.wpm.services import make_sflogs
|
from apps.wpm.services import make_sflogs
|
||||||
from apps.mtm.models import Mgroup, Material
|
from apps.mtm.models import Mgroup, Material
|
||||||
from apps.fim.services import get_cost_unit, get_price_unit
|
from apps.fim.services import get_cost_unit, get_price_unit
|
||||||
|
@ -109,8 +108,7 @@ def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: in
|
||||||
if sflog is None: # 需要创建值班记录
|
if sflog is None: # 需要创建值班记录
|
||||||
make_sflogs(mgroup=mgroup, start_date=(dt-datetime.timedelta(days=1)).date(), end_date=dt.date())
|
make_sflogs(mgroup=mgroup, start_date=(dt-datetime.timedelta(days=1)).date(), end_date=dt.date())
|
||||||
sflog = SfLog.objects.filter(start_time__lte=dt, end_time__gt=dt, mgroup=mgroup).first()
|
sflog = SfLog.objects.filter(start_time__lte=dt, end_time__gt=dt, mgroup=mgroup).first()
|
||||||
end_time_local = localtime(sflog.end_time)
|
year_s, month_s, day_s = sflog.get_ymd
|
||||||
year_s, month_s, day_s = end_time_local.year, end_time_local.month, end_time_local.day
|
|
||||||
|
|
||||||
params_hour_s = {'type': 'hour_s', 'mpoint': mpoint, 'sflog': sflog, 'mgroup': mgroup, 'year': year, 'month': month, 'day': day, 'year_s': year_s, 'month_s': month_s, 'day_s': day_s, 'hour': hour}
|
params_hour_s = {'type': 'hour_s', 'mpoint': mpoint, 'sflog': sflog, 'mgroup': mgroup, 'year': year, 'month': month, 'day': day, 'year_s': year_s, 'month_s': month_s, 'day_s': day_s, 'hour': hour}
|
||||||
ms_hour_s, _ = MpointStat.objects.get_or_create(**params_hour_s, defaults=params_hour_s)
|
ms_hour_s, _ = MpointStat.objects.get_or_create(**params_hour_s, defaults=params_hour_s)
|
||||||
|
|
|
@ -8,7 +8,6 @@ from drf_yasg.utils import swagger_auto_schema
|
||||||
from apps.fim.serializers import CostStatSerializer
|
from apps.fim.serializers import CostStatSerializer
|
||||||
from apps.mtm.models import Material
|
from apps.mtm.models import Material
|
||||||
import datetime
|
import datetime
|
||||||
from django.utils.timezone import localtime
|
|
||||||
from apps.enm.models import EnStat, MpointStat
|
from apps.enm.models import EnStat, MpointStat
|
||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
from apps.fim.services import get_price_unit, get_cost_unit
|
from apps.fim.services import get_price_unit, get_cost_unit
|
||||||
|
|
|
@ -4,7 +4,6 @@ from apps.utils.serializers import CustomModelSerializer
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from apps.system.models import Dept, Dictionary
|
from apps.system.models import Dept, Dictionary
|
||||||
from apps.wpm.models import SfLog
|
from apps.wpm.models import SfLog
|
||||||
from django.utils.timezone import localtime
|
|
||||||
|
|
||||||
class TestItemSerializer(CustomModelSerializer):
|
class TestItemSerializer(CustomModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -11,7 +11,6 @@ from apps.wpm.models import SfLog, StLog, StSfLog
|
||||||
from apps.wpm.serializers import SfLogSerializer, StLogSerializer, StSfLogSerializer
|
from apps.wpm.serializers import SfLogSerializer, StLogSerializer, StSfLogSerializer
|
||||||
from apps.wpm.filters import SfLogFilter
|
from apps.wpm.filters import SfLogFilter
|
||||||
from apps.mtm.models import Material
|
from apps.mtm.models import Material
|
||||||
from django.utils.timezone import localtime
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
class StLogViewSet(ListModelMixin, CustomGenericViewSet):
|
class StLogViewSet(ListModelMixin, CustomGenericViewSet):
|
||||||
|
|
Loading…
Reference in New Issue