From ca1cf4a441f72820ec457ad668feb08bc5faf086 Mon Sep 17 00:00:00 2001
From: Benjamin Ulrich <b.ulrich@adito.de>
Date: Tue, 28 Sep 2021 14:38:17 +0000
Subject: [PATCH] =?UTF-8?q?[Projekt:=20xRM-Sales][TicketNr.:=201086372][Ge?=
 =?UTF-8?q?bietsdefinitionen=20durch=20asynchrone=20Ausf=C3=BChrung=20/=20?=
 =?UTF-8?q?Speicherung=20fehleranf=C3=A4llig=20(Timing=20Problem)]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 entity/Organisation_entity/Organisation_entity.aod    |  4 ++++
 entity/Organisation_entity/afterSave.js               |  3 +--
 entity/QuickEntry_entity/QuickEntry_entity.aod        |  1 +
 entity/QuickEntry_entity/afterSave.js                 | 11 +++++++++++
 .../recordcontainers/jdito/onInsert.js                |  3 ++-
 5 files changed, 19 insertions(+), 3 deletions(-)
 create mode 100644 entity/QuickEntry_entity/afterSave.js

diff --git a/entity/Organisation_entity/Organisation_entity.aod b/entity/Organisation_entity/Organisation_entity.aod
index 3f8cf72297..c26965a80a 100644
--- a/entity/Organisation_entity/Organisation_entity.aod
+++ b/entity/Organisation_entity/Organisation_entity.aod
@@ -1425,6 +1425,10 @@
         </entityParameter>
       </children>
     </entityConsumer>
+    <entityParameter>
+      <name>IsQuickEntry_param</name>
+      <expose v="true" />
+    </entityParameter>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
diff --git a/entity/Organisation_entity/afterSave.js b/entity/Organisation_entity/afterSave.js
index 4e40d8d824..3241812a70 100644
--- a/entity/Organisation_entity/afterSave.js
+++ b/entity/Organisation_entity/afterSave.js
@@ -1,9 +1,8 @@
-import("system.logging");
 import("system.vars");
 import("District_lib");
 import("system.neon");
 
-if (vars.get("$local.recordstate") == neon.OPERATINGSTATE_NEW)
+if (vars.get("$local.recordstate") == neon.OPERATINGSTATE_NEW && !vars.get("$param.IsQuickEntry_param"))
 {
     //Assign this new organisation to all according districts with auto assignment is true
     //2nd parameter "undefined" means, that the current user is determined in the function
diff --git a/entity/QuickEntry_entity/QuickEntry_entity.aod b/entity/QuickEntry_entity/QuickEntry_entity.aod
index e6cb4cfca5..613261bd84 100644
--- a/entity/QuickEntry_entity/QuickEntry_entity.aod
+++ b/entity/QuickEntry_entity/QuickEntry_entity.aod
@@ -5,6 +5,7 @@
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <documentation>%aditoprj%/entity/QuickEntry_entity/documentation.adoc</documentation>
   <onValidation>%aditoprj%/entity/QuickEntry_entity/onValidation.js</onValidation>
+  <afterSave>%aditoprj%/entity/QuickEntry_entity/afterSave.js</afterSave>
   <iconId>VAADIN:BOLT</iconId>
   <recordContainer>jdito</recordContainer>
   <entityFields>
diff --git a/entity/QuickEntry_entity/afterSave.js b/entity/QuickEntry_entity/afterSave.js
new file mode 100644
index 0000000000..8bedae6cc0
--- /dev/null
+++ b/entity/QuickEntry_entity/afterSave.js
@@ -0,0 +1,11 @@
+import("District_lib");
+import("system.vars");
+
+var entityDate = vars.get("$local.entitydata");
+
+if(entityDate["ORGANISATION_NAME"])
+{
+    //Assign this new organisation to all according districts with auto assignment is true
+    //2nd parameter "undefined" means, that the current user is determined in the function
+    DistrictUtils.assignDistrictOnServer([], undefined, entityDate["#UID"])
+}
\ No newline at end of file
diff --git a/entity/QuickEntry_entity/recordcontainers/jdito/onInsert.js b/entity/QuickEntry_entity/recordcontainers/jdito/onInsert.js
index bd04d8dc26..2d03cce14b 100644
--- a/entity/QuickEntry_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/QuickEntry_entity/recordcontainers/jdito/onInsert.js
@@ -15,7 +15,8 @@ if (rowdata["ORGANISATION_NAME.value"])
 {
     let configOrg = entities.createConfigForAddingRows();
     organisationId = rowdata["ORGANISATION_ID.value"];
-    configOrg.entity("Organisation_entity");
+    configOrg.entity("Organisation_entity")
+             .addParameter("IsQuickEntry_param", true);
     configOrg.fieldValues({
         "ORGANISATIONID": organisationId,
         "ORGANISATION_ID": organisationId,
-- 
GitLab