Skip to content

Commit

Permalink
Correct Lot Behavior When Inactive and Several Companies
Browse files Browse the repository at this point in the history
Pull Request: #3995
Tested and accepted by Mario Calderon (marcalwestf, mariocalderon007@gmail.com)
  • Loading branch information
marcalwestf committed Oct 13, 2022
2 parents 5381e3e + fd58923 commit 0e9dc5a
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 287 deletions.
21 changes: 21 additions & 0 deletions base/src/org/compiere/model/MLot.java
Expand Up @@ -46,6 +46,27 @@ public class MLot extends X_M_Lot
/** Logger */
private static CLogger s_log = CLogger.getCLogger(MLot.class);

/**
* Get By Attribute Set Id
* @param ctx
* @param attributeSetId
* @param trxName
* @return
*/
public static List<MLot> getByAttributeSetId(Properties ctx , int attributeSetId, String trxName) {
StringBuilder whereClause = new StringBuilder();
ArrayList<Object> parameters = new ArrayList<>();
if (attributeSetId > 0 ) {
whereClause.append("M_Product_ID IN (SELECT M_Product_ID FROM M_Product WHERE M_AttributeSet_ID=? )");
parameters.add(attributeSetId);
}
return new Query(ctx, Table_Name, whereClause.toString(), trxName)
.setClient_ID()
.setOnlyActiveRecords(true)
.setParameters(parameters)
.setOrderBy("Name")
.list();
}
/**
* Get Lots for Product
* @param ctx context
Expand Down
42 changes: 9 additions & 33 deletions client/src/org/compiere/apps/search/InfoPAttribute.java
Expand Up @@ -25,7 +25,9 @@
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.stream.Collectors;

import javax.swing.Box;
import javax.swing.JDialog;
Expand All @@ -42,6 +44,7 @@
import org.compiere.grid.ed.VString;
import org.compiere.model.MAttribute;
import org.compiere.model.MAttributeSet;
import org.compiere.model.MLot;
import org.compiere.model.MRole;
import org.compiere.swing.CDialog;
import org.compiere.swing.CLabel;
Expand All @@ -63,7 +66,7 @@
* <li>ADEMPIERE-72 VLookup and Info Window improvements
* https://adempiere.atlassian.net/browse/ADEMPIERE-72
*/
public class InfoPAttribute extends CDialog
public class InfoPAttribute extends CDialog
{
/**
*
Expand Down Expand Up @@ -351,38 +354,11 @@ private KeyNamePair[] getAttributeList(int M_Attribute_ID)
*/
private void initLotSelection()
{
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
list.add(new KeyNamePair(-1, ""));

String whereAttributeSet;
if (p_M_AttributeSet_ID > 0)
whereAttributeSet = "AND M_Product_ID IN (SELECT M_Product_ID FROM M_Product WHERE M_AttributeSet_ID="+p_M_AttributeSet_ID+")";
else
whereAttributeSet = "";
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_Lot_ID, Name FROM M_Lot WHERE IsActive='Y' " + whereAttributeSet + " ORDER BY 2",
"M_Lot", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
while (rs.next())
list.add(new KeyNamePair(rs.getInt(1), rs.getString(2)));
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Create List
KeyNamePair[] items = new KeyNamePair[list.size()];
list.toArray(items);
lotSelection = new VComboBox(items);
List<KeyNamePair> keyNamePairLotList = MLot.getByAttributeSetId(Env.getCtx(), p_M_AttributeSet_ID, null)
.stream()
.map(lot -> new KeyNamePair(lot.getM_Lot_ID(), lot.getName()))
.collect(Collectors.toList());
lotSelection = new VComboBox(keyNamePairLotList.toArray());
} // initLotSelection


Expand Down

0 comments on commit 0e9dc5a

Please sign in to comment.