Search in sources :

Example 1 with MInventoryLine

use of org.compiere.model.MInventoryLine in project adempiere by adempiere.

the class CostResult method createInvetoryInternalUse.

public MInventory createInvetoryInternalUse(Timestamp documentDate, BigDecimal qty) {
    int M_Locator_ID = 101;
    MInventory inventory = new MInventory(getCtx(), 0, trxName);
    inventory.setAD_Org_ID(Env.getAD_Org_ID(getCtx()));
    inventory.setM_Warehouse_ID(w.getM_Warehouse_ID());
    inventory.setC_DocType_ID((MDocType.getDocType(MDocType.DOCBASETYPE_MaterialPhysicalInventory)));
    inventory.setMovementDate(documentDate);
    inventory.saveEx();
    MInventoryLine invenotryLine = new MInventoryLine(getCtx(), 0, trxName);
    invenotryLine.setAD_Org_ID(Env.getAD_Org_ID(getCtx()));
    invenotryLine.setM_Inventory_ID(inventory.getM_Inventory_ID());
    invenotryLine.setM_Product_ID(product.getM_Product_ID());
    invenotryLine.setQtyBook(Env.ZERO);
    invenotryLine.setQtyCount(Env.ZERO);
    invenotryLine.setQtyInternalUse(qty);
    invenotryLine.setInventoryType(MInventoryLine.INVENTORYTYPE_ChargeAccount);
    invenotryLine.setC_Charge_ID(100);
    // Default HQ Locator
    invenotryLine.setM_Locator_ID(M_Locator_ID);
    invenotryLine.saveEx();
    inventory.processIt(DocAction.ACTION_Complete);
    inventory.saveEx();
    return inventory;
}
Also used : MInventory(org.compiere.model.MInventory) MInventoryLine(org.compiere.model.MInventoryLine)

Example 2 with MInventoryLine

use of org.compiere.model.MInventoryLine in project adempiere by adempiere.

the class CostResult method createBusinessCaseTest.

/**
	 * create Business Test Case
	 * @param trxName
	 */
void createBusinessCaseTest(String trxName) {
    createDataMaster();
    generateHistoryCost();
    Timestamp dateAcct;
    //First Purchase Receipt 
    dateAcct = today;
    MOrder purchase1 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(36));
    MInOut receipt1 = null;
    for (MOrderLine line : purchase1.getLines()) {
        receipt1 = createMaterialReceipt(dateAcct, new BigDecimal(10), line.getC_OrderLine_ID());
    }
    for (MInOutLine line : receipt1.getLines()) {
        CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("47.7292"), // cumulateQty
        new BigDecimal("30"), //cumulateAmt
        new BigDecimal("1431.8748"), //cdAmt
        new BigDecimal("477.2920"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("10"), //cdCurrentCostPrice
        new BigDecimal("53.5937"), //cdCumulateQty
        new BigDecimal("20"), //cdCumulateAmt
        new BigDecimal("1071.8748"), dateAcct);
        assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    //Create Sales Order Order Credit by 5
    dateAcct = TimeUtil.addDays(today, 15);
    MOrder sales1 = createSalesOrder(dateAcct, new BigDecimal(5), new BigDecimal(45));
    for (MOrderLine line : sales1.getLines()) {
        CostResult costResult = new CostResult(product.getM_Product_ID(), new BigDecimal("47.7292"), new BigDecimal("25"), new BigDecimal("1193.2288"), new BigDecimal("238.6460"), new BigDecimal("0"), new BigDecimal("-5"), new BigDecimal("47.7292"), new BigDecimal("30"), new BigDecimal("1431.8748"), dateAcct);
        assertCostShipment(costResult, line.getC_OrderLine_ID(), as, trxName);
    }
    //Second Purchase Receipt 7 day forward
    dateAcct = TimeUtil.addDays(today, 31);
    MOrder purchase2 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(34));
    MInOut receipt2 = null;
    for (MOrderLine line : purchase2.getLines()) {
        receipt2 = createMaterialReceipt(dateAcct, new BigDecimal(10), line.getC_OrderLine_ID());
    }
    for (MInOutLine line : receipt2.getLines()) {
        CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("43.8065"), // cumulateQty
        new BigDecimal("35"), //cumulateAmt
        new BigDecimal("1533.2288"), //cdAmt
        new BigDecimal("438.0650"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("10"), //cdCurrentCostPrice
        new BigDecimal("47.7292"), //cdCumulateQty
        new BigDecimal("25"), //cdCumulateAmt
        new BigDecimal("1193.2288"), dateAcct);
        assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    //Create Sales Order Order Credit by 5
    dateAcct = TimeUtil.addDays(today, 60);
    MOrder sales2 = createSalesOrder(dateAcct, new BigDecimal(10), new BigDecimal(45));
    for (MOrderLine line : sales2.getLines()) {
        CostResult costResult = new CostResult(product.getM_Product_ID(), new BigDecimal("43.8065"), new BigDecimal("25"), new BigDecimal("1095.1638"), new BigDecimal("438.0650"), new BigDecimal("0"), new BigDecimal("-10"), new BigDecimal("43.8065"), new BigDecimal("35"), new BigDecimal("1533.2288"), dateAcct);
        assertCostShipment(costResult, line.getC_OrderLine_ID(), as, trxName);
    }
    dateAcct = receipt1.getDateAcct();
    int M_InOutLine_ID = 0;
    for (MInOutLine line : receipt1.getLines()) {
        M_InOutLine_ID = line.getM_InOutLine_ID();
        MInvoice invoice = createInvoiceVendor(dateAcct, new BigDecimal(10), new BigDecimal(38), line.getM_InOutLine_ID());
    }
    CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
    new BigDecimal("44.2827"), // cumulateQty
    new BigDecimal("25"), //cumulateAmt
    new BigDecimal("1107.0688"), //cdAmt
    new BigDecimal("380.0000"), //cdAdjutment
    new BigDecimal("20.0000"), //cdQty
    new BigDecimal("10"), //cdCurrentCostPrice
    new BigDecimal("53.5937"), //cdCumulateQty
    new BigDecimal("20"), //cdCumulateAmt
    new BigDecimal("1071.8748"), dateAcct);
    assertCostInvoice(costResult, M_InOutLine_ID, as, trxName);
    dateAcct = Timestamp.valueOf("2010-01-16 00:00:00.0");
    for (MOrderLine line : sales1.getLines()) {
        costResult = new CostResult(line.getM_Product_ID(), new BigDecimal("44.2827"), new BigDecimal("25"), new BigDecimal("1107.0688"), new BigDecimal("241.9790"), new BigDecimal("0"), new BigDecimal("-5"), new BigDecimal("48.3958"), new BigDecimal("30"), new BigDecimal("1451.8748"), dateAcct);
        assertCostShipmentAdjust(costResult, line.getC_OrderLine_ID(), as, trxName);
    }
    //Reverse Material Receipt		
    dateAcct = today;
    receipt1.processIt(DocAction.ACTION_Reverse_Correct);
    receipt1.saveEx();
    for (MInOutLine line : receipt1.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("44.2827"), // cumulateQty
        new BigDecimal("25"), //cumulateAmt
        new BigDecimal("1107.0688"), //cdAmt
        new BigDecimal("380.0000"), //cdAdjutment
        new BigDecimal("20.0000"), //cdQty
        new BigDecimal("10"), //cdCurrentCostPrice
        new BigDecimal("53.5937"), //cdCumulateQty
        new BigDecimal("20"), //cdCumulateAmt
        new BigDecimal("1071.8748"), dateAcct);
        assertCostReceiptReversal(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    MInOut reversal = new MInOut(getCtx(), receipt1.getReversal_ID(), trxName);
    for (MInOutLine line : reversal.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("46.8373"), // cumulateQty
        new BigDecimal("19"), //cumulateAmt
        new BigDecimal("889.9081"), //cdAmt
        new BigDecimal("380"), //cdAdjutment
        new BigDecimal("20"), //cdQty
        new BigDecimal("-10"), //cdCurrentCostPrice
        new BigDecimal("49.0073"), //cdCumulateQty
        new BigDecimal("34"), //cdCumulateAmt
        new BigDecimal("1666.2496"), dateAcct);
        assertCostReceiptReversal(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    //Second Purchase Receipt 7 day forward
    dateAcct = TimeUtil.addDays(today, 7);
    MOrder purchase3 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(37));
    MInOut receipt3 = null;
    for (MOrderLine line : purchase3.getLines()) {
        receipt3 = createMaterialReceipt(dateAcct, new BigDecimal(20), line.getC_OrderLine_ID());
    }
    for (MInOutLine line : receipt3.getLines()) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("42.0489"), // cumulateQty
        new BigDecimal("45"), //cumulateAmt
        new BigDecimal("1892.1983"), //cdAmt
        new BigDecimal("876.7500"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("20"), //cdCurrentCostPrice
        new BigDecimal("48.3958"), //cdCumulateQty
        new BigDecimal("30"), //cdCumulateAmt
        new BigDecimal("1451.8748"), dateAcct);
        assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    dateAcct = TimeUtil.addDays(today, 65);
    MMovement move = createMovement(dateAcct, new BigDecimal("5"));
    for (MMovementLine line : move.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("53.5938"), // cumulateQty
        new BigDecimal("9"), //cumulateAmt
        new BigDecimal("482.3442"), //cdAmt
        new BigDecimal("267.9690"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("5"), //cdCurrentCostPrice
        new BigDecimal("53.5938"), //cdCumulateQty
        new BigDecimal("4"), //cdCumulateAmt
        new BigDecimal("214.3752"), dateAcct);
        assertCostMovement(costResult, line.getM_MovementLine_ID(), as, trxName);
    }
    dateAcct = TimeUtil.addDays(today, 70);
    MInventory inventory = createPhisicalInventory(dateAcct, new BigDecimal("20"), costResult.cumulateQty);
    for (MInventoryLine line : inventory.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("42.0488"), // cumulateQty
        new BigDecimal("51"), //cumulateAmt
        new BigDecimal("2144.4906"), //cdAmt
        new BigDecimal("462.5368"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("11"), //cdCurrentCostPrice
        new BigDecimal("42.0488"), //cdCumulateQty
        new BigDecimal("40"), //cdCumulateAmt
        new BigDecimal("1681.9538"), dateAcct);
        assertCostPhisicalInventory(costResult, line.getM_InventoryLine_ID(), as, trxName);
        break;
    }
    dateAcct = TimeUtil.addDays(today, 80);
    inventory = createInvetoryInternalUse(dateAcct, new BigDecimal("-5"));
    for (MInventoryLine line : inventory.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("42.0488"), // cumulateQty
        new BigDecimal("56"), //cumulateAmt
        new BigDecimal("2354.7346"), //cdAmt
        new BigDecimal("210.2440"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("5"), //cdCurrentCostPrice
        new BigDecimal("42.0488"), //cdCumulateQty
        new BigDecimal("51"), //cdCumulateAmt
        new BigDecimal("2144.4906"), dateAcct);
        assertCostPhisicalInventory(costResult, line.getM_InventoryLine_ID(), as, trxName);
        ;
    }
    createTrxAndInventoryValuationReport();
}
Also used : MInOut(org.compiere.model.MInOut) MInOutLine(org.compiere.model.MInOutLine) MInventoryLine(org.compiere.model.MInventoryLine) MInvoice(org.compiere.model.MInvoice) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) MOrder(org.compiere.model.MOrder) MInventory(org.compiere.model.MInventory) MOrderLine(org.compiere.model.MOrderLine) MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement)

Example 3 with MInventoryLine

use of org.compiere.model.MInventoryLine in project adempiere by adempiere.

the class CostEngine method createCostDetail.

/**
	 * Create Cost Detail
	 * @param accountSchema Account Schema
	 * @param transaction Material Transaction
	 * @param model IDocumentLine
	 * @param costType Cost Type
	 * @param costElement Cost Element
	 */
public void createCostDetail(MAcctSchema accountSchema, MCostType costType, MCostElement costElement, MTransaction transaction, IDocumentLine model, boolean force) {
    if (!force)
        return;
    BigDecimal costThisLevel = Env.ZERO;
    BigDecimal costLowLevel = Env.ZERO;
    String costingLevel = MProduct.get(transaction.getCtx(), transaction.getM_Product_ID()).getCostingLevel(accountSchema, transaction.getAD_Org_ID());
    // adjustment for Average PO Costing method
    if (model instanceof MMatchInv && MCostType.COSTINGMETHOD_AveragePO.equals(costType.getCostingMethod()))
        return;
    // adjustment for Average PO Costing method
    if (model instanceof MMatchPO && MCostType.COSTINGMETHOD_AverageInvoice.equals(costType.getCostingMethod()))
        return;
    if (model instanceof MLandedCostAllocation) {
        MLandedCostAllocation allocation = (MLandedCostAllocation) model;
        costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
    }
    MCost cost = MCost.validateCostForCostType(accountSchema, costType, costElement, transaction.getM_Product_ID(), transaction.getAD_Org_ID(), transaction.getM_Warehouse_ID(), transaction.getM_AttributeSetInstance_ID(), transaction.get_TrxName());
    // get the cost for positive transaction
    if ((MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType()) || MCostElement.COSTELEMENTTYPE_LandedCost.equals(costElement.getCostElementType())) && transaction.getMovementType().contains("+") && !MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod())) {
        if (model instanceof MMovementLine || model instanceof MInventoryLine || (model instanceof MInOutLine && MTransaction.MOVEMENTTYPE_CustomerReturns.equals(transaction.getMovementType()))) {
            costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
            if (model instanceof MInventoryLine) {
                MInventoryLine inventoryLine = (MInventoryLine) model;
                // try get cost from physical inventory
                if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
                    // Use the current cost only for Physical Inventory
                    if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPrice() != null && inventoryLine.getCurrentCostPrice().signum() > 0) {
                        costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
                    }
                    if (costThisLevel.signum() == 0)
                        costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
                }
                costLowLevel = getCostLowLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
                // try get cost low level from physical inventory
                if (costLowLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
                    // Use the current cost only for Physical Inventory
                    if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPriceLL() != null && inventoryLine.getCurrentCostPriceLL().signum() > 0) {
                        costLowLevel = convertCostToSchemaCurrency(accountSchema, model, inventoryLine.getCurrentCostPriceLL());
                    }
                    if (costLowLevel.signum() == 0)
                        costLowLevel = getCostLowLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
                }
            }
            //Get cost from movement from if it > that zero replace cost This Level
            if (model instanceof MMovementLine) {
                MTransaction transactionFrom = MTransaction.getByDocumentLine(model, MTransaction.MOVEMENTTYPE_MovementFrom);
                BigDecimal costMovementFrom = getCostThisLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
                if (costMovementFrom.signum() > 0)
                    costThisLevel = costMovementFrom;
                BigDecimal costMovementFromLL = getCostLowLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
                if (costMovementFromLL.signum() > 0)
                    costLowLevel = costMovementFromLL;
            }
        } else if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
            costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
        }
    }
    if (!MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod())) {
        if (model instanceof MPPCostCollector) {
            MPPCostCollector costCollector = (MPPCostCollector) model;
            if (MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt.equals(costCollector.getCostCollectorType())) {
                // get Actual Cost for Cost Type and Cost Element
                costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
                costLowLevel = CostEngine.getParentActualCostByCostType(accountSchema, costType.getM_CostType_ID(), costElement.getM_CostElement_ID(), costCollector);
            }
        }
        if (model instanceof MProductionLine) {
            MProductionLine productionLine = (MProductionLine) model;
            if (productionLine.isParent())
                costThisLevel = CostEngine.getParentActualCostByCostType(accountSchema, costType, costElement, productionLine.getM_Production());
            if (costThisLevel.signum() == 0)
                costThisLevel = cost.getCurrentCostPrice();
            if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType()))
                costThisLevel = getSeedCost(transaction.getCtx(), transaction.getM_Product_ID(), transaction.get_TrxName());
            // Material Receipt for Production light
            if (productionLine.isParent()) {
                // if the product is purchase then no use low level 
                if (!productionLine.getM_Product().isPurchased()) {
                    costLowLevel = costThisLevel;
                    costThisLevel = Env.ZERO;
                }
            } else if (productionLine.getMovementQty().signum() < 0)
                costLowLevel = Env.ZERO;
        }
    } else if (MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod())) {
        costThisLevel = cost.getCurrentCostPrice();
        costLowLevel = cost.getCurrentCostPriceLL();
        //Define Cost Inventory Line
        if (model instanceof MInventoryLine) {
            MInventoryLine inventoryLine = (MInventoryLine) model;
            //Define Current Cost Level
            if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
                // Use the current cost only for Physical Inventory
                if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPrice() != null && inventoryLine.getCurrentCostPrice().signum() > 0) {
                    costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
                    cost.setCurrentCostPrice(costThisLevel);
                    cost.saveEx();
                }
                if (costThisLevel.signum() == 0)
                    costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
            }
            //Define Current Cost Low Level
            if (costLowLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
                // Use the cost only for Physical Inventory
                if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPriceLL() != null && inventoryLine.getCurrentCostPriceLL().signum() > 0) {
                    costLowLevel = convertCostToSchemaCurrency(accountSchema, model, inventoryLine.getCurrentCostPriceLL());
                    cost.setCurrentCostPriceLL(costLowLevel);
                    cost.saveEx();
                }
                if (costLowLevel.signum() == 0)
                    costLowLevel = getCostLowLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
            }
        }
        if (model instanceof MMovementLine) {
            MTransaction transactionFrom = MTransaction.getByDocumentLine(model, MTransaction.MOVEMENTTYPE_MovementFrom);
            BigDecimal costMovementFrom = getCostThisLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
            if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
                if (costMovementFrom.signum() > 0)
                    costThisLevel = costMovementFrom;
            }
            if (costLowLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
                BigDecimal costMovementFromLL = getCostLowLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
                if (costMovementFromLL.signum() > 0)
                    costLowLevel = costMovementFromLL;
            }
        }
        if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
            costThisLevel = getSeedCost(transaction.getCtx(), transaction.getM_Product_ID(), transaction.get_TrxName());
            if (costThisLevel.signum() == 0)
                if (model instanceof MInOutLine && !model.isSOTrx()) {
                    costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
                }
            if (costThisLevel.signum() != 0) {
                cost.setCurrentCostPrice(costThisLevel);
                cost.saveEx();
            }
        }
        if (costLowLevel.signum() != 0) {
            cost.setCurrentCostPriceLL(costLowLevel);
            cost.saveEx();
        }
    }
    final ICostingMethod method = CostingMethodFactory.get().getCostingMethod(costType.getCostingMethod());
    method.setCostingMethod(accountSchema, transaction, model, cost, costThisLevel, costLowLevel, model.isSOTrx());
    method.process();
}
Also used : MLandedCostAllocation(org.compiere.model.MLandedCostAllocation) MMatchPO(org.compiere.model.MMatchPO) MInventoryLine(org.compiere.model.MInventoryLine) MInOutLine(org.compiere.model.MInOutLine) MCost(org.compiere.model.MCost) MProductionLine(org.compiere.model.MProductionLine) MTransaction(org.compiere.model.MTransaction) BigDecimal(java.math.BigDecimal) MMatchInv(org.compiere.model.MMatchInv) MPPCostCollector(org.eevolution.model.MPPCostCollector) MMovementLine(org.compiere.model.MMovementLine)

Example 4 with MInventoryLine

use of org.compiere.model.MInventoryLine in project adempiere by adempiere.

the class AbstractCostingMethod method createCostDetails.

protected List<MCostDetail> createCostDetails() {
    final String idColumnName;
    if (model instanceof MMatchPO) {
        idColumnName = I_C_OrderLine.COLUMNNAME_C_OrderLine_ID;
    } else if (model instanceof MMatchInv) {
        idColumnName = I_C_InvoiceLine.COLUMNNAME_C_InvoiceLine_ID;
    } else {
        idColumnName = model.get_TableName() + "_ID";
    }
    List<MCostDetail> list = new ArrayList<MCostDetail>();
    if (model.isSOTrx() == true || model instanceof MInventoryLine || model instanceof MMovementLine) {
        List<CostComponent> costComponents = getCalculatedCosts();
        for (CostComponent costComponent : costComponents) {
            MCostDetail cost = new MCostDetail(transaction, accountSchema.getC_AcctSchema_ID(), dimension.getM_CostType_ID(), dimension.getM_CostElement_ID(), costComponent.getAmount(), Env.ZERO, costComponent.getQty(), model.get_TrxName());
            if (!cost.set_ValueOfColumnReturningBoolean(idColumnName, model.get_ID()))
                throw new AdempiereException("Cannot set " + idColumnName);
            StringBuilder description = new StringBuilder();
            if (!Util.isEmpty(model.getDescription(), true))
                description.append(model.getDescription());
            if (model.isSOTrx() != false) {
                description.append(model.isSOTrx() ? "(|->)" : "(|<-)");
            }
            if (// TODO: need evaluate anca
            model.isSOTrx() != false)
                cost.setIsSOTrx(model.isSOTrx());
            else
                cost.setIsSOTrx(model.isSOTrx());
            cost.setM_Transaction_ID(transaction.get_ID());
            cost.setDescription(description.toString());
            cost.saveEx();
            list.add(cost);
        }
    } else // qty and amt is take from documentline
    {
        MCostDetail cost = new MCostDetail(transaction, accountSchema.getC_AcctSchema_ID(), dimension.getM_CostType_ID(), dimension.getM_CostElement_ID(), costThisLevel.multiply(model.getMovementQty()), Env.ZERO, model.getMovementQty(), model.get_TrxName());
        int id;
        if (model instanceof MMatchPO) {
            I_M_InOutLine inOutLine = transaction.getM_InOutLine();
            I_C_OrderLine orderLine = inOutLine.getC_OrderLine();
            id = orderLine.getC_OrderLine_ID();
        } else {
            id = model.get_ID();
        }
        if (!cost.set_ValueOfColumnReturningBoolean(idColumnName, id))
            throw new AdempiereException("Cannot set " + idColumnName);
        if (model.isSOTrx() != false)
            cost.setIsSOTrx(model.isSOTrx());
        else
            cost.setIsSOTrx(model.isSOTrx());
        cost.setM_Transaction_ID(transaction.get_ID());
        cost.saveEx();
        list.add(cost);
    }
    return list;
}
Also used : MMatchPO(org.compiere.model.MMatchPO) MInventoryLine(org.compiere.model.MInventoryLine) I_M_InOutLine(org.compiere.model.I_M_InOutLine) ArrayList(java.util.ArrayList) I_C_OrderLine(org.compiere.model.I_C_OrderLine) AdempiereException(org.adempiere.exceptions.AdempiereException) MMatchInv(org.compiere.model.MMatchInv) MCostDetail(org.compiere.model.MCostDetail) MMovementLine(org.compiere.model.MMovementLine)

Example 5 with MInventoryLine

use of org.compiere.model.MInventoryLine in project adempiere by adempiere.

the class ScanBar method loadData.

protected void loadData() {
    data = new LinkedHashMap<String, Vector>();
    for (PO po : getDocumentLines()) {
        MProduct product = null;
        MAttributeSetInstance asi = null;
        String lotNo = null;
        String serNo = null;
        Integer referenceId = null;
        BigDecimal qty = null;
        boolean reset = false;
        int M_Product_ID = po.get_ValueAsInt(MProduct.COLUMNNAME_M_Product_ID);
        int M_AttributeSetInstance_ID = po.get_ValueAsInt(MAttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID);
        if (M_Product_ID > 0)
            product = MProduct.get(Env.getCtx(), M_Product_ID);
        else
            continue;
        if (M_AttributeSetInstance_ID > 0) {
            asi = new MAttributeSetInstance(Env.getCtx(), M_AttributeSetInstance_ID, null);
            lotNo = asi.getLot();
            serNo = asi.getSerNo();
        } else {
            M_AttributeSetInstance_ID = 0;
            reset = true;
            lotNo = null;
            serNo = null;
        }
        if (po instanceof MInOutLine) {
            MInOutLine ioLine = (MInOutLine) po;
            referenceId = ioLine.getC_OrderLine_ID();
            qty = ioLine.getMovementQty();
        }
        if (po instanceof MInventoryLine) {
            MInventoryLine invenotryLine = (MInventoryLine) po;
            qty = invenotryLine.getQtyCount();
        }
        if (getSource() != null && source.size() > 0) {
            ArrayList<Object> values = checkProduct(product, qty, reset);
            if (values == null)
                throw new AdempiereException("@M_Product_ID@ ; " + product.getName() + " @InValid@");
        }
        String key = product.getValue();
        if (lotNo != null && lotNo.length() > 0)
            key = key + lotNo;
        if (serNo != null && serNo.length() > 0)
            key = key + serNo;
        Vector<Object> line = new Vector<Object>(6);
        // 0
        line.add(product.getValue());
        // 1
        line.add(product.getName());
        // 2
        line.add(lotNo);
        // 3
        line.add(serNo);
        // 4
        line.add(qty);
        // 5
        line.add(po.get_ID());
        // 6
        line.add(referenceId != null ? referenceId.intValue() : 0);
        data.put(key, line);
    }
}
Also used : MProduct(org.compiere.model.MProduct) MInOutLine(org.compiere.model.MInOutLine) MInventoryLine(org.compiere.model.MInventoryLine) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) BigDecimal(java.math.BigDecimal) AdempiereException(org.adempiere.exceptions.AdempiereException) Vector(java.util.Vector) PO(org.compiere.model.PO)

Aggregations

MInventoryLine (org.compiere.model.MInventoryLine)15 BigDecimal (java.math.BigDecimal)7 MInOutLine (org.compiere.model.MInOutLine)6 MInventory (org.compiere.model.MInventory)6 MMovementLine (org.compiere.model.MMovementLine)6 MProduct (org.compiere.model.MProduct)5 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)3 MMatchInv (org.compiere.model.MMatchInv)3 MMatchPO (org.compiere.model.MMatchPO)3 MPPCostCollector (org.eevolution.model.MPPCostCollector)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 Timestamp (java.sql.Timestamp)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 MAttributeSet (org.compiere.model.MAttributeSet)2 MInventoryLineMA (org.compiere.model.MInventoryLineMA)2 MLocator (org.compiere.model.MLocator)2 MOrderLine (org.compiere.model.MOrderLine)2