ep signals bug

This commit is contained in:
曹前明 2022-07-07 10:33:03 +08:00
parent 64e80a7295
commit fe12351f72
2 changed files with 11 additions and 14 deletions

View File

@ -7,19 +7,16 @@ from apps.hrm.models import Employee
@receiver(post_save, sender=User)
def updateEmployee(sender, instance, created, **kwargs):
# if created:
# 如果账号所属部门有变动, 更新关联人员的所属部门, 只限内部人员
if not instance.is_superuser and instance.type == 'employee':
ep = Employee.objects.filter(user=instance).first()
if ep:
if not instance.is_superuser:
ep, ep_created = Employee.objects.get_or_create(user=instance,
defaults={
"user": instance,
"name": instance.name,
"phone": instance.phone,
"belong_dept": instance.belong_dept,
"post": instance.post
})
if not ep_created:
ep.belong_dept = instance.belong_dept
ep.post = instance.post
ep.save()
else:
Employee.objects.get_or_create(user=instance,
defaults={
"user": instance,
"name": instance.name,
"phone": instance.phone,
"belong_dept": instance.belong_dept,
"post": instance.post
})

View File

@ -164,7 +164,7 @@ class TDeviceViewSet(ListModelMixin, DestroyModelMixin, CustomGenericViewSet):
_, res = xxClient.request(**xxapis['blt_list'], json=json)
blt_list = res['recordList']
for i in blt_list:
TDevice.objects.get_or_create(code=i['mac'], default={"code": i['mac'], "type": TDevice.DEVICE_BLT})
TDevice.objects.get_or_create(code=i['mac'], defaults={"code": i['mac'], "type": TDevice.DEVICE_BLT})
return Response()
@action(methods=['post'], detail=False, perms_map={'post': '*'},