[CLAUDE] PE workflow 3-button Duyệt/Trả lại/Từ chối (Task 4)
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 3m6s
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 3m6s
User chỉ thị thay 2-button hiện tại bằng 3 hành động rõ ràng:
- Duyệt = forward phase tiếp theo
- Trả lại = về DangSoanThao + Drafter sửa → workflow tự jump tới phase
đã reject (smart reject Mig 16 pattern + clear N-stage rows)
- Từ chối = phiếu khoá hoàn toàn (Phase=TuChoi → 17 handler Mig 16 lock
edit). Drafter phải tạo phiếu mới.
Domain (PurchaseEvaluationPolicy.cs):
- NccOnly + NccWithPlan: thêm (X → TuChoi) transition cho mọi phase
trung gian (ChoPurchasing/ChoCCM/ChoCEODuyetNCC/ChoDuAn/ChoCEODuyetPA)
với roles của phase đó. Trước đây chỉ DangSoanThao → TuChoi (Drafter).
- FromDefinition expand: mỗi step (trừ DangSoanThao) thêm
(step.Phase → TuChoi) với roles của step.
Service (PurchaseEvaluationWorkflowService.cs):
- Reject branch tách 2 case:
* target=TuChoi → giữ nguyên (KHÔNG override + KHÔNG set
RejectedFromPhase + KHÔNG clear N-stage rows). Phiếu khoá vĩnh viễn.
* target khác (thường DangSoanThao) → smart reject (set
RejectedFromPhase + force DangSoanThao + clear N-stage rows).
FE (PeWorkflowPanel.tsx, fe-admin + fe-user mirror):
- next.phases render 3 button rõ ràng:
* "✓ Duyệt → <label>" brand (forward)
* "← Trả lại (về Drafter sửa)" red (target=DangSoanThao + isSendBack)
* "✗ Hủy / Từ chối" red (target=TuChoi)
- Decision logic: target=TuChoi || isSendBack → Reject (2), else Approve (1)
- Dialog confirm:
* Title rõ theo loại hành động
* Cancel case: warning red "Phiếu sẽ bị khoá hoàn toàn"
* SendBack case: hint amber "Phiếu sẽ về Đang soạn thảo, Drafter sửa
rồi trình lại — workflow tự jump tới phase này"
Tests update + add 1 test mới:
- Reject_Sets_RejectedFromPhase_And_Forces_DangSoanThao →
Reject_To_DangSoanThao_Sets_RejectedFromPhase_TraLai (rename + change
target từ TuChoi → DangSoanThao để test Trả lại pattern)
- + Reject_To_TuChoi_Locks_Permanently_No_RejectedFromPhase (NEW test
Từ chối — phase=TuChoi + RejectedFromPhase null)
- NStage_Reject_Clears_InnerStep_Rows_At_Phase: target TuChoi →
DangSoanThao (test Trả lại + clear N-stage rows pattern)
Verify:
- dotnet build 0 error
- dotnet test 95 → **96 pass** (+1 test mới Từ chối)
- npm build fe-admin + fe-user pass
Pending Task 2: Sample data seed N-stage.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@ -45,12 +45,20 @@ export function PeWorkflowPanel({
|
||||
})
|
||||
|
||||
const transition = useMutation({
|
||||
mutationFn: async () =>
|
||||
api.post(`/purchase-evaluations/${evaluation.id}/transitions`, {
|
||||
mutationFn: async () => {
|
||||
// Decision = Reject (2) khi:
|
||||
// - target = TuChoi (huỷ phiếu)
|
||||
// - target = DangSoanThao từ phase trung gian (= Trả lại — smart reject Mig 16
|
||||
// set RejectedFromPhase + clear N-stage rows + Drafter resume jump-back)
|
||||
const isReject = target === PurchaseEvaluationPhase.TuChoi
|
||||
|| (target === PurchaseEvaluationPhase.DangSoanThao
|
||||
&& evaluation.phase !== PurchaseEvaluationPhase.DangSoanThao)
|
||||
return api.post(`/purchase-evaluations/${evaluation.id}/transitions`, {
|
||||
targetPhase: target,
|
||||
decision: target === PurchaseEvaluationPhase.TuChoi ? 2 : 1,
|
||||
decision: isReject ? 2 : 1,
|
||||
comment: comment || null,
|
||||
}),
|
||||
})
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Đã chuyển phase.')
|
||||
qc.invalidateQueries({ queryKey: ['pe-detail', evaluation.id] })
|
||||
@ -101,22 +109,37 @@ export function PeWorkflowPanel({
|
||||
|
||||
{next.length > 0 && !readOnly && (
|
||||
<div>
|
||||
<Label className="text-xs">Chuyển tiếp:</Label>
|
||||
<Label className="text-xs">Hành động:</Label>
|
||||
<div className="mt-1 flex flex-wrap gap-1.5">
|
||||
{next.map(p => (
|
||||
<button
|
||||
key={p}
|
||||
onClick={() => setTarget(p)}
|
||||
className={cn(
|
||||
'rounded border px-2 py-1 text-[11px] transition',
|
||||
p === PurchaseEvaluationPhase.TuChoi
|
||||
? 'border-red-200 text-red-700 hover:bg-red-50'
|
||||
: 'border-brand-300 text-brand-700 hover:bg-brand-50',
|
||||
)}
|
||||
>
|
||||
→ {PurchaseEvaluationPhaseLabel[p]}
|
||||
</button>
|
||||
))}
|
||||
{next.map(p => {
|
||||
// Phân loại button theo hành động:
|
||||
// - Trả lại = về DangSoanThao (từ phase trung gian) — red
|
||||
// - Hủy/Từ chối = TuChoi (chỉ ở phase DangSoanThao đầu) — red
|
||||
// - Duyệt = forward phase tiếp theo — brand
|
||||
const isSendBack = p === PurchaseEvaluationPhase.DangSoanThao
|
||||
&& evaluation.phase !== PurchaseEvaluationPhase.DangSoanThao
|
||||
const isCancel = p === PurchaseEvaluationPhase.TuChoi
|
||||
const isDanger = isSendBack || isCancel
|
||||
const label = isSendBack
|
||||
? '← Trả lại (về Drafter sửa)'
|
||||
: isCancel
|
||||
? '✗ Hủy / Từ chối'
|
||||
: `✓ Duyệt → ${PurchaseEvaluationPhaseLabel[p]}`
|
||||
return (
|
||||
<button
|
||||
key={p}
|
||||
onClick={() => setTarget(p)}
|
||||
className={cn(
|
||||
'rounded border px-2 py-1 text-[11px] font-medium transition',
|
||||
isDanger
|
||||
? 'border-red-200 text-red-700 hover:bg-red-50'
|
||||
: 'border-brand-300 text-brand-700 hover:bg-brand-50',
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@ -126,20 +149,40 @@ export function PeWorkflowPanel({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{target !== null && (
|
||||
<Dialog
|
||||
open
|
||||
onClose={() => setTarget(null)}
|
||||
title={`Chuyển → ${PurchaseEvaluationPhaseLabel[target]}`}
|
||||
footer={<>
|
||||
<Button variant="ghost" onClick={() => setTarget(null)}>Hủy</Button>
|
||||
<Button onClick={() => transition.mutate()} disabled={transition.isPending}>Xác nhận</Button>
|
||||
</>}
|
||||
>
|
||||
<Label>Ghi chú (tùy chọn)</Label>
|
||||
<Textarea value={comment} onChange={e => setComment(e.target.value)} rows={3} />
|
||||
</Dialog>
|
||||
)}
|
||||
{target !== null && (() => {
|
||||
const isCancel = target === PurchaseEvaluationPhase.TuChoi
|
||||
const isSendBack = target === PurchaseEvaluationPhase.DangSoanThao
|
||||
&& evaluation.phase !== PurchaseEvaluationPhase.DangSoanThao
|
||||
const dialogTitle = isCancel
|
||||
? '✗ Từ chối phiếu (khoá hoàn toàn)'
|
||||
: isSendBack
|
||||
? '← Trả lại Drafter sửa'
|
||||
: `✓ Duyệt → ${PurchaseEvaluationPhaseLabel[target]}`
|
||||
return (
|
||||
<Dialog
|
||||
open
|
||||
onClose={() => setTarget(null)}
|
||||
title={dialogTitle}
|
||||
footer={<>
|
||||
<Button variant="ghost" onClick={() => setTarget(null)}>Hủy</Button>
|
||||
<Button onClick={() => transition.mutate()} disabled={transition.isPending}>Xác nhận</Button>
|
||||
</>}
|
||||
>
|
||||
{isCancel && (
|
||||
<div className="mb-3 rounded border border-red-200 bg-red-50 px-3 py-2 text-[11px] text-red-800">
|
||||
⚠ Phiếu sẽ bị khoá hoàn toàn (không edit/transition được nữa). Drafter cần tạo phiếu mới nếu muốn làm lại.
|
||||
</div>
|
||||
)}
|
||||
{isSendBack && (
|
||||
<div className="mb-3 rounded border border-amber-200 bg-amber-50 px-3 py-2 text-[11px] text-amber-800">
|
||||
Phiếu sẽ về “Đang soạn thảo”. Drafter có thể sửa rồi trình lại — workflow tự jump tới phase này.
|
||||
</div>
|
||||
)}
|
||||
<Label>Ghi chú (tùy chọn)</Label>
|
||||
<Textarea value={comment} onChange={e => setComment(e.target.value)} rows={3} />
|
||||
</Dialog>
|
||||
)
|
||||
})()}
|
||||
|
||||
{deptApprovals.length > 0 && (
|
||||
<div className="border-t border-slate-200 pt-4">
|
||||
|
||||
@ -45,12 +45,20 @@ export function PeWorkflowPanel({
|
||||
})
|
||||
|
||||
const transition = useMutation({
|
||||
mutationFn: async () =>
|
||||
api.post(`/purchase-evaluations/${evaluation.id}/transitions`, {
|
||||
mutationFn: async () => {
|
||||
// Decision = Reject (2) khi:
|
||||
// - target = TuChoi (huỷ phiếu)
|
||||
// - target = DangSoanThao từ phase trung gian (= Trả lại — smart reject Mig 16
|
||||
// set RejectedFromPhase + clear N-stage rows + Drafter resume jump-back)
|
||||
const isReject = target === PurchaseEvaluationPhase.TuChoi
|
||||
|| (target === PurchaseEvaluationPhase.DangSoanThao
|
||||
&& evaluation.phase !== PurchaseEvaluationPhase.DangSoanThao)
|
||||
return api.post(`/purchase-evaluations/${evaluation.id}/transitions`, {
|
||||
targetPhase: target,
|
||||
decision: target === PurchaseEvaluationPhase.TuChoi ? 2 : 1,
|
||||
decision: isReject ? 2 : 1,
|
||||
comment: comment || null,
|
||||
}),
|
||||
})
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Đã chuyển phase.')
|
||||
qc.invalidateQueries({ queryKey: ['pe-detail', evaluation.id] })
|
||||
@ -101,22 +109,37 @@ export function PeWorkflowPanel({
|
||||
|
||||
{next.length > 0 && !readOnly && (
|
||||
<div>
|
||||
<Label className="text-xs">Chuyển tiếp:</Label>
|
||||
<Label className="text-xs">Hành động:</Label>
|
||||
<div className="mt-1 flex flex-wrap gap-1.5">
|
||||
{next.map(p => (
|
||||
<button
|
||||
key={p}
|
||||
onClick={() => setTarget(p)}
|
||||
className={cn(
|
||||
'rounded border px-2 py-1 text-[11px] transition',
|
||||
p === PurchaseEvaluationPhase.TuChoi
|
||||
? 'border-red-200 text-red-700 hover:bg-red-50'
|
||||
: 'border-brand-300 text-brand-700 hover:bg-brand-50',
|
||||
)}
|
||||
>
|
||||
→ {PurchaseEvaluationPhaseLabel[p]}
|
||||
</button>
|
||||
))}
|
||||
{next.map(p => {
|
||||
// Phân loại button theo hành động:
|
||||
// - Trả lại = về DangSoanThao (từ phase trung gian) — red
|
||||
// - Hủy/Từ chối = TuChoi (chỉ ở phase DangSoanThao đầu) — red
|
||||
// - Duyệt = forward phase tiếp theo — brand
|
||||
const isSendBack = p === PurchaseEvaluationPhase.DangSoanThao
|
||||
&& evaluation.phase !== PurchaseEvaluationPhase.DangSoanThao
|
||||
const isCancel = p === PurchaseEvaluationPhase.TuChoi
|
||||
const isDanger = isSendBack || isCancel
|
||||
const label = isSendBack
|
||||
? '← Trả lại (về Drafter sửa)'
|
||||
: isCancel
|
||||
? '✗ Hủy / Từ chối'
|
||||
: `✓ Duyệt → ${PurchaseEvaluationPhaseLabel[p]}`
|
||||
return (
|
||||
<button
|
||||
key={p}
|
||||
onClick={() => setTarget(p)}
|
||||
className={cn(
|
||||
'rounded border px-2 py-1 text-[11px] font-medium transition',
|
||||
isDanger
|
||||
? 'border-red-200 text-red-700 hover:bg-red-50'
|
||||
: 'border-brand-300 text-brand-700 hover:bg-brand-50',
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@ -126,20 +149,40 @@ export function PeWorkflowPanel({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{target !== null && (
|
||||
<Dialog
|
||||
open
|
||||
onClose={() => setTarget(null)}
|
||||
title={`Chuyển → ${PurchaseEvaluationPhaseLabel[target]}`}
|
||||
footer={<>
|
||||
<Button variant="ghost" onClick={() => setTarget(null)}>Hủy</Button>
|
||||
<Button onClick={() => transition.mutate()} disabled={transition.isPending}>Xác nhận</Button>
|
||||
</>}
|
||||
>
|
||||
<Label>Ghi chú (tùy chọn)</Label>
|
||||
<Textarea value={comment} onChange={e => setComment(e.target.value)} rows={3} />
|
||||
</Dialog>
|
||||
)}
|
||||
{target !== null && (() => {
|
||||
const isCancel = target === PurchaseEvaluationPhase.TuChoi
|
||||
const isSendBack = target === PurchaseEvaluationPhase.DangSoanThao
|
||||
&& evaluation.phase !== PurchaseEvaluationPhase.DangSoanThao
|
||||
const dialogTitle = isCancel
|
||||
? '✗ Từ chối phiếu (khoá hoàn toàn)'
|
||||
: isSendBack
|
||||
? '← Trả lại Drafter sửa'
|
||||
: `✓ Duyệt → ${PurchaseEvaluationPhaseLabel[target]}`
|
||||
return (
|
||||
<Dialog
|
||||
open
|
||||
onClose={() => setTarget(null)}
|
||||
title={dialogTitle}
|
||||
footer={<>
|
||||
<Button variant="ghost" onClick={() => setTarget(null)}>Hủy</Button>
|
||||
<Button onClick={() => transition.mutate()} disabled={transition.isPending}>Xác nhận</Button>
|
||||
</>}
|
||||
>
|
||||
{isCancel && (
|
||||
<div className="mb-3 rounded border border-red-200 bg-red-50 px-3 py-2 text-[11px] text-red-800">
|
||||
⚠ Phiếu sẽ bị khoá hoàn toàn (không edit/transition được nữa). Drafter cần tạo phiếu mới nếu muốn làm lại.
|
||||
</div>
|
||||
)}
|
||||
{isSendBack && (
|
||||
<div className="mb-3 rounded border border-amber-200 bg-amber-50 px-3 py-2 text-[11px] text-amber-800">
|
||||
Phiếu sẽ về “Đang soạn thảo”. Drafter có thể sửa rồi trình lại — workflow tự jump tới phase này.
|
||||
</div>
|
||||
)}
|
||||
<Label>Ghi chú (tùy chọn)</Label>
|
||||
<Textarea value={comment} onChange={e => setComment(e.target.value)} rows={3} />
|
||||
</Dialog>
|
||||
)
|
||||
})()}
|
||||
|
||||
{deptApprovals.length > 0 && (
|
||||
<div className="border-t border-slate-200 pt-4">
|
||||
|
||||
@ -56,14 +56,20 @@ public static class PurchaseEvaluationPolicies
|
||||
[(PurchaseEvaluationPhase.DangSoanThao, PurchaseEvaluationPhase.ChoPurchasing)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
[(PurchaseEvaluationPhase.DangSoanThao, PurchaseEvaluationPhase.TuChoi)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
|
||||
// Phase trung gian: 3 hành động — Duyệt forward / Trả lại Drafter (DangSoanThao) / Từ chối hoàn toàn (TuChoi).
|
||||
// Trả lại = smart reject pattern Mig 16 (set RejectedFromPhase + về DangSoanThao + Drafter sửa).
|
||||
// Từ chối = phiếu khoá hoàn toàn (Phase=TuChoi → 17 handler Mig 16 lock edit).
|
||||
[(PurchaseEvaluationPhase.ChoPurchasing, PurchaseEvaluationPhase.ChoCCM)] = [AppRoles.Procurement],
|
||||
[(PurchaseEvaluationPhase.ChoPurchasing, PurchaseEvaluationPhase.DangSoanThao)] = [AppRoles.Procurement],
|
||||
[(PurchaseEvaluationPhase.ChoPurchasing, PurchaseEvaluationPhase.TuChoi)] = [AppRoles.Procurement],
|
||||
|
||||
[(PurchaseEvaluationPhase.ChoCCM, PurchaseEvaluationPhase.ChoCEODuyetNCC)] = [AppRoles.CostControl],
|
||||
[(PurchaseEvaluationPhase.ChoCCM, PurchaseEvaluationPhase.DangSoanThao)] = [AppRoles.CostControl],
|
||||
[(PurchaseEvaluationPhase.ChoCCM, PurchaseEvaluationPhase.TuChoi)] = [AppRoles.CostControl],
|
||||
|
||||
[(PurchaseEvaluationPhase.ChoCEODuyetNCC, PurchaseEvaluationPhase.DaDuyet)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
[(PurchaseEvaluationPhase.ChoCEODuyetNCC, PurchaseEvaluationPhase.DangSoanThao)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
[(PurchaseEvaluationPhase.ChoCEODuyetNCC, PurchaseEvaluationPhase.TuChoi)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
},
|
||||
PhaseSla: DefaultSla,
|
||||
ActivePhases:
|
||||
@ -85,20 +91,26 @@ public static class PurchaseEvaluationPolicies
|
||||
[(PurchaseEvaluationPhase.DangSoanThao, PurchaseEvaluationPhase.ChoPurchasing)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
[(PurchaseEvaluationPhase.DangSoanThao, PurchaseEvaluationPhase.TuChoi)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
|
||||
// Phase trung gian: 3 hành động — Duyệt forward / Trả lại / Từ chối (xem comment NccOnly).
|
||||
[(PurchaseEvaluationPhase.ChoPurchasing, PurchaseEvaluationPhase.ChoDuAn)] = [AppRoles.Procurement],
|
||||
[(PurchaseEvaluationPhase.ChoPurchasing, PurchaseEvaluationPhase.DangSoanThao)] = [AppRoles.Procurement],
|
||||
[(PurchaseEvaluationPhase.ChoPurchasing, PurchaseEvaluationPhase.TuChoi)] = [AppRoles.Procurement],
|
||||
|
||||
[(PurchaseEvaluationPhase.ChoDuAn, PurchaseEvaluationPhase.ChoCCM)] = [AppRoles.ProjectManager],
|
||||
[(PurchaseEvaluationPhase.ChoDuAn, PurchaseEvaluationPhase.DangSoanThao)] = [AppRoles.ProjectManager],
|
||||
[(PurchaseEvaluationPhase.ChoDuAn, PurchaseEvaluationPhase.TuChoi)] = [AppRoles.ProjectManager],
|
||||
|
||||
[(PurchaseEvaluationPhase.ChoCCM, PurchaseEvaluationPhase.ChoCEODuyetPA)] = [AppRoles.CostControl],
|
||||
[(PurchaseEvaluationPhase.ChoCCM, PurchaseEvaluationPhase.DangSoanThao)] = [AppRoles.CostControl],
|
||||
[(PurchaseEvaluationPhase.ChoCCM, PurchaseEvaluationPhase.TuChoi)] = [AppRoles.CostControl],
|
||||
|
||||
[(PurchaseEvaluationPhase.ChoCEODuyetPA, PurchaseEvaluationPhase.ChoCEODuyetNCC)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
[(PurchaseEvaluationPhase.ChoCEODuyetPA, PurchaseEvaluationPhase.DangSoanThao)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
[(PurchaseEvaluationPhase.ChoCEODuyetPA, PurchaseEvaluationPhase.TuChoi)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
|
||||
[(PurchaseEvaluationPhase.ChoCEODuyetNCC, PurchaseEvaluationPhase.DaDuyet)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
[(PurchaseEvaluationPhase.ChoCEODuyetNCC, PurchaseEvaluationPhase.DangSoanThao)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
[(PurchaseEvaluationPhase.ChoCEODuyetNCC, PurchaseEvaluationPhase.TuChoi)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
},
|
||||
PhaseSla: DefaultSla,
|
||||
ActivePhases:
|
||||
@ -171,17 +183,21 @@ public static class PurchaseEvaluationPolicyRegistry
|
||||
transitions[(prev.Value, s.Phase)] = roles;
|
||||
if (userIds.Length > 0) userTransitions[(prev.Value, s.Phase)] = userIds;
|
||||
|
||||
// Reject path back to Drafter (common pattern)
|
||||
// 3 hành động phase trung gian — Duyệt forward + Trả lại Drafter + Từ chối hoàn toàn
|
||||
if (prev.Value != PurchaseEvaluationPhase.DangSoanThao && s.Phase != PurchaseEvaluationPhase.DangSoanThao)
|
||||
{
|
||||
transitions.TryAdd((s.Phase, PurchaseEvaluationPhase.DangSoanThao), roles);
|
||||
transitions.TryAdd((s.Phase, PurchaseEvaluationPhase.TuChoi), roles);
|
||||
if (userIds.Length > 0)
|
||||
{
|
||||
userTransitions.TryAdd((s.Phase, PurchaseEvaluationPhase.DangSoanThao), userIds);
|
||||
userTransitions.TryAdd((s.Phase, PurchaseEvaluationPhase.TuChoi), userIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
prev = s.Phase;
|
||||
}
|
||||
// First step có thể reject to TuChoi
|
||||
// First step (DangSoanThao) — Drafter có thể TuChoi (huỷ phiếu)
|
||||
if (steps.Count > 0)
|
||||
transitions.TryAdd((steps[0].Phase, PurchaseEvaluationPhase.TuChoi),
|
||||
[AppRoles.Drafter, AppRoles.DeptManager]);
|
||||
|
||||
@ -43,17 +43,25 @@ public class PurchaseEvaluationWorkflowService(
|
||||
|
||||
if (decision == ApprovalDecision.Reject)
|
||||
{
|
||||
evaluation.RejectedFromPhase = fromPhase;
|
||||
targetPhase = PurchaseEvaluationPhase.DangSoanThao;
|
||||
// 2 loại Reject (Session 14):
|
||||
// - target=TuChoi: "Từ chối hoàn toàn" — phiếu khoá vĩnh viễn (Phase=TuChoi
|
||||
// → 17 handler Mig 16 lock edit). Drafter phải tạo phiếu mới. KHÔNG set
|
||||
// RejectedFromPhase + KHÔNG clear N-stage (không resume).
|
||||
// - target khác (thường = DangSoanThao): "Trả lại" — smart reject pattern
|
||||
// Mig 16. Set RejectedFromPhase + force DangSoanThao + clear N-stage rows
|
||||
// tại fromPhase → Drafter sửa rồi trình lại jump-back tới phase đã reject.
|
||||
if (targetPhase != PurchaseEvaluationPhase.TuChoi)
|
||||
{
|
||||
evaluation.RejectedFromPhase = fromPhase;
|
||||
targetPhase = PurchaseEvaluationPhase.DangSoanThao;
|
||||
|
||||
// N-stage state reset (Mig 18): clear inner step approval rows tại
|
||||
// fromPhase. User resume sẽ approve lại từ inner step đầu.
|
||||
var staleNStageRows = await db.PurchaseEvaluationDepartmentApprovals
|
||||
.Where(a => a.PurchaseEvaluationId == evaluation.Id
|
||||
&& a.PhaseAtApproval == (int)fromPhase
|
||||
&& a.InnerStepId != null)
|
||||
.ToListAsync(ct);
|
||||
foreach (var r in staleNStageRows) db.PurchaseEvaluationDepartmentApprovals.Remove(r);
|
||||
var staleNStageRows = await db.PurchaseEvaluationDepartmentApprovals
|
||||
.Where(a => a.PurchaseEvaluationId == evaluation.Id
|
||||
&& a.PhaseAtApproval == (int)fromPhase
|
||||
&& a.InnerStepId != null)
|
||||
.ToListAsync(ct);
|
||||
foreach (var r in staleNStageRows) db.PurchaseEvaluationDepartmentApprovals.Remove(r);
|
||||
}
|
||||
}
|
||||
else if (isResumingAfterReject)
|
||||
{
|
||||
|
||||
@ -278,11 +278,11 @@ public class PeNStageApprovalTests : IClassFixture<IdentityFixture>
|
||||
|
||||
pe = await _db.PurchaseEvaluations.FirstAsync(x => x.Id == pe.Id);
|
||||
|
||||
// Act: admin reject (skip 2-stage gate).
|
||||
// Act: admin "Trả lại" (target=DangSoanThao + decision=Reject Session 14).
|
||||
var admin = await _fx.CreateUserAsync($"adm-rej-{Guid.NewGuid():N}@test", "Admin", null, ["Admin"]);
|
||||
await _service.TransitionAsync(
|
||||
pe, PurchaseEvaluationPhase.TuChoi, admin.Id, ["Admin"],
|
||||
ApprovalDecision.Reject, "reject test");
|
||||
pe, PurchaseEvaluationPhase.DangSoanThao, admin.Id, ["Admin"],
|
||||
ApprovalDecision.Reject, "trả lại test");
|
||||
|
||||
// Assert: phase = DangSoanThao, RejectedFromPhase = ChoPurchasing,
|
||||
// N-stage rows tại ChoPurchasing đã clear.
|
||||
|
||||
@ -197,24 +197,41 @@ public class PeTwoStageApprovalTests : IClassFixture<IdentityFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Reject_Sets_RejectedFromPhase_And_Forces_DangSoanThao()
|
||||
public async Task Reject_To_DangSoanThao_Sets_RejectedFromPhase_TraLai()
|
||||
{
|
||||
// Arrange: PE phase=ChoCCM. Drafter reject.
|
||||
// Session 14: "Trả lại" semantic — target=DangSoanThao + decision=Reject.
|
||||
// Service set RejectedFromPhase + force về DangSoanThao + Drafter resume jump-back.
|
||||
var actor = await _fx.CreateUserAsync(
|
||||
$"ccm-{Guid.NewGuid():N}@test", "CCM TPB", _deptCcm, ["DeptManager", "CostControl"]);
|
||||
var pe = await SeedPeAsync(PurchaseEvaluationPhase.ChoCCM);
|
||||
|
||||
// Act: reject (target irrelevant — service forces về DangSoanThao).
|
||||
await _service.TransitionAsync(
|
||||
pe, PurchaseEvaluationPhase.TuChoi, actor.Id, ["DeptManager", "CostControl"],
|
||||
ApprovalDecision.Reject, "không phù hợp");
|
||||
pe, PurchaseEvaluationPhase.DangSoanThao, actor.Id, ["DeptManager", "CostControl"],
|
||||
ApprovalDecision.Reject, "trả lại Drafter sửa");
|
||||
|
||||
// Assert.
|
||||
var fresh = await _db.PurchaseEvaluations.AsNoTracking().FirstAsync(x => x.Id == pe.Id);
|
||||
fresh.Phase.Should().Be(PurchaseEvaluationPhase.DangSoanThao);
|
||||
fresh.RejectedFromPhase.Should().Be(PurchaseEvaluationPhase.ChoCCM);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Reject_To_TuChoi_Locks_Permanently_No_RejectedFromPhase()
|
||||
{
|
||||
// Session 14: "Từ chối" semantic — target=TuChoi + decision=Reject.
|
||||
// Service KHÔNG override target + KHÔNG set RejectedFromPhase (phiếu khoá vĩnh viễn).
|
||||
var actor = await _fx.CreateUserAsync(
|
||||
$"ccm-{Guid.NewGuid():N}@test", "CCM TPB cancel", _deptCcm, ["DeptManager", "CostControl"]);
|
||||
var pe = await SeedPeAsync(PurchaseEvaluationPhase.ChoCCM);
|
||||
|
||||
await _service.TransitionAsync(
|
||||
pe, PurchaseEvaluationPhase.TuChoi, actor.Id, ["DeptManager", "CostControl"],
|
||||
ApprovalDecision.Reject, "từ chối hoàn toàn");
|
||||
|
||||
var fresh = await _db.PurchaseEvaluations.AsNoTracking().FirstAsync(x => x.Id == pe.Id);
|
||||
fresh.Phase.Should().Be(PurchaseEvaluationPhase.TuChoi);
|
||||
fresh.RejectedFromPhase.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Resume_After_Reject_Jumps_Back_To_RejectedPhase()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user