From be2a05bb6a99ba070b29a3819069c014f128b5df Mon Sep 17 00:00:00 2001
From: Henning <leutz@pcsg.de>
Date: Wed, 26 Feb 2025 09:48:41 +0100
Subject: [PATCH] fix: set user to article list at setCustomer()

This commit refactors the formatting and structure of the reversal method for improved readability.
Additionally, it removes an unnecessary exception in the 'setCustomer' method.

This commit also fixes the customer user settings in various methods in the order class. Now,
whenever a customer is set or removed, the related articles will correctly update their user status.
---
 src/QUI/ERP/Order/AbstractOrder.php | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/QUI/ERP/Order/AbstractOrder.php b/src/QUI/ERP/Order/AbstractOrder.php
index e5e45d5d..18b8003c 100644
--- a/src/QUI/ERP/Order/AbstractOrder.php
+++ b/src/QUI/ERP/Order/AbstractOrder.php
@@ -474,8 +474,10 @@ protected function setDataBaseData(array $data): void
      * @param QUI\Interfaces\Users\User|null $PermissionUser
      * @return ErpEntityInterface|null
      */
-    public function reversal(string $reason = '', null | QUI\Interfaces\Users\User $PermissionUser = null): ?ErpEntityInterface
-    {
+    public function reversal(
+        string $reason = '',
+        null | QUI\Interfaces\Users\User $PermissionUser = null
+    ): ?ErpEntityInterface {
         $this->delete($PermissionUser);
         return null;
     }
@@ -1167,7 +1169,6 @@ public function setCurrency(QUI\ERP\Currency\Currency $Currency): void
      * Set a customer to the order
      *
      * @param array|User|QUI\Interfaces\Users\User $User
-     * @throws Exception
      * @throws QUI\Exception
      * @throws ExceptionStack
      */
@@ -1264,6 +1265,7 @@ public function setCustomer(QUI\Interfaces\Users\User | array | User $User): voi
                 QUI::getEvents()->fireEvent('onQuiqqerOrderCustomerChange', [$this]);
             }
 
+            $this->Articles?->setUser($this->Customer);
             return;
         }
 
@@ -1277,6 +1279,7 @@ public function setCustomer(QUI\Interfaces\Users\User | array | User $User): voi
                 QUI::getEvents()->fireEvent('onQuiqqerOrderCustomerChange', [$this]);
             }
 
+            $this->Articles?->setUser($this->Customer);
             return;
         }
 
@@ -1293,6 +1296,8 @@ public function setCustomer(QUI\Interfaces\Users\User | array | User $User): voi
             if ($this->customerId !== $oldCustomerId) {
                 QUI::getEvents()->fireEvent('onQuiqqerOrderCustomerChange', [$this]);
             }
+
+            $this->Articles?->setUser($this->Customer);
         }
     }
 
@@ -1303,6 +1308,7 @@ public function removeCustomer(): void
     {
         $this->Customer = null;
         $this->customerId = 0;
+        $this->Articles->setUser(null);
 
         try {
             QUI::getEvents()->fireEvent('onQuiqqerOrderCustomerChange', [$this]);
-- 
GitLab