From 19e613884e45d092952b226d9670458d2fcac8a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patrick=20M=C3=BCller?= <p.mueller@pcsg.de>
Date: Wed, 19 Feb 2025 11:14:17 +0100
Subject: [PATCH] fix: allow new transactions to change the paid_status of an
 erroneous order

---
 src/QUI/ERP/Order/AbstractOrder.php | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/QUI/ERP/Order/AbstractOrder.php b/src/QUI/ERP/Order/AbstractOrder.php
index 9d80675b..93f6afaa 100644
--- a/src/QUI/ERP/Order/AbstractOrder.php
+++ b/src/QUI/ERP/Order/AbstractOrder.php
@@ -1695,6 +1695,15 @@ public function addTransaction(Transaction $Transaction): void
             ]
         );
 
+        /*
+         * If the paid status was erroneous and a new transaction is added to the order,
+         * we have to change the status to open because otherwise the payment status
+         * would not be set to "successful" by the calculation service.
+         */
+        if ($this->getAttribute('paid_status') === QUI\ERP\Constants::PAYMENT_STATUS_ERROR) {
+            $this->setAttribute('paid_status', QUI\ERP\Constants::PAYMENT_STATUS_OPEN);
+        }
+
         $this->calculatePayments();
 
         QUI::getEvents()->fireEvent(
-- 
GitLab