IDEMPIERE-22 Import Inventory Costs not taking into account cost level / Thanks to David Peñuela
This commit is contained in:
parent
e565badf79
commit
655dec54b0
|
@ -22,6 +22,7 @@ import java.sql.ResultSet;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
import org.compiere.model.MAcctSchema;
|
import org.compiere.model.MAcctSchema;
|
||||||
import org.compiere.model.MAttributeSet;
|
import org.compiere.model.MAttributeSet;
|
||||||
import org.compiere.model.MAttributeSetInstance;
|
import org.compiere.model.MAttributeSetInstance;
|
||||||
|
@ -29,6 +30,7 @@ import org.compiere.model.MCost;
|
||||||
import org.compiere.model.MInventory;
|
import org.compiere.model.MInventory;
|
||||||
import org.compiere.model.MInventoryLine;
|
import org.compiere.model.MInventoryLine;
|
||||||
import org.compiere.model.MProduct;
|
import org.compiere.model.MProduct;
|
||||||
|
import org.compiere.model.MProductCategoryAcct;
|
||||||
import org.compiere.model.X_I_Inventory;
|
import org.compiere.model.X_I_Inventory;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.TimeUtil;
|
import org.compiere.util.TimeUtil;
|
||||||
|
@ -356,12 +358,12 @@ public class ImportInventory extends SvrProcess
|
||||||
x_isInternalUse = isInternalUse;
|
x_isInternalUse = isInternalUse;
|
||||||
noInsert++;
|
noInsert++;
|
||||||
}
|
}
|
||||||
|
MProduct product = MProduct.get(getCtx(), imp.getM_Product_ID());
|
||||||
// Line
|
// Line
|
||||||
int M_AttributeSetInstance_ID = 0;
|
int M_AttributeSetInstance_ID = 0;
|
||||||
if ((imp.getLot() != null && imp.getLot().length() > 0) || (imp.getSerNo() != null && imp.getSerNo().length() > 0))
|
if ((imp.getLot() != null && imp.getLot().length() > 0) || (imp.getSerNo() != null && imp.getSerNo().length() > 0))
|
||||||
{
|
{
|
||||||
MProduct product = MProduct.get(getCtx(), imp.getM_Product_ID());
|
|
||||||
if (product.isInstanceAttribute())
|
if (product.isInstanceAttribute())
|
||||||
{
|
{
|
||||||
MAttributeSet mas = product.getAttributeSet();
|
MAttributeSet mas = product.getAttributeSet();
|
||||||
|
@ -394,15 +396,28 @@ public class ImportInventory extends SvrProcess
|
||||||
noInsertLine++;
|
noInsertLine++;
|
||||||
//@Trifon update Product cost record if Update costing is enabled
|
//@Trifon update Product cost record if Update costing is enabled
|
||||||
if (p_UpdateCosting) {
|
if (p_UpdateCosting) {
|
||||||
MCost cost = MCost.get (MProduct.get(getCtx(), imp.getM_Product_ID()), /*M_AttributeSetInstance_ID*/ 0
|
String costingLevel = null;
|
||||||
, acctSchema, p_AD_OrgTrx_ID, p_M_CostElement_ID, get_TrxName());
|
if(product.getM_Product_Category_ID() > 0){
|
||||||
cost.setCurrentCostPrice( imp.getCurrentCostPrice() );
|
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(), product.getM_Product_Category_ID(), p_C_AcctSchema_ID, get_TrxName());
|
||||||
if (cost.save()) {
|
costingLevel = pca.getCostingLevel();
|
||||||
// nothing here.
|
if (costingLevel == null) {
|
||||||
} else {
|
costingLevel = acctSchema.getCostingLevel();
|
||||||
log.log(Level.SEVERE, "Cost not saved!");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int costOrgID = p_AD_OrgTrx_ID;
|
||||||
|
int costASI = line.getM_AttributeSetInstance_ID();
|
||||||
|
if (MAcctSchema.COSTINGLEVEL_Client.equals(costingLevel)){
|
||||||
|
costOrgID = 0;
|
||||||
|
costASI = 0;
|
||||||
|
} else if (MAcctSchema.COSTINGLEVEL_Organization.equals(costingLevel)) {
|
||||||
|
costASI = 0;
|
||||||
|
}
|
||||||
|
MCost cost = MCost.get (MProduct.get(getCtx(), imp.getM_Product_ID()), costASI
|
||||||
|
, acctSchema, costOrgID, p_M_CostElement_ID, get_TrxName());
|
||||||
|
cost.setCurrentCostPrice( imp.getCurrentCostPrice() );
|
||||||
|
cost.saveEx();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -412,7 +427,7 @@ public class ImportInventory extends SvrProcess
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, sql.toString(), e);
|
throw new AdempiereException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set Error to indicator to not imported
|
// Set Error to indicator to not imported
|
||||||
|
|
Loading…
Reference in New Issue