details: /erp/stable/2.50/rev/f9633ac9ea18
changeset: 9115:f9633ac9ea18
user: Mikel Irurita <mikel.irurita <at> openbravo.com>
date: Thu Dec 30 12:27:15 2010 +0100
summary: Fixes issue 15549: Payment Method combo should show only valid
methods
diffstat:
src-db/database/sourcedata/AD_COLUMN.xml | 1 +
src-db/database/sourcedata/AD_MESSAGE.xml | 11 +
src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_BPartner.java | 125
+++++++++-
3 files changed, 131 insertions(+), 6 deletions(-)
diffs (203 lines):
diff -r 98658fe1c111 -r f9633ac9ea18 src-db/database/sourcedata/AD_COLUMN.xml
--- a/src-db/database/sourcedata/AD_COLUMN.xml Thu Dec 23 16:16:52 2010 +0100
+++ b/src-db/database/sourcedata/AD_COLUMN.xml Thu Dec 30 12:27:15 2010 +0100
@@ -301237,6 +301237,7 @@
<!--828EE0AE80385FA1E040007F010067C7-->
<ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
<!--828EE0AE80385FA1E040007F010067C7-->
<ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
<!--828EE0AE80385FA1E040007F010067C7-->
<ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--828EE0AE80385FA1E040007F010067C7-->
<AD_CALLOUT_ID><![CDATA[105]]></AD_CALLOUT_ID>
<!--828EE0AE80385FA1E040007F010067C7-->
<DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
<!--828EE0AE80385FA1E040007F010067C7-->
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
<!--828EE0AE80385FA1E040007F010067C7--> <POSITION><![CDATA[61]]></POSITION>
diff -r 98658fe1c111 -r f9633ac9ea18 src-db/database/sourcedata/AD_MESSAGE.xml
--- a/src-db/database/sourcedata/AD_MESSAGE.xml Thu Dec 23 16:16:52 2010 +0100
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml Thu Dec 30 12:27:15 2010 +0100
@@ -32871,6 +32871,17 @@
<!--B4E8FD43A0534971B7453E6A7036AE01-->
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
<!--B4E8FD43A0534971B7453E6A7036AE01--></AD_MESSAGE>
+<!--B506C3346CDB44EEB33592003DCA14B2--><AD_MESSAGE>
+<!--B506C3346CDB44EEB33592003DCA14B2-->
<AD_MESSAGE_ID><![CDATA[B506C3346CDB44EEB33592003DCA14B2]]></AD_MESSAGE_ID>
+<!--B506C3346CDB44EEB33592003DCA14B2-->
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--B506C3346CDB44EEB33592003DCA14B2--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--B506C3346CDB44EEB33592003DCA14B2--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--B506C3346CDB44EEB33592003DCA14B2-->
<VALUE><![CDATA[PaymentmethodNotbelongsFinAccount]]></VALUE>
+<!--B506C3346CDB44EEB33592003DCA14B2--> <MSGTEXT><![CDATA[Automatic actions
could not be performed: selected payment method does not belong to the business
partner default financial account.]]></MSGTEXT>
+<!--B506C3346CDB44EEB33592003DCA14B2--> <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--B506C3346CDB44EEB33592003DCA14B2-->
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--B506C3346CDB44EEB33592003DCA14B2--></AD_MESSAGE>
+
<!--B53AA01A4CF8477FA1B7EEFBF8E9AAFB--><AD_MESSAGE>
<!--B53AA01A4CF8477FA1B7EEFBF8E9AAFB-->
<AD_MESSAGE_ID><![CDATA[B53AA01A4CF8477FA1B7EEFBF8E9AAFB]]></AD_MESSAGE_ID>
<!--B53AA01A4CF8477FA1B7EEFBF8E9AAFB-->
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r 98658fe1c111 -r f9633ac9ea18
src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_BPartner.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_BPartner.java Thu Dec
23 16:16:52 2010 +0100
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_BPartner.java Thu Dec
30 12:27:15 2010 +0100
@@ -27,12 +27,23 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.hibernate.criterion.Expression;
import org.openbravo.base.secureApp.HttpSecureAppServlet;
import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
import org.openbravo.data.FieldProvider;
import org.openbravo.erpCommon.businessUtility.BpartnerMiscData;
+import org.openbravo.erpCommon.businessUtility.Preferences;
import org.openbravo.erpCommon.utility.ComboTableData;
+import org.openbravo.erpCommon.utility.PropertyException;
+import org.openbravo.erpCommon.utility.PropertyNotFoundException;
import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
import org.openbravo.utils.FormatUtilities;
import org.openbravo.xmlEngine.XmlDocument;
@@ -59,10 +70,15 @@
String strProjectId = vars.getStringParameter("inpcProjectId");
String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx",
strWindowId);
String strTabId = vars.getStringParameter("inpTabId");
+ String strfinPaymentmethodId =
vars.getStringParameter("inpfinPaymentmethodId");
try {
- printPage(response, vars, strBPartner, strDocType, strIsSOTrx,
strWindowId, strLocation,
- strContact, strProjectId, strTabId);
+ if ("inpfinPaymentmethodId".equals(strChanged)) { // Payment Method
changed
+ printPagePaymentMethod(response, vars, strBPartner, strIsSOTrx,
strfinPaymentmethodId);
+ } else {
+ printPage(response, vars, strBPartner, strDocType, strIsSOTrx,
strWindowId, strLocation,
+ strContact, strProjectId, strTabId);
+ }
} catch (ServletException ex) {
pageErrorCallOut(response);
}
@@ -104,9 +120,7 @@
resultado.append("new Array(\"inppaymentrule\", \"" + strPaymentRule +
"\"),");
String strFinPaymentMethodId = (strIsSOTrx.equals("Y") ?
data[0].finPaymentmethodId
: data[0].poPaymentmethodId);
- if (!"".equals(strFinPaymentMethodId))
- resultado
- .append("new Array(\"inpfinPaymentmethodId\", \"" +
strFinPaymentMethodId + "\"),");
+ resultado.append("new Array(\"inpfinPaymentmethodId\", \"" +
strFinPaymentMethodId + "\"),");
String PaymentTerm = (strIsSOTrx.equals("Y") ? data[0].cPaymenttermId
: data[0].poPaymenttermId);
resultado.append("new Array(\"inpcPaymenttermId\", \"" + PaymentTerm +
"\"),");
@@ -227,9 +241,13 @@
&& new
BigDecimal(data[0].creditavailable).compareTo(BigDecimal.ZERO) < 0
&& strIsSOTrx.equals("Y")) {
String creditLimitExceed = "" +
Double.parseDouble(data[0].creditavailable) * -1;
+ String automationPaymentMethod = isAutomaticCombination(vars,
strBPartner, strIsSOTrx,
+ strFinPaymentMethodId);
resultado.append(", new Array('MESSAGE', \""
+ Utility.messageBD(this, "CreditLimitOver", vars.getLanguage()) +
creditLimitExceed
- + "\")");
+ + "<br/>" + automationPaymentMethod + "\")");
+ } else if (strIsSOTrx.equals("Y")) {
+ resultado.append(", new Array('MESSAGE', \"\")");
}
resultado.append(");");
}
@@ -240,4 +258,99 @@
out.println(xmlDocument.print());
out.close();
}
+
+ private void printPagePaymentMethod(HttpServletResponse response,
VariablesSecureApp vars,
+ String strBPartnerId, String strIsSOTrx, String strfinPaymentmethodId)
throws IOException,
+ ServletException {
+ XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
+ "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+ StringBuilder result = new StringBuilder();
+
+ String message = isAutomaticCombination(vars, strBPartnerId, strIsSOTrx,
strfinPaymentmethodId);
+
+ result.append("var calloutName='SE_Invoice_BPartner';\n\n");
+ result.append("var respuesta = new Array(new Array(\"MESSAGE\", ");
+ result.append("\"" + message + "\"));");
+
+ xmlDocument.setParameter("array", result.toString());
+ xmlDocument.setParameter("frameName", "appFrame");
+ response.setContentType("text/html; charset=UTF-8");
+ PrintWriter out = response.getWriter();
+ out.println(xmlDocument.print());
+ out.close();
+ }
+
+ /**
+ * Verifies if the given payment method belongs to the default financial
account of the given
+ * business partner.
+ *
+ * @param vars
+ * VariablesSecureApp.
+ * @param strBPartnerId
+ * Business Partner id.
+ * @param strIsSOTrx
+ * Sales ('Y') or purchase ('N') transaction.
+ * @param strfinPaymentmethodId
+ * Payment Method id.
+ * @return Message to be displayed in the application warning the user that
automatic actions
+ * could not be performed because given payment method does not
belong to the default
+ * financial account of the given business partner.
+ */
+ private String isAutomaticCombination(VariablesSecureApp vars, String
strBPartnerId,
+ String strIsSOTrx, String strfinPaymentmethodId) {
+ BusinessPartner bpartner = OBDal.getInstance().get(BusinessPartner.class,
strBPartnerId);
+ FIN_PaymentMethod selectedPaymentMethod =
OBDal.getInstance().get(FIN_PaymentMethod.class,
+ strfinPaymentmethodId);
+ OBContext.setAdminMode(true);
+ try {
+ boolean isSales = "Y".equals(strIsSOTrx);
+ FIN_FinancialAccount account = null;
+ String message = "";
+
+ // Only applies if the APRM module is installed
+ if (isAlternativeFinancialFlow()) {
+ if (bpartner != null && selectedPaymentMethod != null) {
+ account = (isSales) ? bpartner.getAccount() :
bpartner.getPOFinancialAccount();
+ if (account != null) {
+ OBCriteria<FinAccPaymentMethod> obc =
OBDal.getInstance().createCriteria(
+ FinAccPaymentMethod.class);
+ obc.add(Expression.eq(FinAccPaymentMethod.PROPERTY_ACCOUNT,
account));
+ obc.add(Expression
+ .eq(FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD,
selectedPaymentMethod));
+ if (obc.list() == null || obc.list().size() == 0) {
+ message = Utility.messageBD(this,
"PaymentmethodNotbelongsFinAccount", vars
+ .getLanguage());
+ }
+ } else {
+ message = Utility.messageBD(this,
"PaymentmethodNotbelongsFinAccount", vars
+ .getLanguage());
+ }
+ }
+ }
+ return message;
+ } finally {
+ OBContext.restorePreviousMode();
+ }
+ }
+
+ /**
+ * Checks if the any module implements and alternative Financial Management
preference. It should
+ * be the Advanced Payables and Receivables module.
+ *
+ * @return true if any module implements and alternative Financial
Management preference.
+ */
+ private boolean isAlternativeFinancialFlow() {
+ try {
+ try {
+ Preferences.getPreferenceValue("FinancialManagement", true, null,
null, OBContext
+ .getOBContext().getUser(), null, null);
+ } catch (PropertyNotFoundException e) {
+ return false;
+ }
+ } catch (PropertyException e) {
+ return false;
+ }
+ return true;
+ }
+
}
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits