Skip to content

Commit

Permalink
#10789 Clone Product with M_Product_Acct records
Browse files Browse the repository at this point in the history
  • Loading branch information
BodorAnnamaria committed Mar 10, 2021
1 parent 6d5c215 commit 5d36704
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public List<CopyRecordSupportTableInfo> getSuggestedChildren(final PO po, final
}
}

private static final List<I_AD_Table> retrieveChildTablesForParentColumn(final String columnName)
private final List<I_AD_Table> retrieveChildTablesForParentColumn(final String columnName)
{
final String whereClause = " EXISTS (SELECT 1 FROM AD_Column c WHERE c.ColumnName = ? AND c.ad_table_id = ad_table.ad_table_id AND c.IsParent = 'Y')"
+ " AND NOT EXISTS (SELECT 1 FROM AD_Column c WHERE c.ColumnName = ? AND c.ad_table_id = ad_table.ad_table_id AND c.ColumnName = ?)"
Expand All @@ -332,7 +332,7 @@ private static final List<I_AD_Table> retrieveChildTablesForParentColumn(final S
* @param tableName
* @return true if the table can be copied
*/
private static final boolean isCopyTable(final String tableName)
protected boolean isCopyTable(final String tableName)
{
final String upperTableName = tableName.toUpperCase();
boolean isCopyTable = !upperTableName.endsWith("_ACCT") // acct table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,16 @@ protected boolean afterSave(boolean newRecord, boolean success)
// New - Acct, Tree, Old Costing
if (newRecord)
{
insert_Accounting(I_M_Product_Acct.Table_Name,
I_M_Product_Category_Acct.Table_Name,
"p.M_Product_Category_ID=" + getM_Product_Category_ID());
if (this.getDynAttribute(PO.DYNATTR_CopyRecordSupport) == null)
{
insert_Accounting(I_M_Product_Acct.Table_Name,
I_M_Product_Category_Acct.Table_Name,
"p.M_Product_Category_ID=" + getM_Product_Category_ID());
}
else
{
log.info("This M_Product is created via CopyRecordSupport; -> don't insert the default _acct records");
}
insert_Tree(X_AD_Tree.TREETYPE_Product);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package de.metas.product;

import java.util.List;

import com.google.common.collect.ImmutableList;
import org.adempiere.model.CopyRecordSupportTableInfo;
import org.adempiere.model.GeneralCopyRecordSupport;
import org.compiere.model.I_M_Product_Acct;
import org.compiere.model.I_M_Product_Allergen;
import org.compiere.model.I_M_Product_Nutrition;
import org.compiere.model.PO;

import com.google.common.collect.ImmutableList;
import java.util.List;

/*
* #%L
Expand Down Expand Up @@ -40,7 +40,14 @@ public List<CopyRecordSupportTableInfo> getSuggestedChildren(final PO po, final
return super.getSuggestedChildren(po, suggestedChildren)
.stream()
.filter(childTableInfo -> I_M_Product_Nutrition.Table_Name.equals(childTableInfo.getTableName())
|| I_M_Product_Allergen.Table_Name.equals(childTableInfo.getTableName()))
|| I_M_Product_Allergen.Table_Name.equals(childTableInfo.getTableName())
|| I_M_Product_Acct.Table_Name.equals(childTableInfo.getTableName()))
.collect(ImmutableList.toImmutableList());
}


protected boolean isCopyTable(final String tableName)
{
return tableName.equals("M_Product_Acct") || super.isCopyTable(tableName);
}
}

0 comments on commit 5d36704

Please sign in to comment.