From 95367619a88e7454318e9c3f0e7c06a57f417a3c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patrick=20M=C3=BCller?= <p.mueller@pcsg.de>
Date: Wed, 27 Apr 2022 08:17:28 +0200
Subject: [PATCH] fix: Invoice -> load customer country fallback

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

diff --git a/src/QUI/ERP/Accounting/Invoice/Invoice.php b/src/QUI/ERP/Accounting/Invoice/Invoice.php
index 622c224..440b2e6 100644
--- a/src/QUI/ERP/Accounting/Invoice/Invoice.php
+++ b/src/QUI/ERP/Accounting/Invoice/Invoice.php
@@ -351,6 +351,15 @@ public function getCustomer(): QUI\ERP\User
             $userData['id'] = $this->getAttribute('customer_id');
         }
 
+        // Country fallback
+        if (empty($userData['country'])) {
+            if (!empty($invoiceAddress['country'])) {
+                $userData['country'] = $invoiceAddress['country'];
+            } else {
+                $userData['country'] = QUI\ERP\Defaults::getCountry()->getCode();
+            }
+        }
+
         return new QUI\ERP\User($userData);
     }
 
-- 
GitLab