use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class StorageEngine method createTrasaction.
public static void createTrasaction(IDocumentLine docLine, String MovementType, Timestamp MovementDate, BigDecimal Qty, boolean isReversal, int M_Warehouse_ID, int o_M_AttributeSetInstance_ID, int o_M_Warehouse_ID, boolean isSOTrx) {
MProduct product = MProduct.get(docLine.getCtx(), docLine.getM_Product_ID());
// Incoming Trx
// V+ Vendor Receipt
boolean incomingTrx = MovementType.charAt(1) == '+';
if (product != null && product.isStocked()) {
//Ignore the Material Policy when is Reverse Correction
if (!isReversal) {
checkMaterialPolicy(docLine, MovementType, MovementDate, M_Warehouse_ID);
}
// Reservation ASI
int reservationAttributeSetInstance_ID = o_M_AttributeSetInstance_ID;
//
if (docLine.getM_AttributeSetInstance_ID() == 0) {
IInventoryAllocation[] mas = StorageEngine.getMA(docLine);
for (int j = 0; j < mas.length; j++) {
IInventoryAllocation ma = mas[j];
BigDecimal QtyMA = ma.getMovementQty();
if (// C- Customer Shipment - V- Vendor Return
!incomingTrx)
QtyMA = QtyMA.negate();
// Update Storage - see also VMatch.createMatchRecord
if (!MStorage.add(docLine.getCtx(), M_Warehouse_ID, docLine.getM_Locator_ID(), docLine.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), reservationAttributeSetInstance_ID, QtyMA, Env.ZERO, Env.ZERO, docLine.get_TrxName())) {
//Cannot correct Inventory (MA)
throw new AdempiereException();
}
create(docLine, MovementType, MovementDate, ma.getM_AttributeSetInstance_ID(), QtyMA);
}
} else // sLine.getM_AttributeSetInstance_ID() != 0
//if (mtrx == null)
{
if (// C- Customer Shipment - V- Vendor Return
!incomingTrx)
Qty = Qty.negate();
// Fallback: Update Storage - see also VMatch.createMatchRecord
if (!MStorage.add(docLine.getCtx(), M_Warehouse_ID, docLine.getM_Locator_ID(), docLine.getM_Product_ID(), docLine.getM_AttributeSetInstance_ID(), reservationAttributeSetInstance_ID, Qty, Env.ZERO, Env.ZERO, docLine.get_TrxName())) {
//Cannot correct Inventory (MA)
throw new AdempiereException();
}
create(docLine, MovementType, MovementDate, docLine.getM_AttributeSetInstance_ID(), Qty);
}
}
// stock movement
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class FifoLifoCostingMethod method processCostDetail.
// need this for reversal documents
public void processCostDetail(MCostDetail costDetail) {
boolean addition = costDetail.getQty().signum() > 0;
MAcctSchema as = MAcctSchema.get(costDetail.getCtx(), costDetail.getC_AcctSchema_ID());
int precision = as.getCostingPrecision();
MProduct product = MProduct.get(costDetail.getCtx(), costDetail.getM_Product_ID());
BigDecimal price = costDetail.getAmt();
if (costDetail.getQty().signum() != 0)
price = costDetail.getAmt().divide(costDetail.getQty(), precision, BigDecimal.ROUND_HALF_UP);
int AD_Org_ID = costDetail.getAD_Org_ID();
int M_ASI_ID = costDetail.getM_AttributeSetInstance_ID();
if (costDetail.getC_OrderLine_ID() != 0 && !(model.getReversalLine_ID() > 0)) {
log.finer("Inv - FiFo/LiFo - amt=" + costDetail.getAmt() + ", qty=" + costDetail.getQty() + " [NOTHING TO DO]");
} else if (// AR Shipment Detail Record
costDetail.getM_InOutLine_ID() != 0 || costDetail.getM_MovementLine_ID() != 0 || costDetail.getM_InventoryLine_ID() != 0 || costDetail.getM_ProductionLine_ID() != 0 || costDetail.getC_ProjectIssue_ID() != 0 || costDetail.getPP_Cost_Collector_ID() != 0 || costDetail.getC_LandedCostAllocation_ID() != 0) {
if (addition) {
MCostQueue.add(product, M_ASI_ID, as, AD_Org_ID, costDetail.getM_CostElement_ID(), costDetail.getAmt(), costDetail.getQty(), precision, (MCostDetail) costDetail, costDetail.get_TrxName());
} else {
BigDecimal amtQueue = MCostQueue.adjustQty(dimension, costDetail.getQty().negate(), costDetail.getDateAcct(), costDetail.get_TrxName());
// outgoing amt should be negative
amtQueue = amtQueue.negate();
if (costDetail.getAmt().compareTo(amtQueue) != 0) {
BigDecimal priceQueue = Env.ZERO;
if (costDetail.getQty().signum() != 0)
priceQueue = amtQueue.divide(costDetail.getQty(), precision, BigDecimal.ROUND_HALF_UP);
log.warning("Amt not match " + this + ": price=" + price + ", priceQueue=" + priceQueue + " [ADJUSTED]");
// FIXME: teo_sarca: should not happen
if ("Y".equals(Env.getContext(costDetail.getCtx(), "#M_CostDetail_CorrectAmt"))) {
costDetail.setAmt(amtQueue);
costDetail.setAmt(amtQueue);
costDetail.setPrice(priceQueue);
} else {
throw new AdempiereException("Amt not match " + this + ": price=" + price + ", priceQueue=" + priceQueue);
}
}
}
costDetail.setCumulatedQty(dimension.getCumulatedQty());
costDetail.setCumulatedAmt(dimension.getCumulatedQty());
costDetail.setCumulatedAmtLL(getNewAccumulatedAmountLowerLevel(lastCostDetail));
costDetail.setCurrentCostPrice(dimension.getCurrentCostPrice());
updateCurrentCost(costDetail);
costDetail.saveEx();
this.costDetail = costDetail;
}
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class FifoLifoCostingMethod method adjustementQueue.
public void adjustementQueue(MCostDetail costDetail) {
final List<MCostDetail> cds;
if (costDetail.getCostAdjustmentDate() != null) {
cds = MCostDetail.getAfterDate(costDetail, costingLevel);
} else
cds = MCostDetail.getAfterDate(costDetail, costingLevel);
List<Object> list = new ArrayList<Object>();
for (MCostDetail cd : cds) {
if (cd == null)
throw new AdempiereException("Error do not exist adjustment");
MCostQueue cq = MCostQueue.getQueueForAdjustment(cd, dimension, model.get_TrxName());
MTransaction trx = get(cd);
//second condition - delayed transaction
if ((!(cq.getCurrentQty().compareTo(Env.ZERO) == 0) && (trx.getMovementType().equals("C-") || trx.getMovementType().equals("I+") || trx.getMovementType().equals("I-")) && cd.getCostAdjustmentDate() != null) || ((trx.getMovementType().equals("C-") || trx.getMovementType().equals("I+") || trx.getMovementType().equals("I-")) && transaction.getMovementType().endsWith("+"))) {
cq.addCurrentQty(cd.getQty().negate());
cq.saveEx();
cd.setProcessed(false);
cd.setAmt(cd.getQty().multiply(costThisLevel.add(costLowLevel)));
cd.saveEx();
list.add(cd);
} else if (trx.getMovementType().equals("V+") && costDetail.getCostAdjustmentDate() != null) {
cd.setProcessed(false);
cd.setAmt(amount);
cd.saveEx();
cq.setCurrentCostPrice(cd.getAmt().divide(cd.getQty()));
cq.saveEx();
break;
} else if (trx.getMovementType().equals("M+") || trx.getMovementType().equals("M-")) {
MTransaction trxTo;
if (trx.getMovementType().equals("M+"))
trxTo = getPrevious(trx);
else
trxTo = getNext(trx);
cd.setProcessed(false);
if (CostDimension.isSameCostDimension(accountSchema, trx, trxTo)) {
cd.setAmt(cd.getQty().multiply(costThisLevel.add(costLowLevel)));
cd.saveEx();
} else {
cq.addCurrentQty(cd.getQty().negate());
cd.setAmt(cd.getQty().multiply(costThisLevel.add(costLowLevel)));
cd.saveEx();
if (trx.getMovementType().equals("M+"))
cq.setCurrentCostPrice(cd.getAmt().divide(cd.getQty()));
if (cq.getCurrentCostPrice().compareTo(Env.ZERO) == 0)
cq.setCurrentCostPrice(cd.getCurrentCostPrice());
cq.saveEx();
list.add(cd);
}
} else
continue;
}
for (MCostDetail cd : list.toArray(new MCostDetail[list.size()])) {
processCostDetail(cd);
}
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class CostDimension method isSameCostDimension.
public static boolean isSameCostDimension(MAcctSchema as, MTransaction trxFrom, MTransaction trxTo) {
if (trxFrom.getM_Product_ID() != trxTo.getM_Product_ID()) {
throw new AdempiereException("Same product is needed - " + trxFrom + ", " + trxTo);
}
MProduct product = MProduct.get(trxFrom.getCtx(), trxFrom.getM_Product_ID());
String CostingLevel = product.getCostingLevel(as, trxFrom.getAD_Org_ID());
MLocator locatorFrom = MLocator.get(trxFrom.getCtx(), trxFrom.getM_Locator_ID());
MLocator locatorTo = MLocator.get(trxTo.getCtx(), trxTo.getM_Locator_ID());
int Org_ID = locatorFrom.getAD_Org_ID();
int Org_ID_To = locatorTo.getAD_Org_ID();
int ASI_ID = trxFrom.getM_AttributeSetInstance_ID();
int ASI_ID_To = trxTo.getM_AttributeSetInstance_ID();
if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel)) {
Org_ID = 0;
Org_ID_To = 0;
ASI_ID = 0;
ASI_ID_To = 0;
} else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel)) {
ASI_ID = 0;
ASI_ID_To = 0;
} else if (MAcctSchema.COSTINGLEVEL_Warehouse.equals(CostingLevel)) {
ASI_ID = 0;
ASI_ID_To = 0;
} else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel)) {
Org_ID = 0;
Org_ID_To = 0;
}
//
return Org_ID == Org_ID_To && ASI_ID == ASI_ID_To;
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class StandardCostingMethod method createMethodVariances.
public void createMethodVariances(MPPCostCollector costCollector) {
if (!costCollector.isCostCollectorType(MPPCostCollector.COSTCOLLECTORTYPE_ActivityControl))
return;
//
final int std_resource_id = costCollector.getPP_Order_Node().getAD_WF_Node().getS_Resource_ID();
final int actual_resource_id = costCollector.getS_Resource_ID();
if (std_resource_id == actual_resource_id) {
return;
}
//
// Cost Collector - Method Change Variance
MPPCostCollector methodChangeVariance = null;
final RoutingService routingService = RoutingServiceFactory.get().getRoutingService(costCollector.getAD_Client_ID());
for (MAcctSchema as : CostEngine.getAcctSchema(costCollector)) {
for (MCostElement element : MCostElement.getCostElement(costCollector.getCtx(), costCollector.get_TrxName())) {
final MProduct resourcePStd = MProduct.forS_Resource_ID(costCollector.getCtx(), std_resource_id, null);
final MProduct resourcePActual = MProduct.forS_Resource_ID(costCollector.getCtx(), actual_resource_id, null);
final BigDecimal priceStd = getProductActualCostPrice(costCollector, resourcePStd, as, element, costCollector.get_TrxName());
final BigDecimal priceActual = getProductActualCostPrice(costCollector, resourcePActual, as, element, costCollector.get_TrxName());
if (priceStd.compareTo(priceActual) == 0) {
continue;
}
//
if (methodChangeVariance == null) {
methodChangeVariance = MPPCostCollector.createVarianceCostCollector(costCollector, MPPCostCollector.COSTCOLLECTORTYPE_MethodChangeVariance);
}
//
final BigDecimal qty = routingService.getResourceBaseValue(costCollector.getS_Resource_ID(), costCollector);
final BigDecimal amtStd = priceStd.multiply(qty);
final BigDecimal amtActual = priceActual.multiply(qty);
//
List<MCostType> costtypes = MCostType.get(as.getCtx(), as.get_TrxName());
for (MCostType costType : costtypes) {
//implementation only for standard cost
if (!MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod()))
continue;
createVarianceCostDetail(methodChangeVariance, amtActual.abs(), qty, null, resourcePActual, as, costType, element);
createVarianceCostDetail(methodChangeVariance, amtStd.negate(), qty.negate(), null, resourcePStd, as, costType, element);
}
}
}
//
if (methodChangeVariance != null) {
boolean ok = methodChangeVariance.processIt(MPPCostCollector.ACTION_Complete);
methodChangeVariance.saveEx();
if (!ok)
throw new AdempiereException(methodChangeVariance.getProcessMsg());
}
}
Aggregations