From 61fa2c3f851eaed5d5fdcf3e9cee899cfdfa9628 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Fri, 15 Feb 2019 16:22:21 +0100
Subject: [PATCH] refactorings & todo refactorings

---
 entity/Orderitem_entity/Orderitem_entity.aod     | 16 +++++++++++++++-
 .../product_id/possibleItemsProcess.js           | 16 ----------------
 .../product_id.displayvalue/expression.js        |  5 +++++
 .../entityfields/image/onValueChange.js          |  2 +-
 .../standard_email_comm/onValueChange.js         |  2 +-
 .../standard_phone_comm/onValueChange.js         |  2 +-
 .../recordcontainers/db/onDBUpdate.js            |  2 +-
 entity/Product_entity/Product_entity.aod         |  6 ++++++
 .../entityfields/image/onValueChange.js          |  2 +-
 .../recordcontainers/db/onDBUpdate.js            |  2 +-
 .../_____PREFERENCES_PROJECT.aod                 |  2 +-
 11 files changed, 33 insertions(+), 24 deletions(-)
 delete mode 100644 entity/Orderitem_entity/entityfields/product_id/possibleItemsProcess.js
 create mode 100644 entity/Orderitem_entity/recordcontainers/db/recordfieldmappings/product_id.displayvalue/expression.js

diff --git a/entity/Orderitem_entity/Orderitem_entity.aod b/entity/Orderitem_entity/Orderitem_entity.aod
index ae3ec522497..14b2e4111b7 100644
--- a/entity/Orderitem_entity/Orderitem_entity.aod
+++ b/entity/Orderitem_entity/Orderitem_entity.aod
@@ -62,7 +62,8 @@
       <name>PRODUCT_ID</name>
       <documentation>%aditoprj%/entity/Orderitem_entity/entityfields/product_id/documentation.adoc</documentation>
       <title>Article</title>
-      <possibleItemsProcess>%aditoprj%/entity/Orderitem_entity/entityfields/product_id/possibleItemsProcess.js</possibleItemsProcess>
+      <consumer>Products</consumer>
+      <linkedContext>Product_context</linkedContext>
       <onValueChange>%aditoprj%/entity/Orderitem_entity/entityfields/product_id/onValueChange.js</onValueChange>
       <onValueChangeTypes>
         <element>MASK</element>
@@ -182,6 +183,15 @@
         </entityParameter>
       </children>
     </entityConsumer>
+    <entityConsumer>
+      <name>Products</name>
+      <fieldType>DEPENDENCY_OUT</fieldType>
+      <dependency>
+        <name>dependency</name>
+        <entityName>Product_entity</entityName>
+        <fieldName>#PROVIDER</fieldName>
+      </dependency>
+    </entityConsumer>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
@@ -271,6 +281,10 @@
           <name>UNIT.displayValue</name>
           <expression>%aditoprj%/entity/Orderitem_entity/recordcontainers/db/recordfieldmappings/unit.displayvalue/expression.js</expression>
         </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>PRODUCT_ID.displayValue</name>
+          <expression>%aditoprj%/entity/Orderitem_entity/recordcontainers/db/recordfieldmappings/product_id.displayvalue/expression.js</expression>
+        </dbRecordFieldMapping>
       </recordFieldMappings>
     </dbRecordContainer>
   </recordContainers>
diff --git a/entity/Orderitem_entity/entityfields/product_id/possibleItemsProcess.js b/entity/Orderitem_entity/entityfields/product_id/possibleItemsProcess.js
deleted file mode 100644
index e19938f82d7..00000000000
--- a/entity/Orderitem_entity/entityfields/product_id/possibleItemsProcess.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import("system.result");
-import("system.db");
-import("Sql_lib");
-
-//TODO: change field to lookup field
-var sqlUtils = new SqlMaskingUtils();
-var prodsSql = "select PRODUCTID, " + sqlUtils.concat(["PRODUCTCODE", "PRODUCTNAME"], "/") 
-                    + " from PRODUCT";
-
-var prods = db.table(prodsSql);
-
-var retArray = [];
-for(var i = 0; i < prods.length; i++)
-    retArray.push(prods[i]);
-
-result.object(retArray);
\ No newline at end of file
diff --git a/entity/Orderitem_entity/recordcontainers/db/recordfieldmappings/product_id.displayvalue/expression.js b/entity/Orderitem_entity/recordcontainers/db/recordfieldmappings/product_id.displayvalue/expression.js
new file mode 100644
index 00000000000..c356272a550
--- /dev/null
+++ b/entity/Orderitem_entity/recordcontainers/db/recordfieldmappings/product_id.displayvalue/expression.js
@@ -0,0 +1,5 @@
+import("system.vars");
+import("system.result");
+
+// TODO: remove when #title is used as display value for lookups
+result.string("(select PRODUCT.PRODUCTNAME from PRODUCT where SALESORDERITEM.PRODUCT_ID = PRODUCT.PRODUCTID)");
\ No newline at end of file
diff --git a/entity/Person_entity/entityfields/image/onValueChange.js b/entity/Person_entity/entityfields/image/onValueChange.js
index f7fffb124f8..86a4f85653a 100644
--- a/entity/Person_entity/entityfields/image/onValueChange.js
+++ b/entity/Person_entity/entityfields/image/onValueChange.js
@@ -1,4 +1,4 @@
 import("Entity_lib");
 
-// TODO: also there is currently no good way to do updates with fields not connected to the record container. Workaround: imagevariable and update in onDBUpdate Process
+// TODO: also there is currently no good way to do updates with fields not connected to the record container. Workaround: imagevariable and update in onDBUpdate Process #1030023
 FieldChanges.setChange("$field.IMAGE");
\ No newline at end of file
diff --git a/entity/Person_entity/entityfields/standard_email_comm/onValueChange.js b/entity/Person_entity/entityfields/standard_email_comm/onValueChange.js
index 25c5a67ac86..972cb181d55 100644
--- a/entity/Person_entity/entityfields/standard_email_comm/onValueChange.js
+++ b/entity/Person_entity/entityfields/standard_email_comm/onValueChange.js
@@ -1,4 +1,4 @@
 import("Entity_lib");
 
-// TODO: also there is currently no good way to do updates with fields not connected to the record container. Workaround: imagevariable and update in onDBUpdate Process
+// TODO: also there is currently no good way to do updates with fields not connected to the record container. Workaround: imagevariable and update in onDBUpdate Process #1030023
 FieldChanges.setChange("$field.STANDARD_EMAIL_COMMUNICATION");
\ No newline at end of file
diff --git a/entity/Person_entity/entityfields/standard_phone_comm/onValueChange.js b/entity/Person_entity/entityfields/standard_phone_comm/onValueChange.js
index fd9905c4cde..991c92d38d0 100644
--- a/entity/Person_entity/entityfields/standard_phone_comm/onValueChange.js
+++ b/entity/Person_entity/entityfields/standard_phone_comm/onValueChange.js
@@ -1,4 +1,4 @@
 import("Entity_lib");
 
-// TODO: also there is currently no good way to do updates with fields not connected to the record container. Workaround: imagevariable and update in onDBUpdate Process
+// TODO: also there is currently no good way to do updates with fields not connected to the record container. Workaround: imagevariable and update in onDBUpdate Process #1030023
 FieldChanges.setChange("$field.STANDARD_PHONE_COMMUNICATION");
\ No newline at end of file
diff --git a/entity/Person_entity/recordcontainers/db/onDBUpdate.js b/entity/Person_entity/recordcontainers/db/onDBUpdate.js
index ebda79e5118..c1aaada5945 100644
--- a/entity/Person_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Person_entity/recordcontainers/db/onDBUpdate.js
@@ -3,7 +3,7 @@ import("Person_lib");
 import("Communication_lib");
 import("Entity_lib");
 
-// TODO: this is a workaround for missing possibility to react on changes of fields not connected to record Contqainer
+// TODO: this is a workaround for missing possibility to react on changes of fields not connected to record Contqainer #1030023
 FieldChanges.assimilateChangeAndDispose("$field.IMAGE", function(state, value){
     if (state == FieldChanges.STATE_CHANGED())
         PersUtils.setImage(vars.get("$field.PERSONID"), value);
diff --git a/entity/Product_entity/Product_entity.aod b/entity/Product_entity/Product_entity.aod
index 678e3886fa7..2cd464e46c2 100644
--- a/entity/Product_entity/Product_entity.aod
+++ b/entity/Product_entity/Product_entity.aod
@@ -153,6 +153,12 @@
           <fieldName>Products</fieldName>
           <isConsumer v="false" />
         </entityDependency>
+        <entityDependency>
+          <name>e4ba4c26-a777-4560-ab68-311ffae76e2f</name>
+          <entityName>Orderitem_entity</entityName>
+          <fieldName>Products</fieldName>
+          <isConsumer v="false" />
+        </entityDependency>
       </dependencies>
     </entityProvider>
     <entityConsumer>
diff --git a/entity/Product_entity/entityfields/image/onValueChange.js b/entity/Product_entity/entityfields/image/onValueChange.js
index 4997061690d..1fc5daeeea2 100644
--- a/entity/Product_entity/entityfields/image/onValueChange.js
+++ b/entity/Product_entity/entityfields/image/onValueChange.js
@@ -1,5 +1,5 @@
 import("system.vars");
 import("Entity_lib");
 
-// TODO: also there is currently no good way to do updates with fields not connected to the record container. Workaround: imagevariable and update in onDBUpdate Process
+// TODO: also there is currently no good way to do updates with fields not connected to the record container. Workaround: imagevariable and update in onDBUpdate Process #1030023
 FieldChanges.setChange("$field.IMAGE");
\ No newline at end of file
diff --git a/entity/Product_entity/recordcontainers/db/onDBUpdate.js b/entity/Product_entity/recordcontainers/db/onDBUpdate.js
index de4985229e6..11c4f6b2dd5 100644
--- a/entity/Product_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Product_entity/recordcontainers/db/onDBUpdate.js
@@ -2,7 +2,7 @@ import("system.vars");
 import("Product_lib");
 import("Entity_lib");
 
-// TODO: this is a workaround for missing possibility to react on changes of fields not connected to record Contqainer
+// TODO: this is a workaround for missing possibility to react on changes of fields not connected to record Contqainer #1030023
 FieldChanges.assimilateChangeAndDispose("$field.IMAGE", function(state, value){
     if (state == FieldChanges.STATE_CHANGED())
         ProductUtils.setImage(vars.get("$field.PRODUCTID"), value);
diff --git a/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod b/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod
index 5edf76c7779..336d6b092bd 100644
--- a/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod
+++ b/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod
@@ -2,7 +2,7 @@
 <preferences xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="3.0.3" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/preferences/3.0.3">
   <name>_____PREFERENCES_PROJECT</name>
   <majorModelMode>DISTRIBUTED</majorModelMode>
-  <projectName>xRM-Basic5</projectName>
+  <projectName>xRM-Basic2019</projectName>
   <jditoMaxContentSize v="57671680" />
   <calendarCategoriesEvent>
     <entry>
-- 
GitLab