mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-06-09 15:07:49 +00:00
normalize data po number to pr number and fix logic to fill field PO number
This commit is contained in:
@@ -779,8 +779,7 @@ func (s *purchaseService) ApproveManagerPurchase(c *fiber.Ctx, id uint, req *val
|
||||
transactionErr := s.PurchaseRepo.DB().WithContext(c.Context()).Transaction(func(tx *gorm.DB) error {
|
||||
updateData := map[string]any{}
|
||||
if !hasExistingPO {
|
||||
repoTx := rPurchase.NewPurchaseRepository(tx)
|
||||
code, err := repoTx.NextPoNumber(c.Context(), tx)
|
||||
code, err := derivePoFromPr(purchase.PrNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -2513,6 +2512,18 @@ func parseApprovalActionInput(raw string) (entity.ApprovalAction, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// derivePoFromPr menghasilkan po_number dari pr_number dengan swap prefix.
|
||||
// Contoh: "PR-LTI-0050" -> "PO-LTI-0050". Mengembalikan error kalau pr_number
|
||||
// tidak diawali prefix standar — caller harus memastikan PR sudah valid.
|
||||
func derivePoFromPr(prNumber string) (string, error) {
|
||||
trimmed := strings.TrimSpace(prNumber)
|
||||
if !strings.HasPrefix(trimmed, utils.PurchasePRNumberPrefix) {
|
||||
return "", fmt.Errorf("invalid pr_number %q: missing prefix %q", trimmed, utils.PurchasePRNumberPrefix)
|
||||
}
|
||||
suffix := strings.TrimPrefix(trimmed, utils.PurchasePRNumberPrefix)
|
||||
return utils.PurchasePONumberPrefix + suffix, nil
|
||||
}
|
||||
|
||||
func (s *purchaseService) rejectAndReload(
|
||||
c *fiber.Ctx,
|
||||
step approvalutils.ApprovalStep,
|
||||
|
||||
Reference in New Issue
Block a user