Fixes Issue 22685. When creating a Payment against an Invoice
authorDavid Miguelez <david.miguelez@openbravo.com>
Thu, 31 Jan 2013 18:48:18 +0100
changeset 19538 d1469d10c70a
parent 19537 42aac1ca959c
child 19539 f16520f2d3f1
Fixes Issue 22685. When creating a Payment against an Invoice
sets the Currency correctly.
Plus, added a restriction. Is not possible to change a Price List
of a Business Partner that has generated credit into one with
a different Currency of the credit generated.
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/ProcessInvoice.java
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	Thu Jan 31 18:16:22 2013 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/ProcessInvoice.java	Thu Jan 31 18:48:18 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/triggers/C_BPARTNER_TRG.xml	Thu Jan 31 18:16:22 2013 +0100
+++ b/src-db/database/model/triggers/C_BPARTNER_TRG.xml	Thu Jan 31 18:48:18 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	Thu Jan 31 18:16:22 2013 +0100
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Jan 31 18:48:18 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>