feat: Attendance批量创建时执行覆盖操作
This commit is contained in:
parent
31814f2495
commit
d1f183237d
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.12 on 2023-11-17 09:24
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mtm', '0024_auto_20231116_1416'),
|
||||||
|
('hrm', '0017_auto_20231117_1700'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='attendance',
|
||||||
|
unique_together={('employee', 'work_date', 'shift')},
|
||||||
|
),
|
||||||
|
]
|
|
@ -107,6 +107,9 @@ class Attendance(CommonADModel):
|
||||||
choices=ATT_STATE_CHOICES, default='pending', help_text=str(ATT_STATE_CHOICES))
|
choices=ATT_STATE_CHOICES, default='pending', help_text=str(ATT_STATE_CHOICES))
|
||||||
note = models.TextField('备注信息', default='')
|
note = models.TextField('备注信息', default='')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = ('employee', 'work_date', 'shift')
|
||||||
|
|
||||||
|
|
||||||
class ClockRecord(BaseModel):
|
class ClockRecord(BaseModel):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -280,7 +280,15 @@ class AttendanceSerializer(CustomModelSerializer):
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
shift = validated_data['shift']
|
shift = validated_data['shift']
|
||||||
work_date = validated_data['work_date']
|
work_date = validated_data['work_date']
|
||||||
|
att = Attendance.objects.filter(
|
||||||
|
employee=validated_data['employee'], work_date=work_date, shift=shift).first()
|
||||||
|
if att:
|
||||||
|
att.note = validated_data.get('note', '')
|
||||||
|
att.state = validated_data['state']
|
||||||
|
att.update_by = self.context['request'].user
|
||||||
|
att.save()
|
||||||
|
return att
|
||||||
|
else:
|
||||||
start_time_o = shift.start_time_o
|
start_time_o = shift.start_time_o
|
||||||
end_time_o = shift.end_time_o
|
end_time_o = shift.end_time_o
|
||||||
if end_time_o >= start_time_o:
|
if end_time_o >= start_time_o:
|
||||||
|
|
Loading…
Reference in New Issue