perf: 工单根据选择组织自动选择流

pull/7363/head
feng626 2021-12-11 12:50:30 +08:00
parent c7f2afc3c1
commit 9b9e32d2f4
2 changed files with 10 additions and 5 deletions

View File

@ -7,7 +7,7 @@ from common.mixins.models import CommonModelMixin
from common.db.encoder import ModelJSONFieldEncoder from common.db.encoder import ModelJSONFieldEncoder
from orgs.mixins.models import OrgModelMixin from orgs.mixins.models import OrgModelMixin
from orgs.models import Organization from orgs.models import Organization
from orgs.utils import tmp_to_root_org from orgs.utils import tmp_to_root_org, tmp_to_org
from ..const import TicketType, TicketApprovalLevel, TicketApprovalStrategy from ..const import TicketType, TicketApprovalLevel, TicketApprovalStrategy
from ..signals import post_or_update_change_ticket_flow_approval from ..signals import post_or_update_change_ticket_flow_approval
@ -64,9 +64,13 @@ class TicketFlow(CommonModelMixin, OrgModelMixin):
return '{}'.format(self.type) return '{}'.format(self.type)
@classmethod @classmethod
def get_org_related_flows(cls): def get_org_related_flows(cls, org_id=None):
if org_id:
with tmp_to_org(org_id):
flows = cls.objects.all()
else:
flows = cls.objects.all() flows = cls.objects.all()
cur_flow_types = flows.values_list('type', flat=True) cur_flow_types = flows.values_list('type', flat=True)
with tmp_to_root_org(): with tmp_to_root_org():
diff_global_flows = cls.objects.exclude(type__in=cur_flow_types).filter(org_id=Organization.ROOT_ID) diff_global_flows = cls.objects.exclude(type__in=cur_flow_types)
return flows | diff_global_flows return flows | diff_global_flows

View File

@ -108,7 +108,8 @@ class TicketApplySerializer(TicketSerializer):
def validate(self, attrs): def validate(self, attrs):
ticket_type = attrs.get('type') ticket_type = attrs.get('type')
flow = TicketFlow.get_org_related_flows().filter(type=ticket_type).first() org_id = attrs.get('org_id')
flow = TicketFlow.get_org_related_flows(org_id=org_id).filter(type=ticket_type).first()
if flow: if flow:
attrs['flow'] = flow attrs['flow'] = flow
else: else: