fix: rparty create时dept字段冲突
This commit is contained in:
parent
e32f82ace7
commit
ec6c1c3d84
|
@ -31,13 +31,14 @@ class RpartyCreateUpdateSerializer(CustomModelSerializer):
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
instance = super().create(validated_data)
|
instance = super().create(validated_data)
|
||||||
dept, _ = Dept.objects.get_or_create(name=instance.name,
|
dept, _ = Dept.objects.get_or_create(name=instance.name, type="rparty",
|
||||||
defaults={
|
defaults={
|
||||||
"name": instance.name,
|
"name": instance.name,
|
||||||
"parent": instance.belong_dept,
|
"parent": instance.belong_dept,
|
||||||
"type": "rparty"
|
"type": "rparty"
|
||||||
})
|
})
|
||||||
sync_dahua_dept(dept)
|
sync_dahua_dept(dept)
|
||||||
|
Rparty.objects.get_queryset(all=True).filter(dept=dept).update(dept=None, is_deleted=True)
|
||||||
instance.dept = dept
|
instance.dept = dept
|
||||||
instance.save()
|
instance.save()
|
||||||
return instance
|
return instance
|
||||||
|
@ -46,6 +47,7 @@ class RpartyCreateUpdateSerializer(CustomModelSerializer):
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
instance = super().update(instance, validated_data)
|
instance = super().update(instance, validated_data)
|
||||||
dept = instance.dept
|
dept = instance.dept
|
||||||
|
if dept:
|
||||||
dept.name = instance.name
|
dept.name = instance.name
|
||||||
dept.parent = instance.belong_dept # 重新规划归属部门
|
dept.parent = instance.belong_dept # 重新规划归属部门
|
||||||
dept.save()
|
dept.save()
|
||||||
|
|
Loading…
Reference in New Issue