From 33616de91239a2b741172fb9815688bd192c9643 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Fri, 19 Jul 2019 08:53:27 +0200
Subject: [PATCH] Offer performance fixes

---
 entity/Offer_entity/Offer_entity.aod                  |  5 +++++
 .../entityfields/contact_id/displayValueProcess.js    | 11 +++++------
 .../entityfields/contact_id/linkedContextProcess.js   | 10 +++++-----
 .../contact_id.displayvalue/expression.js             |  7 +++++++
 4 files changed, 22 insertions(+), 11 deletions(-)
 create mode 100644 entity/Offer_entity/recordcontainers/db/recordfieldmappings/contact_id.displayvalue/expression.js

diff --git a/entity/Offer_entity/Offer_entity.aod b/entity/Offer_entity/Offer_entity.aod
index e9400dd1aa..6b9124e09f 100644
--- a/entity/Offer_entity/Offer_entity.aod
+++ b/entity/Offer_entity/Offer_entity.aod
@@ -199,6 +199,7 @@
       <name>printOffer</name>
       <title>Print Offer</title>
       <onActionProcess>%aditoprj%/entity/Offer_entity/entityfields/printoffer/onActionProcess.js</onActionProcess>
+      <isMenuAction v="false" />
       <iconId>VAADIN:FILE_TEXT_O</iconId>
       <stateProcess>%aditoprj%/entity/Offer_entity/entityfields/printoffer/stateProcess.js</stateProcess>
     </entityActionField>
@@ -1085,6 +1086,10 @@
           <name>CONTACT_PERSON_ID.displayValue</name>
           <expression>%aditoprj%/entity/Offer_entity/recordcontainers/db/recordfieldmappings/contact_person_id.displayvalue/expression.js</expression>
         </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>CONTACT_ID.displayValue</name>
+          <expression>%aditoprj%/entity/Offer_entity/recordcontainers/db/recordfieldmappings/contact_id.displayvalue/expression.js</expression>
+        </dbRecordFieldMapping>
       </recordFieldMappings>
     </dbRecordContainer>
     <indexRecordContainer>
diff --git a/entity/Offer_entity/entityfields/contact_id/displayValueProcess.js b/entity/Offer_entity/entityfields/contact_id/displayValueProcess.js
index d8f47a34a6..85822946ab 100644
--- a/entity/Offer_entity/entityfields/contact_id/displayValueProcess.js
+++ b/entity/Offer_entity/entityfields/contact_id/displayValueProcess.js
@@ -1,7 +1,6 @@
-import("system.result");
-import("system.vars");
-import("Contact_lib");
-import("system.neon");
-
-
+import("system.result");
+import("system.vars");
+import("Contact_lib");
+import("system.neon");
+
 result.string(ContactUtils.getFullTitleByContactId(vars.getString("$field.CONTACT_ID")));
\ No newline at end of file
diff --git a/entity/Offer_entity/entityfields/contact_id/linkedContextProcess.js b/entity/Offer_entity/entityfields/contact_id/linkedContextProcess.js
index c6e221c744..666b134974 100644
--- a/entity/Offer_entity/entityfields/contact_id/linkedContextProcess.js
+++ b/entity/Offer_entity/entityfields/contact_id/linkedContextProcess.js
@@ -1,5 +1,5 @@
-import("system.vars");
-import("system.result");
-import("Contact_lib");
-
-result.string(ContactUtils.getContextByContactId(vars.getString("$field.CONTACT_ID")));
\ No newline at end of file
+import("system.vars");
+import("system.result");
+import("Contact_lib");
+
+result.string(ContactUtils.getContextByPersOrg(vars.get("$field.CONTACT_PERSON_ID"), vars.get("$field.CONTACT_ORG_ID")));
\ No newline at end of file
diff --git a/entity/Offer_entity/recordcontainers/db/recordfieldmappings/contact_id.displayvalue/expression.js b/entity/Offer_entity/recordcontainers/db/recordfieldmappings/contact_id.displayvalue/expression.js
new file mode 100644
index 0000000000..2821fb702f
--- /dev/null
+++ b/entity/Offer_entity/recordcontainers/db/recordfieldmappings/contact_id.displayvalue/expression.js
@@ -0,0 +1,7 @@
+import("system.vars");
+import("Contact_lib");
+import("system.result");
+
+var contact = Contact.createWithColumnPreset()
+var renderer = new ContactTitleRenderer(contact, ContactTitleRenderer.OPTIONS.IncludeOrganisation);
+result.string(renderer.asSql());
\ No newline at end of file
-- 
GitLab