Search in sources :

Example 1 with I_M_InOutLine

use of org.compiere.model.I_M_InOutLine 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)

Aggregations

ArrayList (java.util.ArrayList)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 I_C_OrderLine (org.compiere.model.I_C_OrderLine)1 I_M_InOutLine (org.compiere.model.I_M_InOutLine)1 MCostDetail (org.compiere.model.MCostDetail)1 MInventoryLine (org.compiere.model.MInventoryLine)1 MMatchInv (org.compiere.model.MMatchInv)1 MMatchPO (org.compiere.model.MMatchPO)1 MMovementLine (org.compiere.model.MMovementLine)1