hrm信号修改

This commit is contained in:
曹前明 2022-09-15 10:43:59 +08:00
parent 1d438d12f7
commit abe63b30a6
1 changed files with 13 additions and 11 deletions

View File

@ -6,17 +6,19 @@ from apps.hrm.models import Employee
@receiver(post_save, sender=User)
def updateEmployee(sender, instance, created, **kwargs):
# if created:
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,
"type": instance.type
})
if not ep_created:
ep = None
ep_created = False
if created:
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,
"type": instance.type
})
if ep and not ep_created:
ep.belong_dept = instance.belong_dept
ep.post = instance.post
ep.type = instance.type