From f03a80f3e277e189f30c04994652d69d4581add9 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 16 Dec 2015 16:09:11 -0500 Subject: [PATCH] IDEMPIERE-2979 Only change BP Location name when a related field changes --- .../src/org/compiere/model/MLocation.java | 23 +++++++- .../webui/window/WLocationDialog.java | 59 ++++++++++++------- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MLocation.java b/org.adempiere.base/src/org/compiere/model/MLocation.java index f24c2c1bae..27b6683284 100644 --- a/org.adempiere.base/src/org/compiere/model/MLocation.java +++ b/org.adempiere.base/src/org/compiere/model/MLocation.java @@ -695,9 +695,26 @@ public class MLocation extends X_C_Location implements Comparator int bplID = DB.getSQLValueEx(get_TrxName(), "SELECT C_BPartner_Location_ID FROM C_BPartner_Location WHERE C_Location_ID = " + getC_Location_ID()); if (bplID>0) { - MBPartnerLocation bpl = new MBPartnerLocation(getCtx(), bplID, get_TrxName()); - bpl.setName(bpl.getBPLocName(this)); - bpl.saveEx(); + // just trigger BPLocation name change when the location change affects the name: + // START_VALUE_BPLOCATION_NAME + // 0 - City + // 1 - City + Address1 + // 2 - City + Address1 + Address2 + // 3 - City + Address1 + Address2 + Region + // 4 - City + Address1 + Address2 + Region + ID + int bplocname = MSysConfig.getIntValue(MSysConfig.START_VALUE_BPLOCATION_NAME, 0, getAD_Client_ID(), getAD_Org_ID()); + if (bplocname < 0 || bplocname > 4) + bplocname = 0; + if ( is_ValueChanged(COLUMNNAME_City) + || is_ValueChanged(COLUMNNAME_C_City_ID) + || (bplocname >= 1 && is_ValueChanged(COLUMNNAME_Address1)) + || (bplocname >= 2 && is_ValueChanged(COLUMNNAME_Address2)) + || (bplocname >= 3 && (is_ValueChanged(COLUMNNAME_RegionName) || is_ValueChanged(COLUMNNAME_C_Region_ID))) + ) { + MBPartnerLocation bpl = new MBPartnerLocation(getCtx(), bplID, get_TrxName()); + bpl.setName(bpl.getBPLocName(this)); + bpl.saveEx(); + } } } return success; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java index 6a183b586c..2c45e87558 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java @@ -941,30 +941,45 @@ public class WLocationDialog extends Window implements EventListener MAddressValidation validation = (MAddressValidation) lstAddressValidation.getSelectedItem().getValue(); m_location.setC_AddressValidation_ID(validation.getC_AddressValidation_ID()); } - + + boolean changedCity = m_location.is_ValueChanged(MLocation.COLUMNNAME_City) || m_location.is_ValueChanged(MLocation.COLUMNNAME_C_City_ID); + boolean changedAddress1 = m_location.is_ValueChanged(MLocation.COLUMNNAME_Address1); + boolean changedAddress2 = m_location.is_ValueChanged(MLocation.COLUMNNAME_Address2); + boolean changedRegion = m_location.is_ValueChanged(MLocation.COLUMNNAME_RegionName) || m_location.is_ValueChanged(MLocation.COLUMNNAME_C_Region_ID); // Save changes - boolean success = false; - if (m_location.save()) - { + boolean success = m_location.save(); + if (success) { // IDEMPIERE-417 Force Update BPLocation.Name - if (m_GridField != null && m_GridField.getGridTab() != null - && "C_BPartner_Location".equals(m_GridField.getGridTab().getTableName())) - { - m_GridField.getGridTab().setValue("Name", "."); - success = true; - } else { - //Update BP_Location name IDEMPIERE 417 - int bplID = DB.getSQLValueEx(trx.getTrxName(), "SELECT C_BPartner_Location_ID FROM C_BPartner_Location WHERE C_Location_ID = " + m_location.getC_Location_ID()); - if (bplID>0) - { - MBPartnerLocation bpl = new MBPartnerLocation(Env.getCtx(), bplID, trx.getTrxName()); - bpl.setName(bpl.getBPLocName(m_location)); - if (bpl.save()) - success = true; - } else { - success = true; - } - } + // just trigger BPLocation name change when the location change affects the name: + // START_VALUE_BPLOCATION_NAME + // 0 - City + // 1 - City + Address1 + // 2 - City + Address1 + Address2 + // 3 - City + Address1 + Address2 + Region + // 4 - City + Address1 + Address2 + Region + ID + int bplocname = MSysConfig.getIntValue(MSysConfig.START_VALUE_BPLOCATION_NAME, 0, m_location.getAD_Client_ID(), m_location.getAD_Org_ID()); + if (bplocname < 0 || bplocname > 4) + bplocname = 0; + if ( changedCity + || (bplocname >= 1 && changedAddress1) + || (bplocname >= 2 && changedAddress2) + || (bplocname >= 3 && changedRegion) + ) { + if ( m_GridField != null && m_GridField.getGridTab() != null + && "C_BPartner_Location".equals(m_GridField.getGridTab().getTableName())) + { + m_GridField.getGridTab().setValue("Name", "."); + } else { + //Update BP_Location name IDEMPIERE 417 + int bplID = DB.getSQLValueEx(trx.getTrxName(), "SELECT C_BPartner_Location_ID FROM C_BPartner_Location WHERE C_Location_ID = " + m_location.getC_Location_ID()); + if (bplID>0) + { + MBPartnerLocation bpl = new MBPartnerLocation(Env.getCtx(), bplID, trx.getTrxName()); + bpl.setName(bpl.getBPLocName(m_location)); + success = bpl.save(); + } + } + } } if (success) { trx.commit();