details: /erp/devel/pi/rev/5ef94bee291c
changeset: 7934:5ef94bee291c
user: Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date: Thu Jul 29 12:34:09 2010 +0200
summary: Fixes bug 0013776: Needed Alerts for Build validations if needed
diffstat:
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/Cbpvendoracct.class
| 0
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/CbpvendoracctData.class
| 0
src-util/buildvalidation/src/org/openbravo/buildvalidation/Cbpvendoracct.java
| 35 +++-
src-util/buildvalidation/src/org/openbravo/buildvalidation/Cbpvendoracct_data.xsql
| 99 ++++++++++
4 files changed, 133 insertions(+), 1 deletions(-)
diffs (175 lines):
diff -r acbf6d8e8822 -r 5ef94bee291c
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/Cbpvendoracct.class
Binary file
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/Cbpvendoracct.class
has changed
diff -r acbf6d8e8822 -r 5ef94bee291c
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/CbpvendoracctData.class
Binary file
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/CbpvendoracctData.class
has changed
diff -r acbf6d8e8822 -r 5ef94bee291c
src-util/buildvalidation/src/org/openbravo/buildvalidation/Cbpvendoracct.java
---
a/src-util/buildvalidation/src/org/openbravo/buildvalidation/Cbpvendoracct.java
Thu Jul 29 10:50:08 2010 +0200
+++
b/src-util/buildvalidation/src/org/openbravo/buildvalidation/Cbpvendoracct.java
Thu Jul 29 12:34:09 2010 +0200
@@ -23,6 +23,7 @@
import org.openbravo.database.ConnectionProvider;
+
/**
* This validation is related to this issue:
https://issues.openbravo.com/view.php?id=12824 The
* unique constraint C_BP_VENDOR_ACCT_ACCTSCHEMA_UN was made more restrictive,
and it will fail if
@@ -39,12 +40,44 @@
int b = Integer.parseInt(CbpvendoracctData.countDistinct(cp));
if (a != b) {
errors
- .add("Due to a database constraint modification, is no longer
allowed to have more than one entry in business partner -> vendor -> accounting
tab, for the same accounting schema and status. In previous releases, one per
organization was allowed, but is not the case now. There exists data in your
database that do not fit this new constraint. Please fix it before updating the
database.");
+ .add("You can not apply this MP because your instance fails in a
pre-validation: from Openbravo 2.50 MP18 it is not allowed to have more than
one entry in business partner -> vendor -> accounting tab with the same
accounting schema and status. Untill MP18 it was allowed although it was wrong
since the behaviour was unpredictable: any of the duplicated accounts could be
used for the accounting of that business partner. To fix this problem in your
instance, you can know the duplicated entries by reviewing Alerts in your
system (Alert Rule: Vendor Duplicate Accounts). Once you find the duplicated
entries you should remove the wrong ones. Once it is fixed you should be able
to apply this MP.");
+ String alertRuleId = CbpvendoracctData.getUUID(cp);
+ if (CbpvendoracctData.existsAlertRule(cp).equals("0")){
+ CbpvendoracctData.insertAlertRule(cp, alertRuleId);
+ processAlert(alertRuleId, cp);
+ }
}
} catch (Exception e) {
return handleError(e);
}
return errors;
}
+ /**
+ * @param alertRule
+ * @param conn
+ * @throws Exception
+ */
+ private void processAlert(String adAlertruleId, ConnectionProvider cp)
throws Exception {
+ CbpvendoracctData[] alertRule = CbpvendoracctData.select(cp,
adAlertruleId);
+ CbpvendoracctData[] alert = null;
+ if (!alertRule[0].sql.equals("")) {
+ try {
+ alert = CbpvendoracctData.selectAlert(cp, alertRule[0].sql);
+ } catch (Exception ex) {
+ return;
+ }
+ }
+ // Insert
+ if (alert != null && alert.length != 0) {
+ StringBuilder msg = new StringBuilder();
+ ;
+
+ for (int i = 0; i < alert.length; i++) {
+ if (CbpvendoracctData.existsReference(cp, adAlertruleId,
alert[i].referencekeyId).equals("0")) {
+ CbpvendoracctData.insertAlert(cp, alert[i].description,
alertRule[0].adAlertruleId, alert[i].recordId, alert[i].referencekeyId);
+ }
+ }
+ }
+ }
}
diff -r acbf6d8e8822 -r 5ef94bee291c
src-util/buildvalidation/src/org/openbravo/buildvalidation/Cbpvendoracct_data.xsql
---
a/src-util/buildvalidation/src/org/openbravo/buildvalidation/Cbpvendoracct_data.xsql
Thu Jul 29 10:50:08 2010 +0200
+++
b/src-util/buildvalidation/src/org/openbravo/buildvalidation/Cbpvendoracct_data.xsql
Thu Jul 29 12:34:09 2010 +0200
@@ -20,6 +20,56 @@
<SqlClass name="CbpvendoracctData" package="org.openbravo.buildvalidation">
+ <SqlMethod name="select" type="preparedStatement" return="multiple">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ SELECT AD_CLIENT_ID,
+ AD_ORG_ID,
+ CREATED,
+ CREATEDBY,
+ UPDATED,
+ UPDATEDBY,
+ ISACTIVE,
+ '' as RECORD_ID,
+ '' as DESCRIPTION,
+ '' as REFERENCEKEY_ID,
+ '' as AD_ROLE_ID,
+ AD_ALERTRULE_ID,
+ SQL,
+ NAME
+ FROM AD_ALERTRULE
+ WHERE AD_ALERTRULE_ID = ?
+ ]]></Sql>
+ <Parameter name="alertRule"/>
+ </SqlMethod>
+ <SqlMethod name="existsAlertRule" type="preparedStatement" return="string">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ SELECT COUNT(*) AS EXISTING
+ FROM AD_ALERTRULE
+ WHERE NAME LIKE 'Vendor Duplicate Accounts'
+ AND ISACTIVE = 'Y'
+ ]]></Sql>
+ </SqlMethod>
+ <SqlMethod name="existsReference" type="preparedStatement" return="string">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ SELECT COUNT(*) AS EXISTING
+ FROM AD_ALERT
+ WHERE AD_ALERTRULE_ID = ?
+ AND REFERENCEKEY_ID = ?
+ AND ISACTIVE = 'Y'
+ ]]></Sql>
+ <Parameter name="alertRule"/>
+ <Parameter name="ref"/>
+ </SqlMethod>
+ <SqlMethod name="getUUID" type="preparedStatement" return="string">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ SELECT get_uuid()
+ FROM dual
+ ]]></Sql>
+ </SqlMethod>
<SqlMethod name="countNoDistinct" type="preparedStatement" return="string">
<SqlMethodComment>This query counts the number of rows in
c_bp_vendor_acct</SqlMethodComment>
<Sql><![CDATA[
@@ -34,4 +84,53 @@
]]>
</Sql>
</SqlMethod>
+ <SqlMethod name="insertAlertRule" type="preparedStatement" return="rowcount">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ INSERT INTO AD_ALERTRULE (
+ AD_ALERTRULE_ID,
+ AD_CLIENT_ID ,
+ AD_ORG_ID ,
+ ISACTIVE ,
+ CREATED ,
+ CREATEDBY ,
+ UPDATED ,
+ UPDATEDBY ,
+ NAME ,
+ AD_TAB_ID ,
+ FILTERCLAUSE ,
+ SQL ,
+ TYPE
+ )
+ VALUES (?, '0', '0', 'Y', now(), '100', now(), '100', 'Vendor Duplicate
Accounts', '213', '',
+ 'select max(c_bp_vendor_acct_id) as referencekey_id,
ad_column_identifier(''C_BP_Vendor_Acct'',max(C_BP_Vendor_Acct_ID),''en_US'')
as record_id, 0 as ad_role_id, null as ad_user_id, ''Duplicated accounting
Configuration entry. Please ensure just one entry exists per accounting schema
and status for this business partner'' as description, ''Y'' as isActive,
max(ad_org_id), max(ad_client_id), now() as created, 0 as createdBy, now() as
updated, 0 as updatedBy from c_bp_vendor_acct p group by c_acctschema_id,
c_bpartner_id, status having count(c_bp_vendor_acct_id)>1'
+ , 'D')
+ ]]>
+ </Sql>
+ <Parameter name="alertRuleId"/>
+ </SqlMethod>
+ <SqlMethod name="insertAlert" type="preparedStatement"
+ return="rowcount">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql>
+ <![CDATA[
+ INSERT INTO AD_Alert (AD_Alert_ID, AD_Client_ID, AD_Org_ID, IsActive,
+ Created, CreatedBy, Updated, UpdatedBy, Description,
AD_AlertRule_ID, Record_Id, Referencekey_ID)
+ VALUES (get_uuid(), '0', '0', 'Y', NOW(), '0', NOW(), '0', ?,
?, ?, ?)
+ ]]>
+ </Sql>
+ <Parameter name="description" />
+ <Parameter name="adAlertRuleId" />
+ <Parameter name="recordId" />
+ <Parameter name="referencekey_id" />
+ </SqlMethod>
+
+ <SqlMethod name="selectAlert" type="preparedStatement" return="multiple">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ SELECT AAA.*
+ FROM (SELECT '' AS DESCRIPTION, '' AS RECORD_ID, '' AS
REFERENCEKEY_ID FROM DUAL) AAA
+ ]]></Sql>
+ <Parameter name="sql" type="replace" optional="true" after="FROM ("
text="SELECT '' AS DESCRIPTION, '' AS RECORD_ID, '' AS REFERENCEKEY_ID FROM
DUAL"/>
+ </SqlMethod>
</SqlClass>
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits