mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 23:05:44 +00:00
Fix[BE]: fix wrong approval step when SO uppdated
This commit is contained in:
@@ -291,32 +291,30 @@ func (s salesOrdersService) UpdateOne(c *fiber.Ctx, req *validation.Update, id u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Create new marketing product (use helper)
|
|
||||||
if err := s.createMarketingProductWithDelivery(c.Context(), id, rp, marketingProductRepoTx, invDeliveryRepoTx); err != nil {
|
if err := s.createMarketingProductWithDelivery(c.Context(), id, rp, marketingProductRepoTx, invDeliveryRepoTx); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to create marketing product")
|
return fiber.NewError(fiber.StatusInternalServerError, "Failed to create marketing product")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) Delete missing old products (prevent deletion if deliveries exist)
|
|
||||||
for _, old := range oldProducts {
|
for _, old := range oldProducts {
|
||||||
if _, ok := reqByPW[old.ProductWarehouseId]; !ok {
|
if _, ok := reqByPW[old.ProductWarehouseId]; !ok {
|
||||||
// Check delivery product for this marketing product
|
|
||||||
deliveryProduct, err := invDeliveryRepoTx.GetByMarketingProductID(c.Context(), old.Id)
|
deliveryProduct, err := invDeliveryRepoTx.GetByMarketingProductID(c.Context(), old.Id)
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to check existing delivery product")
|
return fiber.NewError(fiber.StatusInternalServerError, "Failed to check existing delivery product")
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// If delivery exists (delivery_date not nil or qty > 0), prevent deletion
|
|
||||||
if deliveryProduct.DeliveryDate != nil || deliveryProduct.Qty > 0 {
|
if deliveryProduct.DeliveryDate != nil || deliveryProduct.Qty > 0 {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Cannot delete marketing product %d because it has delivery records", old.Id))
|
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Cannot delete marketing product %d because it has delivery records", old.Id))
|
||||||
}
|
}
|
||||||
// safe to delete delivery product record
|
|
||||||
if err := invDeliveryRepoTx.DeleteOne(c.Context(), deliveryProduct.Id); err != nil {
|
if err := invDeliveryRepoTx.DeleteOne(c.Context(), deliveryProduct.Id); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to delete marketing delivery product")
|
return fiber.NewError(fiber.StatusInternalServerError, "Failed to delete marketing delivery product")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Delete marketing product
|
|
||||||
if err := marketingProductRepoTx.DeleteOne(c.Context(), old.Id); err != nil {
|
if err := marketingProductRepoTx.DeleteOne(c.Context(), old.Id); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to delete marketing product")
|
return fiber.NewError(fiber.StatusInternalServerError, "Failed to delete marketing product")
|
||||||
}
|
}
|
||||||
@@ -327,7 +325,7 @@ func (s salesOrdersService) UpdateOne(c *fiber.Ctx, req *validation.Update, id u
|
|||||||
if latestApproval != nil && latestApproval.StepNumber == 2 {
|
if latestApproval != nil && latestApproval.StepNumber == 2 {
|
||||||
actorID := uint(1) // todo: ambil dari auth context
|
actorID := uint(1) // todo: ambil dari auth context
|
||||||
resetNote := ""
|
resetNote := ""
|
||||||
action := entity.ApprovalActionApproved
|
action := entity.ApprovalActionUpdated
|
||||||
_, err := approvalSvcTx.CreateApproval(
|
_, err := approvalSvcTx.CreateApproval(
|
||||||
c.Context(),
|
c.Context(),
|
||||||
utils.ApprovalWorkflowMarketing,
|
utils.ApprovalWorkflowMarketing,
|
||||||
|
|||||||
Reference in New Issue
Block a user