use of org.compiere.model.MProduct in project adempiere by adempiere.
the class CostEngine method clearAccounting.
/**
* Clear Accounting
* @param accountSchema
* @param costType
* @param model
* @param productId
* @param dateAcct
* @return true clean
*/
public boolean clearAccounting(MAcctSchema accountSchema, I_M_CostType costType, PO model, int productId, Timestamp dateAcct) {
// check if costing type need reset accounting
if (!accountSchema.getCostingMethod().equals(costType.getCostingMethod())) {
MProduct product = MProduct.get(accountSchema.getCtx(), productId);
MProductCategoryAcct productCategoryAcct = MProductCategoryAcct.get(accountSchema.getCtx(), product.getM_Product_Category_ID(), accountSchema.get_ID(), model.get_TrxName());
if (productCategoryAcct == null || !costType.getCostingMethod().equals(productCategoryAcct.getCostingMethod()))
return false;
}
final String docBaseType;
// check if account period is open
if (model instanceof MMatchInv)
docBaseType = MPeriodControl.DOCBASETYPE_MatchInvoice;
else if (model instanceof MMatchPO)
docBaseType = MPeriodControl.DOCBASETYPE_MatchPO;
else if (model instanceof MProduction)
docBaseType = MPeriodControl.DOCBASETYPE_MaterialProduction;
else {
MDocType docType = MDocType.get(model.getCtx(), model.get_ValueAsInt(MDocType.COLUMNNAME_C_DocType_ID));
docBaseType = docType.getDocBaseType();
}
Boolean openPeriod = MPeriod.isOpen(model.getCtx(), dateAcct, docBaseType, model.getAD_Org_ID());
if (!openPeriod) {
System.out.println("Period closed.");
return false;
}
final String sqlUpdate = "UPDATE " + model.get_TableName() + " SET Posted = 'N' WHERE " + model.get_TableName() + "_ID=?";
DB.executeUpdate(sqlUpdate, new Object[] { model.get_ID() }, false, model.get_TrxName());
//Delete account
final String sqldelete = "DELETE FROM Fact_Acct WHERE Record_ID =? AND AD_Table_ID=?";
DB.executeUpdate(sqldelete, new Object[] { model.get_ID(), model.get_Table_ID() }, false, model.get_TrxName());
return true;
}
use of org.compiere.model.MProduct 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.compiere.model.MProduct 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.compiere.model.MProduct 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.compiere.model.MProduct in project adempiere by adempiere.
the class CostDimension method isSameCostDimension.
public static boolean isSameCostDimension(MAcctSchema as, IDocumentLine model) {
MProduct product = MProduct.get(model.getCtx(), model.getM_Product_ID());
MLocator locator = MLocator.get(model.getCtx(), model.getM_LocatorTo_ID());
String CostingLevel = product.getCostingLevel(as, model.getAD_Org_ID());
int Org_ID = model.getAD_Org_ID();
int Org_ID_To = locator.getAD_Org_ID();
int ASI_ID = model.getM_AttributeSetInstance_ID();
int ASI_ID_To = model.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;
}
Aggregations