Fixes Issue 22916. Adds removed code.
authorDavid Miguelez <david.miguelez@openbravo.com>
Tue, 29 Jan 2013 18:02:20 +0100
changeset 19502 51b18ffbb897
parent 19501 81295cf8b1e8
child 19503 af634aae179d
Fixes Issue 22916. Adds removed code.
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/ProcessInvoice.java
src-db/database/model/functions/M_INOUT_CREATE.xml
src-db/database/model/triggers/C_BPARTNER_TRG.xml
src-db/database/sourcedata/AD_MESSAGE.xml
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/ProcessInvoice.java	Tue Jan 29 17:18:03 2013 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/ProcessInvoice.java	Tue Jan 29 18:02:20 2013 +0100
@@ -342,7 +342,7 @@
               docType, strPaymentDocumentNo, invoice.getBusinessPartner(),
               invoice.getPaymentMethod(), bpFinAccount, "0", FIN_Utility.getDate(strPaymentDate),
               invoice.getOrganization(), invoice.getDocumentNo(), paymentScheduleDetails,
-              paymentScheduleDetailsAmounts, false, false);
+              paymentScheduleDetailsAmounts, false, false, invoice.getCurrency(), null, null);
           newPayment.setAmount(BigDecimal.ZERO);
           newPayment.setGeneratedCredit(BigDecimal.ZERO);
           newPayment.setUsedCredit(totalUsedCreditAmt);
--- a/src-db/database/model/functions/M_INOUT_CREATE.xml	Tue Jan 29 17:18:03 2013 +0100
+++ b/src-db/database/model/functions/M_INOUT_CREATE.xml	Tue Jan 29 18:02:20 2013 +0100
@@ -66,6 +66,7 @@
   v_MessageBPB VARCHAR2(2000):='';
   result_String VARCHAR2(2000):='';
   v_ResultLinesStr VARCHAR2(2000):='';
+  v_stdPrecision NUMBER:=2;
   -- Parameter
   TYPE RECORD IS REF CURSOR;
     Cur_Parameter RECORD;
@@ -397,14 +398,15 @@
             --MODIFIED BY F.IRIAZABAL
             v_QtyOrder:=0;
             IF (ol.M_Product_UOM_ID IS NOT NULL) THEN
-              SELECT M_PRODUCT_UOM.C_UOM_ID INTO v_ProductUOM
+              SELECT M_PRODUCT_UOM.C_UOM_ID, C_UOM.stdprecision
+              INTO v_ProductUOM, v_stdPrecision
               FROM M_PRODUCT_UOM, C_UOM
               WHERE M_PRODUCT_UOM.C_UOM_ID=C_UOM.C_UOM_ID
                 AND M_Product_UOM_ID=ol.M_Product_UOM_ID;
               IF (ol.QtyDelivered = 0) THEN
                 v_QtyOrder:=ol.QuantityOrder;
               ELSIF (v_ProductUOM IS NOT NULL) THEN
-                v_QtyOrder:=ol.QuantityOrder*v_Qty/ol.QtyOrdered;
+                v_QtyOrder:=ROUND(ol.QuantityOrder*v_Qty/ol.QtyOrdered,v_stdPrecision);
                 --v_QtyOrder:=C_Uom_Convert(v_Qty, ol.C_UOM_ID, v_ProductUOM, 'Y') ;
               ELSE
                 v_QtyOrder:=NULL;
--- a/src-db/database/model/triggers/C_BPARTNER_TRG.xml	Tue Jan 29 17:18:03 2013 +0100
+++ b/src-db/database/model/triggers/C_BPARTNER_TRG.xml	Tue Jan 29 18:02:20 2013 +0100
@@ -46,6 +46,9 @@
   v_Sequence_No		            varchar2(32);
   v_C_AcctSchema_ID	          VARCHAR2(32);
   v_count 					  NUMBER;
+  v_currency_pl							VARCHAR2(32);
+  v_currency_credit					VARCHAR2(32);
+  v_currency_iso						VARCHAR2(32);
 BEGIN
     
     IF AD_isTriggerEnabled()='N' THEN RETURN;
@@ -241,6 +244,34 @@
      END LOOP;
 
   ELSIF (UPDATING) THEN
+  
+		 IF (:new.M_PRICELIST_ID <> :old.M_PRICELIST_ID) THEN
+		 -- When Updating the Price List, check if the Business Partner has already generated Credit
+		 -- In that case, do not allow to update to a Price List with a different Currency from the generated Credit.
+       SELECT c_currency_id
+       INTO v_currency_pl
+       FROM m_pricelist pl
+       JOIN c_currency USING (c_currency_id)
+       WHERE m_pricelist_id = :new.M_PRICELIST_ID;
+       
+     --Currency of the generated Credit not consumed yet.
+       SELECT MAX(p.c_currency_id)
+       INTO v_currency_credit
+       FROM fin_payment p
+       WHERE p.c_bpartner_id = :new.C_BPartner_ID
+       AND p.generated_credit <> 0
+       AND p.generated_credit-COALESCE(p.used_credit, 0) <> 0;
+      
+			 IF (v_currency_pl <> COALESCE(v_currency_credit, v_currency_pl)) THEN
+			   SELECT iso_code
+			   INTO v_currency_iso
+			   FROM c_currency
+			   WHERE c_currency_id = v_currency_credit;
+			   
+         RAISE_APPLICATION_ERROR(-20000, '@C_BPWithCreditPriceList@' || ' ' || v_currency_iso || '. ' || '@C_BPWithCreditPriceList2@');
+			 END IF;
+     END IF;
+
      UPDATE C_BP_CUSTOMER_ACCT SET AD_ORG_ID = :new.AD_Org_ID
      WHERE C_BPARTNER_ID = :new.C_BPartner_ID;
      UPDATE C_BP_VENDOR_ACCT SET AD_ORG_ID = :new.AD_Org_ID
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Jan 29 17:18:03 2013 +0100
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Jan 29 18:02:20 2013 +0100
@@ -15080,6 +15080,17 @@
 <!--157D9E4CAE3849F6949415E3425AEB30-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--157D9E4CAE3849F6949415E3425AEB30--></AD_MESSAGE>
 
+<!--15CDE4BE875A46608CEB541331D2CFE7--><AD_MESSAGE>
+<!--15CDE4BE875A46608CEB541331D2CFE7-->  <AD_MESSAGE_ID><![CDATA[15CDE4BE875A46608CEB541331D2CFE7]]></AD_MESSAGE_ID>
+<!--15CDE4BE875A46608CEB541331D2CFE7-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--15CDE4BE875A46608CEB541331D2CFE7-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--15CDE4BE875A46608CEB541331D2CFE7-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--15CDE4BE875A46608CEB541331D2CFE7-->  <VALUE><![CDATA[C_BPWithCreditPriceList2]]></VALUE>
+<!--15CDE4BE875A46608CEB541331D2CFE7-->  <MSGTEXT><![CDATA[ Only Price Lists with the same Currency can be selected.]]></MSGTEXT>
+<!--15CDE4BE875A46608CEB541331D2CFE7-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--15CDE4BE875A46608CEB541331D2CFE7-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--15CDE4BE875A46608CEB541331D2CFE7--></AD_MESSAGE>
+
 <!--164937FDAAF344F1A958007F98DD53FC--><AD_MESSAGE>
 <!--164937FDAAF344F1A958007F98DD53FC-->  <AD_MESSAGE_ID><![CDATA[164937FDAAF344F1A958007F98DD53FC]]></AD_MESSAGE_ID>
 <!--164937FDAAF344F1A958007F98DD53FC-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -17617,6 +17628,17 @@
 <!--643C242A10AE4A4495EA6D82B99C1F86-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--643C242A10AE4A4495EA6D82B99C1F86--></AD_MESSAGE>
 
+<!--66BEE4A0FBD44C96B2967716918A1318--><AD_MESSAGE>
+<!--66BEE4A0FBD44C96B2967716918A1318-->  <AD_MESSAGE_ID><![CDATA[66BEE4A0FBD44C96B2967716918A1318]]></AD_MESSAGE_ID>
+<!--66BEE4A0FBD44C96B2967716918A1318-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--66BEE4A0FBD44C96B2967716918A1318-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--66BEE4A0FBD44C96B2967716918A1318-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--66BEE4A0FBD44C96B2967716918A1318-->  <VALUE><![CDATA[C_BPWithCreditPriceList]]></VALUE>
+<!--66BEE4A0FBD44C96B2967716918A1318-->  <MSGTEXT><![CDATA[This Business Partner has already generated Credit in  ]]></MSGTEXT>
+<!--66BEE4A0FBD44C96B2967716918A1318-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--66BEE4A0FBD44C96B2967716918A1318-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--66BEE4A0FBD44C96B2967716918A1318--></AD_MESSAGE>
+
 <!--67178C115E364ED2B68EC84473CD7404--><AD_MESSAGE>
 <!--67178C115E364ED2B68EC84473CD7404-->  <AD_MESSAGE_ID><![CDATA[67178C115E364ED2B68EC84473CD7404]]></AD_MESSAGE_ID>
 <!--67178C115E364ED2B68EC84473CD7404-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>