Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1089] Fix approval names on "waiting on" column #1090

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions backend/api/v1/v1_data/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,14 @@ def get_created(self, instance: PendingDataBatch):
def get_approver(self, instance: PendingDataBatch):
user: SystemUser = self.context.get("user")
data = {}
approval = (instance.batch_approval.filter(
status__in=[
DataApprovalStatus.pending, DataApprovalStatus.rejected
],
).order_by("-level__level").first())
approval = instance.batch_approval.filter(
level__level=user.user_access.administration.level.level - 1
if user.user_access.administration.level.level > 1 else 1,
).order_by("-level__level").first()
rejected: PendingDataApproval = instance.batch_approval.filter(
status=DataApprovalStatus.rejected
).first()
if approval:

data["id"] = approval.user.pk
data["name"] = approval.user.get_full_name()
data["status"] = approval.status
Expand All @@ -532,9 +533,10 @@ def get_approver(self, instance: PendingDataBatch):
data["allow_approve"] = True
else:
data["allow_approve"] = False
rejected: PendingDataApproval = instance.batch_approval.filter(
status=DataApprovalStatus.rejected).first()
if rejected:
data["name"] = instance.batch_approval.filter(
level__level=approval.level.level + 1
).first().user.get_full_name()
data["rejected"] = {
"name":
rejected.user.get_full_name(),
Expand All @@ -551,7 +553,12 @@ def get_approver(self, instance: PendingDataBatch):
data["status_text"] = DataApprovalStatus.FieldStr.get(
approval.status)
data["allow_approve"] = True

final_approved = instance.batch_approval.filter(
status=DataApprovalStatus.approved,
level__level=1
).count()
if final_approved:
data["name"] = "-"
return data

class Meta:
Expand Down
5 changes: 4 additions & 1 deletion backend/api/v1/v1_data/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,10 @@ def list_pending_batch(request, version):
"total_page": ceil(queryset.count() / page_size),
"batch": ListPendingDataBatchSerializer(
instance=values, context={
'user': user, },
'user': user,
'approved': approved,
'subordinate': subordinate,
},
many=True).data,
}
return Response(data, status=status.HTTP_200_OK)
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/pages/approvals/Approvals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ const Approvals = () => {
return items;
}, [text, user]);

const finalApproval = useMemo(() => {
if (user.role.id === 2 && approvalTab === "approved") {
return true;
}
return false;
}, [user, approvalTab]);

useEffect(() => {
setRole(user?.role?.id);
}, [user]);
Expand Down Expand Up @@ -128,7 +135,11 @@ const Approvals = () => {
<Table
dataSource={batches}
onChange={handleChange}
columns={columns}
columns={
finalApproval
? columns.filter((c) => c.key !== "waiting_on")
: columns
}
loading={loading}
pagination={{
current: currentPage,
Expand Down