IDEMPIERE-417 - Update BPLocation.Name
This commit is contained in:
parent
e251dbbc26
commit
af759b7134
|
@ -20,18 +20,18 @@ import java.sql.ResultSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Partner Location Model
|
* Partner Location Model
|
||||||
*
|
*
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
* @version $Id: MBPartnerLocation.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
* @version $Id: MBPartnerLocation.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
||||||
* @author Teo Sarca, www.arhipac.ro
|
* @author Teo Sarca, www.arhipac.ro <li>FR [ 2788465 ]
|
||||||
* <li>FR [ 2788465 ] MBPartnerLocation.getForBPartner method add trxName
|
* MBPartnerLocation.getForBPartner method add trxName
|
||||||
* https://sourceforge.net/tracker/index.php?func=detail&aid=2788465&group_id=176962&atid=879335
|
* https://sourceforge
|
||||||
|
* .net/tracker/index.php?func=detail&aid=2788465&group_id
|
||||||
|
* =176962&atid=879335
|
||||||
*/
|
*/
|
||||||
public class MBPartnerLocation extends X_C_BPartner_Location
|
public class MBPartnerLocation extends X_C_BPartner_Location {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -39,148 +39,216 @@ public class MBPartnerLocation extends X_C_BPartner_Location
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Locations for BPartner
|
* Get Locations for BPartner
|
||||||
* @param ctx context
|
*
|
||||||
* @param C_BPartner_ID bp
|
* @param ctx
|
||||||
|
* context
|
||||||
|
* @param C_BPartner_ID
|
||||||
|
* bp
|
||||||
* @return array of locations
|
* @return array of locations
|
||||||
* @deprecated Since 3.5.3a. Please use {@link #getForBPartner(Properties, int, String)}.
|
* @deprecated Since 3.5.3a. Please use
|
||||||
|
* {@link #getForBPartner(Properties, int, String)}.
|
||||||
*/
|
*/
|
||||||
public static MBPartnerLocation[] getForBPartner (Properties ctx, int C_BPartner_ID)
|
public static MBPartnerLocation[] getForBPartner(Properties ctx,
|
||||||
{
|
int C_BPartner_ID) {
|
||||||
return getForBPartner(ctx, C_BPartner_ID, null);
|
return getForBPartner(ctx, C_BPartner_ID, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Locations for BPartner
|
* Get Locations for BPartner
|
||||||
* @param ctx context
|
*
|
||||||
* @param C_BPartner_ID bp
|
* @param ctx
|
||||||
|
* context
|
||||||
|
* @param C_BPartner_ID
|
||||||
|
* bp
|
||||||
* @param trxName
|
* @param trxName
|
||||||
* @return array of locations
|
* @return array of locations
|
||||||
*/
|
*/
|
||||||
public static MBPartnerLocation[] getForBPartner (Properties ctx, int C_BPartner_ID, String trxName)
|
public static MBPartnerLocation[] getForBPartner(Properties ctx,
|
||||||
{
|
int C_BPartner_ID, String trxName) {
|
||||||
List<MBPartnerLocation> list = new Query(ctx, Table_Name, "C_BPartner_ID=?", trxName)
|
List<MBPartnerLocation> list = new Query(ctx, Table_Name,
|
||||||
.setParameters(C_BPartner_ID)
|
"C_BPartner_ID=?", trxName).setParameters(C_BPartner_ID).list();
|
||||||
.list();
|
MBPartnerLocation[] retValue = new MBPartnerLocation[list.size()];
|
||||||
MBPartnerLocation[] retValue = new MBPartnerLocation[list.size ()];
|
list.toArray(retValue);
|
||||||
list.toArray (retValue);
|
|
||||||
return retValue;
|
return retValue;
|
||||||
} // getForBPartner
|
} // getForBPartner
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param ctx context
|
*
|
||||||
* @param C_BPartner_Location_ID id
|
* @param ctx
|
||||||
* @param trxName transaction
|
* context
|
||||||
|
* @param C_BPartner_Location_ID
|
||||||
|
* id
|
||||||
|
* @param trxName
|
||||||
|
* transaction
|
||||||
*/
|
*/
|
||||||
public MBPartnerLocation (Properties ctx, int C_BPartner_Location_ID, String trxName)
|
public MBPartnerLocation(Properties ctx, int C_BPartner_Location_ID,
|
||||||
{
|
String trxName) {
|
||||||
super (ctx, C_BPartner_Location_ID, trxName);
|
super(ctx, C_BPartner_Location_ID, trxName);
|
||||||
if (C_BPartner_Location_ID == 0)
|
if (C_BPartner_Location_ID == 0) {
|
||||||
{
|
setName(".");
|
||||||
setName (".");
|
|
||||||
//
|
//
|
||||||
setIsShipTo (true);
|
setIsShipTo(true);
|
||||||
setIsRemitTo (true);
|
setIsRemitTo(true);
|
||||||
setIsPayFrom (true);
|
setIsPayFrom(true);
|
||||||
setIsBillTo (true);
|
setIsBillTo(true);
|
||||||
}
|
}
|
||||||
} // MBPartner_Location
|
} // MBPartner_Location
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BP Parent Constructor
|
* BP Parent Constructor
|
||||||
* @param bp partner
|
*
|
||||||
|
* @param bp
|
||||||
|
* partner
|
||||||
*/
|
*/
|
||||||
public MBPartnerLocation (MBPartner bp)
|
public MBPartnerLocation(MBPartner bp) {
|
||||||
{
|
this(bp.getCtx(), 0, bp.get_TrxName());
|
||||||
this (bp.getCtx(), 0, bp.get_TrxName());
|
|
||||||
setClientOrg(bp);
|
setClientOrg(bp);
|
||||||
// may (still) be 0
|
// may (still) be 0
|
||||||
set_ValueNoCheck ("C_BPartner_ID", new Integer(bp.getC_BPartner_ID()));
|
set_ValueNoCheck("C_BPartner_ID", new Integer(bp.getC_BPartner_ID()));
|
||||||
} // MBPartner_Location
|
} // MBPartner_Location
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor from ResultSet row
|
* Constructor from ResultSet row
|
||||||
* @param ctx context
|
*
|
||||||
* @param rs current row of result set to be loaded
|
* @param ctx
|
||||||
* @param trxName transaction
|
* context
|
||||||
|
* @param rs
|
||||||
|
* current row of result set to be loaded
|
||||||
|
* @param trxName
|
||||||
|
* transaction
|
||||||
*/
|
*/
|
||||||
public MBPartnerLocation (Properties ctx, ResultSet rs, String trxName)
|
public MBPartnerLocation(Properties ctx, ResultSet rs, String trxName) {
|
||||||
{
|
|
||||||
super(ctx, rs, trxName);
|
super(ctx, rs, trxName);
|
||||||
} // MBPartner_Location
|
} // MBPartner_Location
|
||||||
|
|
||||||
|
/** Cached Location */
|
||||||
|
private MLocation m_location = null;
|
||||||
|
/** Unique Name */
|
||||||
|
private String m_uniqueName = null;
|
||||||
|
private int m_unique = 0;
|
||||||
|
|
||||||
/** Cached Location */
|
|
||||||
private MLocation m_location = null;
|
|
||||||
/** Unique Name */
|
|
||||||
private String m_uniqueName = null;
|
|
||||||
private int m_unique = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Location/Address
|
* Get Location/Address
|
||||||
* @param requery requery
|
*
|
||||||
* @return location
|
* @param requery
|
||||||
|
* requery
|
||||||
|
* @return location
|
||||||
*/
|
*/
|
||||||
public MLocation getLocation (boolean requery)
|
public MLocation getLocation(boolean requery) {
|
||||||
{
|
|
||||||
if (m_location == null)
|
if (m_location == null)
|
||||||
m_location = MLocation.get (getCtx(), getC_Location_ID(), get_TrxName());
|
m_location = MLocation.get(getCtx(), getC_Location_ID(),
|
||||||
|
get_TrxName());
|
||||||
return m_location;
|
return m_location;
|
||||||
} // getLoaction
|
} // getLoaction
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String Representation
|
* String Representation
|
||||||
* @return info
|
*
|
||||||
|
* @return info
|
||||||
*/
|
*/
|
||||||
public String toString ()
|
public String toString() {
|
||||||
{
|
StringBuffer sb = new StringBuffer("MBPartner_Location[ID=")
|
||||||
StringBuffer sb = new StringBuffer ("MBPartner_Location[ID=")
|
.append(get_ID()).append(",C_Location_ID=")
|
||||||
.append(get_ID())
|
.append(getC_Location_ID()).append(",Name=").append(getName())
|
||||||
.append(",C_Location_ID=").append(getC_Location_ID())
|
.append("]");
|
||||||
.append(",Name=").append(getName())
|
return sb.toString();
|
||||||
.append ("]");
|
} // toString
|
||||||
return sb.toString ();
|
|
||||||
} // toString
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Before Save.
|
* Before Save. - Set Name
|
||||||
* - Set Name
|
*
|
||||||
* @param newRecord new
|
* @param newRecord
|
||||||
* @return save
|
* new
|
||||||
|
* @return save
|
||||||
*/
|
*/
|
||||||
protected boolean beforeSave (boolean newRecord)
|
protected boolean beforeSave(boolean newRecord) {
|
||||||
{
|
|
||||||
if (getC_Location_ID() == 0)
|
if (getC_Location_ID() == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Set New Name
|
// Set New Name
|
||||||
if (!newRecord)
|
if (!newRecord)
|
||||||
return true;
|
return true;
|
||||||
MLocation address = getLocation(true);
|
MLocation address = getLocation(true);
|
||||||
|
setName(getBPLocName(address));
|
||||||
|
return true;
|
||||||
|
} // beforeSave
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make name Unique
|
||||||
|
*
|
||||||
|
* @param address
|
||||||
|
* address
|
||||||
|
*/
|
||||||
|
private void makeUnique(MLocation address) {
|
||||||
|
m_uniqueName = "";
|
||||||
|
|
||||||
|
// 0 - City
|
||||||
|
if (m_unique >= 0 || m_uniqueName.length() == 0) {
|
||||||
|
String xx = address.getCity();
|
||||||
|
if (xx != null && xx.length() > 0)
|
||||||
|
m_uniqueName = xx;
|
||||||
|
}
|
||||||
|
// 1 + Address1
|
||||||
|
if (m_unique >= 1 || m_uniqueName.length() == 0) {
|
||||||
|
String xx = address.getAddress1();
|
||||||
|
if (xx != null && xx.length() > 0) {
|
||||||
|
if (m_uniqueName.length() > 0)
|
||||||
|
m_uniqueName += " ";
|
||||||
|
m_uniqueName += xx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 2 + Address2
|
||||||
|
if (m_unique >= 2 || m_uniqueName.length() == 0) {
|
||||||
|
String xx = address.getAddress2();
|
||||||
|
if (xx != null && xx.length() > 0) {
|
||||||
|
if (m_uniqueName.length() > 0)
|
||||||
|
m_uniqueName += " ";
|
||||||
|
m_uniqueName += xx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 3 - Region
|
||||||
|
if (m_unique >= 3 || m_uniqueName.length() == 0) {
|
||||||
|
String xx = address.getRegionName(true);
|
||||||
|
if (xx != null && xx.length() > 0) {
|
||||||
|
if (m_uniqueName.length() > 0)
|
||||||
|
m_uniqueName += " ";
|
||||||
|
m_uniqueName += xx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 4 - ID
|
||||||
|
if (m_unique >= 4 || m_uniqueName.length() == 0) {
|
||||||
|
int id = get_ID();
|
||||||
|
if (id == 0)
|
||||||
|
id = address.get_ID();
|
||||||
|
m_uniqueName += "#" + id;
|
||||||
|
}
|
||||||
|
} // makeUnique
|
||||||
|
|
||||||
|
public String getBPLocName(MLocation address) {
|
||||||
m_uniqueName = getName();
|
m_uniqueName = getName();
|
||||||
m_unique = MSysConfig.getIntValue(MSysConfig.START_VALUE_BPLOCATION_NAME, 0, getAD_Client_ID(), getAD_Org_ID());
|
m_unique = MSysConfig.getIntValue("START_VALUE_BPLOCATION_NAME", 0,
|
||||||
|
getAD_Client_ID(), getAD_Org_ID());
|
||||||
if (m_unique < 0 || m_unique > 4)
|
if (m_unique < 0 || m_unique > 4)
|
||||||
m_unique = 0;
|
m_unique = 0;
|
||||||
if (m_uniqueName != null && m_uniqueName.equals(".")) {
|
if (m_uniqueName != null) { // && m_uniqueName.equals(".")) {
|
||||||
// default
|
// default
|
||||||
m_uniqueName = null;
|
m_uniqueName = null;
|
||||||
makeUnique(address);
|
makeUnique(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check uniqueness
|
// Check uniqueness
|
||||||
MBPartnerLocation[] locations = getForBPartner(getCtx(), getC_BPartner_ID());
|
MBPartnerLocation[] locations = getForBPartner(getCtx(),
|
||||||
|
getC_BPartner_ID());
|
||||||
boolean unique = locations.length == 0;
|
boolean unique = locations.length == 0;
|
||||||
while (!unique)
|
while (!unique) {
|
||||||
{
|
|
||||||
unique = true;
|
unique = true;
|
||||||
for (int i = 0; i < locations.length; i++)
|
for (int i = 0; i < locations.length; i++) {
|
||||||
{
|
|
||||||
MBPartnerLocation location = locations[i];
|
MBPartnerLocation location = locations[i];
|
||||||
if (location.getC_BPartner_Location_ID() == get_ID())
|
if (location.getC_BPartner_Location_ID() == get_ID())
|
||||||
continue;
|
continue;
|
||||||
if (m_uniqueName.equals(location.getName()))
|
if (m_uniqueName.equals(location.getName())) {
|
||||||
{
|
// m_uniqueName = null;
|
||||||
//m_uniqueName = null;
|
|
||||||
m_unique++;
|
m_unique++;
|
||||||
makeUnique(address);
|
makeUnique(address);
|
||||||
unique = false;
|
unique = false;
|
||||||
|
@ -188,67 +256,7 @@ public class MBPartnerLocation extends X_C_BPartner_Location
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setName (m_uniqueName);
|
return m_uniqueName;
|
||||||
return true;
|
}
|
||||||
} // beforeSave
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make name Unique
|
|
||||||
* @param address address
|
|
||||||
*/
|
|
||||||
private void makeUnique (MLocation address)
|
|
||||||
{
|
|
||||||
|
|
||||||
m_uniqueName = "";
|
|
||||||
|
|
||||||
// 0 - City
|
} // MBPartnerLocation
|
||||||
if (m_unique >= 0 || m_uniqueName.length() == 0)
|
|
||||||
{
|
|
||||||
String xx = address.getCity();
|
|
||||||
if (xx != null && xx.length() > 0)
|
|
||||||
m_uniqueName = xx;
|
|
||||||
}
|
|
||||||
// 1 + Address1
|
|
||||||
if (m_unique >= 1 || m_uniqueName.length() == 0)
|
|
||||||
{
|
|
||||||
String xx = address.getAddress1();
|
|
||||||
if (xx != null && xx.length() > 0)
|
|
||||||
{
|
|
||||||
if (m_uniqueName.length() > 0)
|
|
||||||
m_uniqueName += " ";
|
|
||||||
m_uniqueName += xx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 2 + Address2
|
|
||||||
if (m_unique >= 2 || m_uniqueName.length() == 0)
|
|
||||||
{
|
|
||||||
String xx = address.getAddress2();
|
|
||||||
if (xx != null && xx.length() > 0)
|
|
||||||
{
|
|
||||||
if (m_uniqueName.length() > 0)
|
|
||||||
m_uniqueName += " ";
|
|
||||||
m_uniqueName += xx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 3 - Region
|
|
||||||
if (m_unique >= 3 || m_uniqueName.length() == 0)
|
|
||||||
{
|
|
||||||
String xx = address.getRegionName(true);
|
|
||||||
if (xx != null && xx.length() > 0)
|
|
||||||
{
|
|
||||||
if (m_uniqueName.length() > 0)
|
|
||||||
m_uniqueName += " ";
|
|
||||||
m_uniqueName += xx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 4 - ID
|
|
||||||
if (m_unique >= 4 || m_uniqueName.length() == 0)
|
|
||||||
{
|
|
||||||
int id = get_ID();
|
|
||||||
if (id == 0)
|
|
||||||
id = address.get_ID();
|
|
||||||
m_uniqueName += "#" + id;
|
|
||||||
}
|
|
||||||
} // makeUnique
|
|
||||||
|
|
||||||
} // MBPartnerLocation
|
|
||||||
|
|
|
@ -654,6 +654,15 @@ public class MLocation extends X_C_Location implements Comparator<Object>
|
||||||
MAccount.updateValueDescription(getCtx(),
|
MAccount.updateValueDescription(getCtx(),
|
||||||
"(C_LocFrom_ID=" + getC_Location_ID()
|
"(C_LocFrom_ID=" + getC_Location_ID()
|
||||||
+ " OR C_LocTo_ID=" + getC_Location_ID() + ")", get_TrxName());
|
+ " OR C_LocTo_ID=" + getC_Location_ID() + ")", get_TrxName());
|
||||||
|
|
||||||
|
//Update BP_Location name IDEMPIERE 417
|
||||||
|
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();
|
||||||
|
}
|
||||||
return success;
|
return success;
|
||||||
} // afterSave
|
} // afterSave
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue