Attached Files | ModularizeDiscountsAndPromotions.diff [^] (9,521 bytes) 2014-11-13 17:01 [Show Content] [Hide Content]diff --git a/modules/org.openbravo.base.weld/src/META-INF/beans.xml b/modules/org.openbravo.base.weld/src/META-INF/beans.xml
--- a/modules/org.openbravo.base.weld/src/META-INF/beans.xml
+++ b/modules/org.openbravo.base.weld/src/META-INF/beans.xml
@@ -7,7 +7,12 @@
<weld:scan>
<weld:include name="**"/>
- <weld:exclude name="org.openbravo.erpCommon.**"/>
+ <weld:exclude name="org.openbravo.erpCommon.info.**"/>
+ <weld:exclude name="org.openbravo.erpCommon.modules.**"/>
+ <weld:exclude name="org.openbravo.erpCommon.obps.**"/>
+ <weld:exclude name="org.openbravo.erpCommon.reference.**"/>
+ <weld:exclude name="org.openbravo.erpCommon.security.**"/>
+ <weld:exclude name="org.openbravo.erpCommon.utility.**"/>
<weld:exclude name="org.openbravo.erpWindows.**"/>
<weld:exclude name="org.openbravo.base.exception.**"/>
<weld:exclude name="org.openbravo.base.expression.**"/>
@@ -20,7 +25,6 @@
<weld:exclude name="org.openbravo.base.util.**"/>
<weld:exclude name="org.openbravo.base.validation.**"/>
<weld:exclude name="org.openbravo.dal.**"/>
- <weld:exclude name="org.openbravo.erpCommon.**"/>
<weld:exclude name="org.openbravo.erpReports.**"/>
<weld:exclude name="org.openbravo.reference.**"/>
<weld:exclude name="org.openbravo.scheduling.**"/>
diff --git a/src-db/database/model/functions/M_PROMOTION_CALCULATE.xml b/src-db/database/model/functions/M_PROMOTION_CALCULATE.xml
--- a/src-db/database/model/functions/M_PROMOTION_CALCULATE.xml
+++ b/src-db/database/model/functions/M_PROMOTION_CALCULATE.xml
@@ -35,6 +35,7 @@
v_taxIncluded VARCHAR(1);
v_count NUMBER;
+ v_apply_discount NUMBER:= 1;
TYPE RECORD IS REF CURSOR;
Cur_Order RECORD;
@@ -315,10 +316,46 @@
M_OFFER_ID
)
loop
- if (v_apply_next = 'Y' AND Cur_Offer.PL_Order_Implementor is not null) then
- v_method := Cur_Offer.PL_Order_Implementor || '('''||p_type||''', '''||Cur_Offer.M_Offer_ID||''','''||Cur_Order.id||''', '||v_precision||', '|| v_stdprecision||', '''||p_user_id||''', '''||v_taxIncluded||''')';
- v_apply_next := AD_Execute_Function(v_method);
- end if;
+
+ --M_Promotions_Calculate - Extension Point to apply additional filters to discounts
+ SELECT count(*) INTO v_count
+ FROM DUAL
+ WHERE EXISTS (SELECT 1 FROM ad_ep_procedures WHERE ad_extension_points_id = 'F20050CAA4E1420B8766E1867F7D07CC');
+ IF (v_count=1) THEN
+ DECLARE
+ v_ep_instance VARCHAR2(32);
+ v_extension_point_id VARCHAR2(32) := 'F20050CAA4E1420B8766E1867F7D07CC';
+ v_Record_ID varchar(32) := Cur_Offer.M_Offer_ID; --OBTG:VARCHAR2--
+ v_Product_ID varchar(32) := Cur_Order.M_Product_ID; --OBTG:VARCHAR2--
+
+ BEGIN
+ v_ep_instance := get_uuid();
+
+ AD_EP_INSTANCE_PARA_INSERT(v_ep_instance, v_extension_point_id, 'Record_ID',
+ v_Record_ID, NULL, NULL, NULL, NULL, NULL, NULL);
+ AD_EP_INSTANCE_PARA_INSERT(v_ep_instance, v_extension_point_id, 'Product',
+ v_Product_ID, NULL, NULL, NULL, NULL, NULL, NULL);
+ AD_EP_INSTANCE_PARA_INSERT(v_ep_instance, v_extension_point_id, 'Result',
+ NULL, NULL, v_apply_discount, NULL, NULL, NULL, NULL);
+ AD_EXTENSION_POINT_HANDLER(v_ep_instance, v_extension_point_id);
+
+ SELECT p_number INTO v_apply_discount
+ FROM ad_ep_instance_para
+ WHERE ad_ep_instance_id = v_ep_instance
+ AND parametername LIKE 'Result';
+
+ DELETE FROM ad_ep_instance_para
+ WHERE ad_ep_instance_id = v_ep_instance;
+ END;
+ END IF;
+
+ IF v_apply_discount = 1 THEN
+ if (v_apply_next = 'Y' AND Cur_Offer.PL_Order_Implementor is not null) then
+ v_method := Cur_Offer.PL_Order_Implementor || '('''||p_type||''', '''||Cur_Offer.M_Offer_ID||''','''||Cur_Order.id||''', '||v_precision||', '|| v_stdprecision||', '''||p_user_id||''', '''||v_taxIncluded||''')';
+ v_apply_next := AD_Execute_Function(v_method);
+ end if;
+ END IF;
+ v_apply_discount :=1;
end loop;
end if;
end loop;
diff --git a/src-db/database/sourcedata/AD_EXTENSION_POINTS.xml b/src-db/database/sourcedata/AD_EXTENSION_POINTS.xml
--- a/src-db/database/sourcedata/AD_EXTENSION_POINTS.xml
+++ b/src-db/database/sourcedata/AD_EXTENSION_POINTS.xml
@@ -110,6 +110,16 @@
<!--CBE7DD2E561E4D3D8257ECEA5F19687F--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
<!--CBE7DD2E561E4D3D8257ECEA5F19687F--></AD_EXTENSION_POINTS>
+<!--F20050CAA4E1420B8766E1867F7D07CC--><AD_EXTENSION_POINTS>
+<!--F20050CAA4E1420B8766E1867F7D07CC--> <AD_EXTENSION_POINTS_ID><![CDATA[F20050CAA4E1420B8766E1867F7D07CC]]></AD_EXTENSION_POINTS_ID>
+<!--F20050CAA4E1420B8766E1867F7D07CC--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--F20050CAA4E1420B8766E1867F7D07CC--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--F20050CAA4E1420B8766E1867F7D07CC--> <NAME><![CDATA[M_Promotions_Calculate Extension point]]></NAME>
+<!--F20050CAA4E1420B8766E1867F7D07CC--> <DESCRIPTION><![CDATA[Extension Point added to the main loop of M_Promotions_Calculate to allow custom filters for discounts that apply on top of the standard filters]]></DESCRIPTION>
+<!--F20050CAA4E1420B8766E1867F7D07CC--> <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--F20050CAA4E1420B8766E1867F7D07CC--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--F20050CAA4E1420B8766E1867F7D07CC--></AD_EXTENSION_POINTS>
+
<!--FB653E9B971343B3989222ECD5B73A72--><AD_EXTENSION_POINTS>
<!--FB653E9B971343B3989222ECD5B73A72--> <AD_EXTENSION_POINTS_ID><![CDATA[FB653E9B971343B3989222ECD5B73A72]]></AD_EXTENSION_POINTS_ID>
<!--FB653E9B971343B3989222ECD5B73A72--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff --git a/src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java b/src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java
--- a/src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java
+++ b/src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java
@@ -20,10 +20,16 @@
import java.math.BigDecimal;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
import org.apache.log4j.Logger;
import org.openbravo.base.structure.BaseOBObject;
+import org.openbravo.base.weld.WeldUtils;
import org.openbravo.dal.service.OBDal;
import org.openbravo.dal.service.OBQuery;
import org.openbravo.model.common.currency.Currency;
@@ -43,6 +49,10 @@
public class PriceAdjustment {
private static final Logger log = Logger.getLogger(PriceAdjustment.class);
+ @Inject
+ @Any
+ private Instance<PriceAdjustmentHqlExtension> extensions;
+
/**
* Calculates price actual from price standard applying the Price Adjustments that fit the rules.
*
@@ -250,6 +260,17 @@
hql += " )) ";
hql += " ) ";
+ PriceAdjustment priceAdInstance = WeldUtils
+ .getInstanceFromStaticBeanManager(PriceAdjustment.class);
+
+ if (priceAdInstance.extensions != null) {
+ for (Iterator<? extends Object> extIter = priceAdInstance.extensions.iterator(); extIter
+ .hasNext();) {
+ PriceAdjustmentHqlExtension ext = (PriceAdjustmentHqlExtension) extIter.next();
+ hql += ext.getHQLStringExtension();
+ }
+ }
+
hql += " order by priority, id";
OBQuery<org.openbravo.model.pricing.priceadjustment.PriceAdjustment> q = OBDal.getInstance()
diff --git a/src/org/openbravo/erpCommon/businessUtility/PriceAdjustmentHqlExtension.java b/src/org/openbravo/erpCommon/businessUtility/PriceAdjustmentHqlExtension.java
new file mode 100644
--- /dev/null
+++ b/src/org/openbravo/erpCommon/businessUtility/PriceAdjustmentHqlExtension.java
@@ -0,0 +1,40 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):
+ *************************************************************************
+ */
+
+package org.openbravo.erpCommon.businessUtility;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * This class allows PriceAdjustment discounts to be extended from external modules and to be
+ * correctly calculated on the callouts that show the price before the booking process.
+ *
+ * @author aaroncalero
+ *
+ */
+
+@ApplicationScoped
+public abstract class PriceAdjustmentHqlExtension {
+
+ /**
+ * Returns a String that will be used to extend the hql query string of {@link PriceAdjustment}
+ *
+ */
+ public abstract String getHQLStringExtension();
+}
|