相关方创建
This commit is contained in:
parent
5c5cc60fed
commit
5acc65a6f0
|
@ -24,28 +24,28 @@ class RpartyCreateUpdateSerializer(CustomModelSerializer):
|
||||||
'belong_dept': {'required': True}
|
'belong_dept': {'required': True}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
instance = super().create(validated_data)
|
instance = super().create(validated_data)
|
||||||
with transaction.atomic():
|
dept = Dept.objects.get_or_create(name=instance.name,
|
||||||
dept = Dept.objects.get_or_create(name=instance.name,
|
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)
|
|
||||||
instance.dept = dept
|
instance.dept = dept
|
||||||
instance.save()
|
instance.save()
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
instance = super().update(instance, validated_data)
|
instance = super().update(instance, validated_data)
|
||||||
with transaction.atomic():
|
dept = instance.dept
|
||||||
dept = instance.dept
|
dept.name = instance.name
|
||||||
dept.name = instance.name
|
dept.parent = instance.belong_dept # 重新规划归属部门
|
||||||
dept.parent = instance.belong_dept # 重新规划归属部门
|
dept.save()
|
||||||
dept.save()
|
sync_dahua_dept(dept)
|
||||||
sync_dahua_dept(dept)
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue