From 3932a507aa1e783eb7d128d15a519fa4fbf8f312 Mon Sep 17 00:00:00 2001
From: Benjamin Ulrich <b.ulrich@adito.de>
Date: Tue, 25 May 2021 13:55:46 +0000
Subject: [PATCH] Merge branch
 'sales_pn_1079933_offerstatus_lost_won_cantbeset' into '2021.1'

[Projekt: xRM-Sales][TicketNr.: 1079933][[Angebot] Status "Verloren",...

See merge request xrm/basic!978

(cherry picked from commit 6bf9d41eea11061c1bd7bea44168cc7009e4775e)

75aa38a9 [Projekt: xRM-Sales][TicketNr.: 1079933][[Angebot] Status "Verloren",...
---
 .../recordcontainers/jdito/contentProcess.js   | 18 ++++++++++++++++++
 .../ObjectProxy_entity/ObjectProxy_entity.aod  |  2 --
 entity/Offer_entity/Offer_entity.aod           |  4 ++++
 .../whitelistids_param/valueProcess.js         | 12 ++++++++++++
 entity/Offer_entity/grantUpdateProcess.js      |  4 +---
 5 files changed, 35 insertions(+), 5 deletions(-)
 create mode 100644 entity/Offer_entity/entityfields/keywordofferstates/children/whitelistids_param/valueProcess.js

diff --git a/entity/KeywordEntry_entity/recordcontainers/jdito/contentProcess.js b/entity/KeywordEntry_entity/recordcontainers/jdito/contentProcess.js
index 7fa2f2e399..bd4a9e38d8 100644
--- a/entity/KeywordEntry_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/KeywordEntry_entity/recordcontainers/jdito/contentProcess.js
@@ -20,6 +20,24 @@ var keywordStatement = newSelect("AB_KEYWORD_ENTRY.KEYID, AB_KEYWORD_ENTRY.TITLE
                 .from("AB_KEYWORD_ENTRY")
                 .join("AB_KEYWORD_CATEGORY", "AB_KEYWORD_ENTRY.AB_KEYWORD_CATEGORY_ID = AB_KEYWORD_CATEGORY.AB_KEYWORD_CATEGORYID")
                 .where();
+                
+var whitelist = JSON.parse(vars.get("$param.WhitelistIds_param"));
+var blacklist = JSON.parse(vars.get("$param.BlacklistIds_param"));
+if (whitelist)
+{
+    if (whitelist.length > 0)
+    {
+        keywordStatement.and("AB_KEYWORD_ENTRY.KEYID", whitelist, SqlBuilder.IN());
+    }
+    else
+    {
+        keywordStatement.noResult(); // force empty result if whitelist is empty
+    }
+}
+if (blacklist && blacklist.length > 0)
+{
+    keywordStatement.and("AB_KEYWORD_ENTRY.KEYID", blacklist, SqlBuilder.NOT_IN());
+}
             
 if (vars.get("$param.OnlyActives_param") == "true")
 {
diff --git a/entity/ObjectProxy_entity/ObjectProxy_entity.aod b/entity/ObjectProxy_entity/ObjectProxy_entity.aod
index de754623cf..1e633cfb90 100644
--- a/entity/ObjectProxy_entity/ObjectProxy_entity.aod
+++ b/entity/ObjectProxy_entity/ObjectProxy_entity.aod
@@ -156,8 +156,6 @@
       <name>DocumentTemplates</name>
       <dependency>
         <name>dependency</name>
-        <entityName>DocumentTemplate_entity</entityName>
-        <fieldName>#PROVIDER</fieldName>
       </dependency>
     </entityConsumer>
     <entityConsumer>
diff --git a/entity/Offer_entity/Offer_entity.aod b/entity/Offer_entity/Offer_entity.aod
index de9acec821..a16373ac50 100644
--- a/entity/Offer_entity/Offer_entity.aod
+++ b/entity/Offer_entity/Offer_entity.aod
@@ -328,6 +328,10 @@
           <valueProcess>%aditoprj%/entity/Offer_entity/entityfields/keywordofferstates/children/containername_param/valueProcess.js</valueProcess>
           <expose v="false" />
         </entityParameter>
+        <entityParameter>
+          <name>WhitelistIds_param</name>
+          <valueProcess>%aditoprj%/entity/Offer_entity/entityfields/keywordofferstates/children/whitelistids_param/valueProcess.js</valueProcess>
+        </entityParameter>
       </children>
     </entityConsumer>
     <entityConsumer>
diff --git a/entity/Offer_entity/entityfields/keywordofferstates/children/whitelistids_param/valueProcess.js b/entity/Offer_entity/entityfields/keywordofferstates/children/whitelistids_param/valueProcess.js
new file mode 100644
index 0000000000..31c9a715e4
--- /dev/null
+++ b/entity/Offer_entity/entityfields/keywordofferstates/children/whitelistids_param/valueProcess.js
@@ -0,0 +1,12 @@
+import("system.vars");
+import("system.result");
+import("KeywordRegistry_basic");
+
+if(vars.get("$field.STATUS") == $KeywordRegistry.offerStatus$sent())
+{
+    result.string(JSON.stringify([
+        $KeywordRegistry.offerStatus$sent(),
+        $KeywordRegistry.offerStatus$won(),
+        $KeywordRegistry.offerStatus$lost()
+    ]));
+}
diff --git a/entity/Offer_entity/grantUpdateProcess.js b/entity/Offer_entity/grantUpdateProcess.js
index dd8ad2ced3..1677ad01a5 100644
--- a/entity/Offer_entity/grantUpdateProcess.js
+++ b/entity/Offer_entity/grantUpdateProcess.js
@@ -7,8 +7,6 @@ import("KeywordRegistry_basic");
 // using the grant update would also disable the status field.
 
 var status = vars.get("$field.STATUS");
-var editable = status != $KeywordRegistry.offerStatus$sent()
-    && status != $KeywordRegistry.offerStatus$won()
-    && status != $KeywordRegistry.offerStatus$lost();
+var editable = status != $KeywordRegistry.offerStatus$won() && status != $KeywordRegistry.offerStatus$lost();
 
 result.string(editable || tools.hasRole(vars.get("$sys.user"), "INTERNAL_ADMINISTRATOR"));
-- 
GitLab