task-d.5.7
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
canAccessScopedCrmRecord
|
||||
} from '@/features/crm/security/server/service';
|
||||
import { getActiveOptionsByCategory } from '@/features/foundation/master-options/service';
|
||||
import { syncOpportunityFromQuotationApproval } from '@/features/crm/opportunities/server/quotation-sync.service';
|
||||
import type {
|
||||
ApprovalActionRecord,
|
||||
ApprovalDetailRecord,
|
||||
@@ -576,14 +577,46 @@ async function syncEntityStatusFromApproval(
|
||||
return;
|
||||
}
|
||||
|
||||
const [quotation] = await db
|
||||
.select({
|
||||
id: crmQuotations.id,
|
||||
opportunityId: crmQuotations.opportunityId
|
||||
})
|
||||
.from(crmQuotations)
|
||||
.where(
|
||||
and(
|
||||
eq(crmQuotations.id, entityId),
|
||||
eq(crmQuotations.organizationId, organizationId),
|
||||
isNull(crmQuotations.deletedAt)
|
||||
)
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
if (approvalStatus === APPROVAL_REQUEST_STATUSES.pending) {
|
||||
await syncQuotationStatusFromApproval(entityId, organizationId, userId, 'pending_approval');
|
||||
if (quotation?.opportunityId) {
|
||||
await syncOpportunityFromQuotationApproval({
|
||||
organizationId,
|
||||
userId,
|
||||
opportunityId: quotation.opportunityId,
|
||||
quotationId: quotation.id,
|
||||
quotationStatusCode: 'pending_approval'
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (approvalStatus === APPROVAL_REQUEST_STATUSES.approved) {
|
||||
// TODO(task-h.1): add an async hook/job to auto-generate approved PDFs after final approval.
|
||||
await syncQuotationStatusFromApproval(entityId, organizationId, userId, 'approved');
|
||||
if (quotation?.opportunityId) {
|
||||
await syncOpportunityFromQuotationApproval({
|
||||
organizationId,
|
||||
userId,
|
||||
opportunityId: quotation.opportunityId,
|
||||
quotationId: quotation.id,
|
||||
quotationStatusCode: 'approved'
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user