Search in sources :

Example 1 with MBPartner

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

the class SB_InvoiceGenerateFromOrderLine method generate.

//	doIt
/**
	 * 	Generate Shipments
	 * 	@param pstmt order query 
	 *	@return info
	 */
private String generate(MOrder order) {
    try {
        {
            //	New Invoice Location
            if (!p_ConsolidateDocument || (m_invoice != null && m_invoice.getC_BPartner_Location_ID() != order.getBill_Location_ID()))
                completeInvoice();
            boolean completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.equals(order.getInvoiceRule());
            //	Schedule After Delivery
            boolean doInvoice = false;
            if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.equals(order.getInvoiceRule())) {
                m_bp = new MBPartner(getCtx(), order.getBill_BPartner_ID(), null);
                if (m_bp.getC_InvoiceSchedule_ID() == 0) {
                    log.warning("BPartner has no Schedule - set to After Delivery");
                    order.setInvoiceRule(MOrder.INVOICERULE_AfterDelivery);
                    order.saveEx();
                } else {
                    MInvoiceSchedule is = MInvoiceSchedule.get(getCtx(), m_bp.getC_InvoiceSchedule_ID(), get_TrxName());
                    if (is.canInvoice(order.getDateOrdered(), order.getGrandTotal()))
                        doInvoice = true;
                    else
                        return "";
                }
            }
            //	After Delivery
            if (doInvoice || MOrder.INVOICERULE_AfterDelivery.equals(order.getInvoiceRule())) {
                MInOut[] shipments = order.getShipments();
                for (int i = 0; i < shipments.length; i++) {
                    MInOut ship = shipments[i];
                    if (//	ignore incomplete or reversals 
                    !ship.isComplete() || ship.getDocStatus().equals(MInOut.DOCSTATUS_Reversed))
                        continue;
                    MInOutLine[] shipLines = ship.getLines(false);
                    for (int j = 0; j < shipLines.length; j++) {
                        MInOutLine shipLine = shipLines[j];
                        if (!order.isOrderLine(shipLine.getC_OrderLine_ID()))
                            continue;
                        if (!getSelectionKeys().contains(shipLine.getC_OrderLine_ID()))
                            continue;
                        if (!shipLine.isInvoiced())
                            createLine(order, ship, shipLine);
                    }
                    m_line += 1000;
                }
            } else //	After Order Delivered, Immediate
            {
                MOrderLine[] oLines = order.getLines(true, null);
                for (int i = 0; i < oLines.length; i++) {
                    MOrderLine oLine = oLines[i];
                    if (!getSelectionKeys().contains(oLine.getC_OrderLine_ID()))
                        continue;
                    BigDecimal toInvoice = oLine.getQtyOrdered().subtract(oLine.getQtyInvoiced());
                    if (toInvoice.compareTo(Env.ZERO) == 0 && oLine.getM_Product_ID() != 0)
                        continue;
                    BigDecimal notInvoicedShipment = oLine.getQtyDelivered().subtract(oLine.getQtyInvoiced());
                    //
                    boolean fullyDelivered = oLine.getQtyOrdered().compareTo(oLine.getQtyDelivered()) == 0;
                    //	Complete Order
                    if (completeOrder && !fullyDelivered) {
                        log.fine("Failed CompleteOrder - " + oLine);
                        // Elaine 2008/11/25
                        addLog("Failed CompleteOrder - " + oLine);
                        completeOrder = false;
                        break;
                    } else //	Immediate
                    if (MOrder.INVOICERULE_Immediate.equals(order.getInvoiceRule())) {
                        log.fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine);
                        BigDecimal qtyEntered = toInvoice;
                        if (oLine.getQtyEntered().compareTo(oLine.getQtyOrdered()) != 0)
                            qtyEntered = toInvoice.multiply(oLine.getQtyEntered()).divide(oLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP);
                        createLine(order, oLine, toInvoice, qtyEntered);
                    } else {
                        log.fine("Failed: " + order.getInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine);
                        addLog("Failed: " + order.getInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine);
                    }
                }
                //	for all order lines
                if (MOrder.INVOICERULE_Immediate.equals(order.getInvoiceRule()))
                    m_line += 1000;
            }
            //	Complete Order successful
            if (completeOrder && MOrder.INVOICERULE_AfterOrderDelivered.equals(order.getInvoiceRule())) {
                MInOut[] shipments = order.getShipments();
                for (int i = 0; i < shipments.length; i++) {
                    MInOut ship = shipments[i];
                    if (//	ignore incomplete or reversals 
                    !ship.isComplete() || ship.getDocStatus().equals(MInOut.DOCSTATUS_Reversed))
                        continue;
                    MInOutLine[] shipLines = ship.getLines(false);
                    for (int j = 0; j < shipLines.length; j++) {
                        MInOutLine shipLine = shipLines[j];
                        if (!order.isOrderLine(shipLine.getC_OrderLine_ID()))
                            continue;
                        if (!shipLine.isInvoiced())
                            createLine(order, ship, shipLine);
                    }
                    m_line += 1000;
                }
            }
        //	complete Order
        }
    //	for all orders
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
    completeInvoice();
    return "@Created@ = " + m_created;
}
Also used : MInOut(org.compiere.model.MInOut) MInOutLine(org.compiere.model.MInOutLine) MInvoiceSchedule(org.compiere.model.MInvoiceSchedule) MBPartner(org.compiere.model.MBPartner) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Example 2 with MBPartner

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

the class BPartnerOrgLink method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message (text with variables)
	 *  @throws Exception if not successful
	 */
protected String doIt() throws Exception {
    log.info("C_BPartner_ID=" + p_C_BPartner_ID + ", AD_Org_ID=" + p_AD_Org_ID + ", AD_OrgType_ID=" + p_AD_OrgType_ID + ", AD_Role_ID=" + p_AD_Role_ID);
    if (p_C_BPartner_ID == 0)
        throw new AdempiereUserError("No Business Partner ID");
    MBPartner bp = new MBPartner(getCtx(), p_C_BPartner_ID, get_TrxName());
    if (bp.get_ID() == 0)
        throw new AdempiereUserError("Business Partner not found - C_BPartner_ID=" + p_C_BPartner_ID);
    //	BP Location
    MBPartnerLocation[] locs = bp.getLocations(false);
    if (locs == null || locs.length == 0)
        throw new IllegalArgumentException("Business Partner has no Location");
    //	Location
    int C_Location_ID = locs[0].getC_Location_ID();
    if (C_Location_ID == 0)
        throw new IllegalArgumentException("Business Partner Location has no Address");
    //	Create Org
    boolean newOrg = p_AD_Org_ID == 0;
    MOrg org = new MOrg(getCtx(), p_AD_Org_ID, get_TrxName());
    if (newOrg) {
        org.setValue(bp.getValue());
        org.setName(bp.getName());
        org.setDescription(bp.getDescription());
        if (!org.save())
            throw new Exception("Organization not saved");
    } else //	check if linked to already
    {
        int C_BPartner_ID = org.getLinkedC_BPartner_ID(get_TrxName());
        if (C_BPartner_ID > 0)
            throw new IllegalArgumentException("Organization '" + org.getName() + "' already linked (to C_BPartner_ID=" + C_BPartner_ID + ")");
    }
    p_AD_Org_ID = org.getAD_Org_ID();
    //	Update Org Info
    MOrgInfo oInfo = org.getInfo();
    oInfo.setAD_OrgType_ID(p_AD_OrgType_ID);
    if (newOrg)
        oInfo.setC_Location_ID(C_Location_ID);
    //	Create Warehouse
    MWarehouse wh = null;
    if (!newOrg) {
        MWarehouse[] whs = MWarehouse.getForOrg(getCtx(), p_AD_Org_ID);
        if (whs != null && whs.length > 0)
            //	pick first
            wh = whs[0];
    }
    //	New Warehouse
    if (wh == null) {
        wh = new MWarehouse(org);
        if (!wh.save(get_TrxName()))
            throw new Exception("Warehouse not saved");
    }
    //	Create Locator
    MLocator mLoc = wh.getDefaultLocator();
    if (mLoc == null) {
        mLoc = new MLocator(wh, "Standard");
        mLoc.setIsDefault(true);
        mLoc.save(get_TrxName());
    }
    //	Update/Save Org Info
    oInfo.setM_Warehouse_ID(wh.getM_Warehouse_ID());
    if (!oInfo.save(get_TrxName()))
        throw new Exception("Organization Info not saved");
    //	Update BPartner
    bp.setAD_OrgBP_ID(p_AD_Org_ID);
    if (bp.getAD_Org_ID() != 0)
        //	Shared BPartner
        bp.setClientOrg(bp.getAD_Client_ID(), 0);
    //	Save BP
    if (!bp.save())
        throw new Exception("Business Partner not updated");
    //	Limit to specific Role
    if (p_AD_Role_ID != 0) {
        boolean found = false;
        MRoleOrgAccess[] orgAccesses = MRoleOrgAccess.getOfOrg(getCtx(), p_AD_Org_ID);
        //	delete all accesses except the specific
        for (int i = 0; i < orgAccesses.length; i++) {
            if (orgAccesses[i].getAD_Role_ID() == p_AD_Role_ID)
                found = true;
            else
                orgAccesses[i].delete(true);
        }
        //	create access
        if (!found) {
            MRoleOrgAccess orgAccess = new MRoleOrgAccess(org, p_AD_Role_ID);
            orgAccess.save(get_TrxName());
        }
    }
    //	Reset Client Role
    MRole.getDefault(getCtx(), true);
    return "Business Partner - Organization Link created";
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) MBPartner(org.compiere.model.MBPartner) MWarehouse(org.compiere.model.MWarehouse) MBPartnerLocation(org.compiere.model.MBPartnerLocation) MOrg(org.compiere.model.MOrg) MLocator(org.compiere.model.MLocator) MOrgInfo(org.compiere.model.MOrgInfo) MRoleOrgAccess(org.compiere.model.MRoleOrgAccess)

Example 3 with MBPartner

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

the class ConvertLead method doIt.

@Override
protected String doIt() throws Exception {
    if (p_AD_User_ID <= 0)
        throw new FillMandatoryException("AD_User_ID");
    MUser lead = new MUser(getCtx(), p_AD_User_ID, get_TrxName());
    if (!lead.isSalesLead() || lead.getC_BPartner_ID() != 0)
        throw new AdempiereUserError("Lead already converted");
    MBPartner bp = MBPartner.getTemplate(getCtx(), getAD_Client_ID());
    bp.set_TrxName(get_TrxName());
    if (!Util.isEmpty(lead.getBPName()))
        bp.setName(lead.getBPName());
    else
        bp.setName(lead.getName());
    bp.saveEx();
    addLog("Business Partner created.");
    lead.setC_BPartner_ID(bp.getC_BPartner_ID());
    if (lead.getC_Location_ID() != 0) {
        MLocation leadAddress = (MLocation) lead.getC_Location();
        MBPartnerLocation loc = new MBPartnerLocation(bp);
        MLocation address = new MLocation(getCtx(), 0, get_TrxName());
        PO.copyValues(leadAddress, address);
        address.saveEx();
        loc.setC_Location_ID(address.getC_Location_ID());
        loc.setPhone(lead.getPhone());
        loc.setPhone2(lead.getPhone2());
        loc.setFax(lead.getFax());
        loc.saveEx();
        lead.setC_BPartner_Location_ID(loc.getC_BPartner_Location_ID());
        addLog("Contact Location added.");
    }
    // company address
    if (lead.getBP_Location_ID() != 0) {
        MLocation leadAddress = (MLocation) lead.getBP_Location();
        MBPartnerLocation loc = new MBPartnerLocation(bp);
        MLocation address = new MLocation(getCtx(), 0, get_TrxName());
        PO.copyValues(leadAddress, address);
        address.saveEx();
        loc.setC_Location_ID(address.getC_Location_ID());
        loc.saveEx();
        addLog("BP Address added.");
    }
    if (p_createOpportunity) {
        MOpportunity op = new MOpportunity(getCtx(), 0, get_TrxName());
        op.setAD_User_ID(lead.getAD_User_ID());
        op.setC_BPartner_ID(bp.getC_BPartner_ID());
        op.setExpectedCloseDate(p_expectedCloseDate != null ? p_expectedCloseDate : new Timestamp(System.currentTimeMillis()));
        op.setOpportunityAmt(p_opportunityAmt != null ? p_opportunityAmt : Env.ZERO);
        if (p_C_SalesStage_ID > 0)
            op.setC_SalesStage_ID(p_C_SalesStage_ID);
        String sql = "SELECT Probability FROM C_SalesStage WHERE C_SalesStage_ID = ?";
        BigDecimal probability = DB.getSQLValueBD(get_TrxName(), sql, p_C_SalesStage_ID);
        op.setProbability(probability != null ? probability : Env.ZERO);
        op.setDescription(p_Description);
        if (p_C_Currency_ID > 0)
            op.setC_Currency_ID(p_C_Currency_ID);
        else
            op.setC_Currency_ID(Env.getContextAsInt(getCtx(), "$C_Currency_ID"));
        if (p_SalesRep_ID > 0)
            op.setSalesRep_ID(p_SalesRep_ID);
        else if (lead.getSalesRep_ID() > 0)
            op.setSalesRep_ID(lead.getSalesRep_ID());
        else
            op.setSalesRep_ID(Env.getContextAsInt(getCtx(), "#SalesRep_ID"));
        op.setC_Campaign_ID(lead.getC_Campaign_ID());
        op.saveEx();
        addLog("Opportunity created.");
    }
    lead.setIsSalesLead(false);
    lead.setLeadStatus(MUser.LEADSTATUS_Converted);
    lead.saveEx();
    addLog("Lead converted.");
    return "@OK@";
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) MOpportunity(org.compiere.model.MOpportunity) MBPartner(org.compiere.model.MBPartner) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) MUser(org.compiere.model.MUser) MLocation(org.compiere.model.MLocation) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Example 4 with MBPartner

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

the class BPartnerValidate method doIt.

//	prepare
/**
	 * 	Process
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("C_BPartner_ID=" + p_C_BPartner_ID + ", C_BP_Group_ID=" + p_C_BP_Group_ID);
    if (p_C_BPartner_ID == 0 && p_C_BP_Group_ID == 0)
        throw new AdempiereUserError("No Business Partner/Group selected");
    if (p_C_BP_Group_ID == 0) {
        MBPartner bp = new MBPartner(getCtx(), p_C_BPartner_ID, get_TrxName());
        if (bp.get_ID() == 0)
            throw new AdempiereUserError("Business Partner not found - C_BPartner_ID=" + p_C_BPartner_ID);
        checkBP(bp);
    } else {
        final String whereClause = "C_BP_Group_ID=?";
        Iterator<MBPartner> it = new Query(getCtx(), I_C_BPartner.Table_Name, whereClause, get_TrxName()).setParameters(p_C_BP_Group_ID).setOnlyActiveRecords(true).iterate();
        while (it.hasNext()) {
            checkBP(it.next());
        }
    }
    //
    return "OK";
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) Query(org.compiere.model.Query) MBPartner(org.compiere.model.MBPartner)

Example 5 with MBPartner

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

the class MBPartnerTest method testBPartner.

/*
 	private MBPartnerLocation bpl = null; //business partner location
	private MUser user = null; //business contact
	private MContactInterest ci = null; //contact interest area

	// Variables needed for importing/migrating accounts
	private MElementValue ev = null;  //element value
	private MAcctSchema as = null; //account schema
	private MAccount acct = null; //account
	
	// Variables needed for importing/migrating bank statements
	private MBankStatement statement = null;
	private MBankAccount account = null;
	private MBankStatementLine line = null;

	// Variables needed for importing/migrating conversion rates
	private MConversionRate rate = null;

	// Variables needed for importing/migrating General Ledger Journal
	private MJournalBatch batch = null;
	private MJournal journal = null;
	private MJournalLine line = null;

	// Variables needed for importing/migrating Inventory
	private MInventory inventory = null;
	private MProduct product = null;
	private MAttributeSet mas = null;
	private MAttributeSetInstance masi = null;
	private MInventoryLine line = null;

	// Variables needed for importing/migrating Invoices
	private MInvoice invoice = null;
	private MInvoiceLine line = null;

	// Variables needed for importing/migrating orders
	private MOrder order = null;
	private MOrderLine line = null;

	// Variables needed for importing/migrating payments
	private MPayment payment = null;

	// Variables needed for importing/migrating products
	private MProduct product = null;
	private MProductPrice pp = null;

	// Variables needed for mrp
	
	private MCost cost = null;
	private MCostElement costElement = null;
	private MForecastLine forcastLine = null;
	private MOrder order = null;
	private MOrderLine line = null;
	private MPPCostCollector costCollector = null;
	private MPPOrderBOM orderBOM = null;
	private MPPOrderBOMLine = null;
	private MPPOrderBOMLineMA = null;
	private MPPOrderCost = null;
	private MPPOrder = null;
	private MPPProductBOM = null;
	private MPPProductBOMLine = null;
	private MPPProductCosting = null;
	private MPPProductPlanning = null;
	private MPPProfileBOMCost = null;
	private MPPProfileBOM = null;
	private MPPProfileBOMProduct = null;
	private MPPProfileBOMReal = null;
	private MPPProfileBOMSelected = null;
	private MQMSpecification = null;
	private MQMSpecificationLine = null;
	private MRequisition = null;
	private MRequisitionLine = null;
	

	// other variables that may be needed:

	private MAdvertisement = null;
	private MAging = null;
	private MAlert = null;
	private MAlertRecipient = null;
	private MAlertRule = null;

	private MAllocationHdr = null;
	private MAllocationLine = null;

	private MAssetDelivery = null;
	private MAssetGroup = null;
	private MAsset = null;
	private MAssignmentSlot = null;
	private MAttributeInstance = null;

	private MAccessProfile = null;
	private MMailText = null;
	private MAcctProcessor = null;
	private MMatchInv = null;
	private MAcctProcessorLog = null;
	private MMatchPO = null;
	private MAchievement = null;
	private MMeasureCalc = null;
	private MActivity = null;
	private MMeasure = null;
	private MAd = null;
	private MMediaDeploy = null;
	private MAdvertisement = null;
	private MMedia = null;
	private MAging = null;
	private MMediaServer = null;
	private MAlert = null;
	private MMovementConfirm = null;
	private MAlertProcessor = null;
	private MMovement = null;
	private MAlertProcessorLog = null;
	private MMovementLineConfirm = null;
	private MAlertRecipient = null;
	private MMovementLine = null;
	private MAlertRule = null;
	private MMovementLineMA = null;
	private MAllocationHdr = null;
	private MNewsChannel = null;
	private MAllocationLine = null;
	private MNewsItem = null;
	private MAssetDelivery = null;
	private MOrder = null;
	private MAssetGroup = null;
	private MOrderLine = null;
	private MAsset = null;
	private MOrderTax = null;
	private MAssignmentSlot = null;
	private MPackage = null;
	private MAttributeInstance = null;
	private MPackageLine = null;
	private MAttribute = null;
	private MPaymentAllocate = null;
	private MAttributeSetInstance = null;
	private MPaymentBatch = null;
	private MAttributeSet = null;
	private MPayment = null;
	private MAttributeUse = null;
	private MPaymentProcessor = null;
	private MAttributeValue = null;
	private MPaymentTerm = null;
	private MBankAccount = null;
	private MPaymentValidate = null;
	private MBank = null;
	private MPaySchedule = null;
	private MBankStatement = null;
	private MPaySelectionCheck = null;
	private MBankStatementLine = null;
	private MPaySelection = null;
	private MBankStatementLoader = null;
	private MPaySelectionLine = null;
	private MBankStatementMatcher = null;
	private MPeriodControl = null;
	private MBOM = null;
	private MPeriod = null;
	private MBOMProduct = null;
	private MPOS = null;
	private MBPartnerInfo = null;
	private MPOSKey = null;
	private MPOSKeyLayout = null;
	private MPreference = null;
	private MBPBankAccount = null;
	private MPriceList = null;
	private MBPGroup = null;
	private MPriceListVersion = null;
	private MCalendar = null;
	private MProductBOM = null;
	private MCampaign = null;
	private MProductCategoryAcct = null;
	private MCashBook = null;
	private MProductCategory = null;
	private MCash = null;
	private MProductCosting = null;
	private MCashLine = null;
	private MProductDownload = null;
	private MChangeNotice = null;
	private MProduct = null;
	private MChangeRequest = null;
	private MProductPO = null;
	private MCharge = null;
	private MProductPrice = null;
	private MChatEntry = null;
	private MProductPricing = null;
	private MChat = null;
	private MProjectIssue = null;
	private MChatType = null;
	private MProject = null;
	private MClickCount = null;
	private MProjectLine = null;
	private MClick = null;
	private MProjectPhase = null;
	private MColor = null;
	private MProjectTask = null;
	private MColorSchema = null;
	private MProjectType = null;
	private MCommissionAmt = null;
	private MProjectTypePhase = null;
	private MCommissionDetail = null;
	private MProjectTypeTask = null;
	private MCommission = null;
	private MRecurring = null;
	private MCommissionLine = null;
	private MRecurringRun = null;
	private MCommissionRun = null;
	private MRefTable = null;
	private MContactInterest = null;
	private MRegistrationAttribute = null;
	private MContainerElement = null;
	private MRegistration = null;
	private MContainer = null;
	private MRegistrationValue = null;
	private MCostDetail = null;
	private MReplication = null;
	private MCost = null;
	private MReplicationLog = null;
	private MCostQueue = null;
	private MReplicationRun = null;
	private MCounterCount = null;
	private MRequestAction = null;
	private MCStageElement = null;
	private MRequestCategory = null;
	private MCStage = null;
	private MRequest = null;
	private MDesktop = null;
	private MRequestProcessor = null;
	private MDiscountSchemaBreak = null;
	private MRequestProcessorLog = null;
	private MDiscountSchema = null;
	private MRequestProcessorRoute = null;
	private MDiscountSchemaLine = null;
	private MRequestType = null;
	private MDistribution = null;
	private MRequestUpdate = null;
	private MDistributionLine = null;
	private MRequisition = null;
	private MDistributionList = null;
	private MRequisitionLine = null;
	private MDistributionListLine = null;
	private MResolution = null;
	private MDistributionRunDetail = null;
	private MResourceAssignment = null;
	private MDistributionRun = null;
	private MResource = null;
	private MDistributionRunLine = null;
	private MResourceType = null;
	private MDocTypeCounter = null;
	private MResourceUnAvailable = null;
	private MDunning = null;
	private MRevenueRecognition = null;
	private MDunningLevel = null;
	private MRevenueRecognitionPlan = null;
	private MDunningRunEntry = null;
	private MRfQ = null;
	private MDunningRun = null;
	private MRfQLine = null;
	private MDunningRunLine = null;
	private MRfQLineQty = null;
	private Measure = null;
	private MRfQResponse = null;
	private MEntityType = null;
	private MRfQResponseLine = null;
	private MExpenseType = null;
	private MRfQResponseLineQty = null;
	private MFactAcct = null;
	private MRfQTopic = null;
	private MFormAccess = null;
	private MRfQTopicSubscriber = null;
	private MForm = null;
	private MRfQTopicSubscriberOnly = null;
	private MGLCategory = null;
	private MRMA = null;
	private MGoal = null;
	private MRMALine = null;
	private MGoalRestriction = null;
	private MScheduler = null;
	private MGroup = null;
	private MSchedulerLog = null;
	private MHierarchy = null;
	private MSchedulerPara = null;
	private MIndex = null;
	private MSchedulerRecipient = null;
	private MIndexStop = null;
	private MSerNoCtl = null;
	private MInfoColumn = null;
	private MSetup = null;
	private MInfoWindow = null;
	private MShipper = null;
	private MInOutConfirm = null;
	private MSLACriteria = null;
	private MInOut = null;
	private MSLAGoal = null;
	private MInOutLineConfirm = null;
	private MSLAMeasure = null;
	private MInOutLine = null;
	private MStatusCategory = null;
	private MInOutLineMA = null;
	private MStatus = null;
	private MInterestArea = null;
	private MStorage = null;
	private MInventory = null;
	private MStore = null;
	private MInventoryLine = null;
	private MTask = null;
	private MInventoryLineMA = null;
	private MTaxCategory = null;
	private MInvoiceBatch = null;
	private MTaxDeclarationAcct = null;
	private MInvoiceBatchLine = null;
	private MTaxDeclaration = null;
	private MInvoice = null;
	private MTaxDeclarationLine = null;
	private MInvoiceLine = null;
	private MTax = null;
	private MInvoicePaySchedule = null;
	private MTaxPostal = null;
	private MInvoiceSchedule = null;
	private MTemplate = null;
	private MInvoiceTax = null;
	private MTimeExpense = null;
	private MJournalBatch = null;
	private MTimeExpenseLine = null;
	private MJournal = null;
	private MTransaction = null;
	private MJournalLine = null;
	private MTree = null;
	private MKCategory = null;
	private MTreeNode = null;
	private MLandedCostAllocation = null;
	private MultiMap = null;
	private MLandedCost = null;
	private MUOMConversion = null;
	private MLdapAccess = null;
	private MUOM = null;
	private MLdapProcessor = null;
	private MUserMail = null;
	private MLdapProcessorLog = null;
	private MWarehousePrice = null;
	private MLdapUser = null;
	private MWebProjectDomain = null;
	private MLotCtl = null;
	private MWebProject = null;
	private MLot = null;
	private MWithholding = null;
	private MMailMsg = null;
	private MYear = null;

	

	// from dbPort/src/org/compiere/model
	
	private MAccessLog = null;          
	private MIssueProject = null;
	private MRecordAccess = null;
	private MAccount = null;
	private MIssueSystem = null;
	private MRefList = null;
	private MAccountLookup = null;
	private MIssueUser = null;
	private MRegion = null;
	private MAcctSchemaDefault = null;
	private MLanguage = null;
	private M_Registration = null;
	private MAcctSchemaElement = null;
	private MLocation = null;
	private MRole = null;
	private MAcctSchemaGL = null;
	private MLocationLookup = null;
	private MRoleOrgAccess = null;
	private MAcctSchema = null;
	private MLocator = null;
	private MRoleTest = null;
	private MArchive = null;
	private MLocatorLookup = null;
	private MSalesRegion = null;
	private MAttachmentEntry = null;
	private MLookupCache = null;
	private MSequence = null;
	private MAttachment = null;
	private MLookupFactory = null;
	private MSession = null;
	private MAttachmentNote = null;
	private MLookupInfo = null;
	private MSysConfig = null;
	private MChangeLog = null;
	private MLookup = null;
	private MSystem = null;
	private MClientInfo = null;
	private MMenu = null;
	private MTab = null;
	private MClient = null;
	private MMessage = null;
	private MTableAccess = null;
	private MClientShare = null;
	private MNote = null;
	private MTable = null;
	private MColumnAccess = null;
	private ModelValidationEngine = null;
	private MTest = null;
	private MColumn = null;
	private ModelValidator = null;
	private MTree_Base = null;
	private MConversionRate = null;
	private MOrgInfo = null;
	private MTree_NodeBP = null;
	private MConversionType = null;
	private MOrg = null;
	private MTree_NodeCMC = null;
	private MCostElement = null;
	private MPackageExpCommon = null;
	private MTree_NodeCMS = null;
	private MCostType = null;
	private MPackageExpDetail = null;
	private MTree_Node = null;
	private MCountry = null;
	private MPackageExp = null;
	private MTree_NodeMM = null;
	private MCurrencyAcct = null;
	private MPAttributeLookup = null;
	private MTree_NodePR = null;
	private MCurrency = null;
	private MPInstance = null;
	private MUser = null;
	private MDocType = null;
	private MPInstanceLog = null;
	private MUserOrgAccess = null;
	private M_Element = null;
	private MPInstancePara = null;
	private MUserRoles = null;
	private MElement = null;
	private MPrivateAccess = null;
	private MWarehouse = null;
	private MElementValue = null;
	private MProcessAccess = null;
	private MWindowAccess = null;
	private MField = null;
	private MProcess = null;
	private MWindow = null;
	private MImage = null;
	private MProcessPara = null;
	private MIssue = null;
	private MQuery = null;
	
    public int getC_Region_ID(String Region) {
		String sql = "select c_region_id from c_region where name = ?";
		PreparedStatement pstmt = null;
		ResultSet rs = null;
	
		int C_Region_ID = -1;
		
	         try {
			pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, getTrxName());
			pstmt.setString(1, Region);
			rs = pstmt.executeQuery();
			
	
			while (rs.next()) {
				C_Region_ID = rs.getInt(1);
			}
		} catch (SQLException e) {
			fail(e.getLocalizedMessage());
		} finally {
			DB.close( rs, pstmt );
		}
	
	    return C_Region_ID;
    }

    public int getC_Country_ID(String Country) {
		String sql = "select c_country_id from c_country where name = ?";
		PreparedStatement pstmt = null;
		ResultSet rs = null;
	
		int C_Country_ID = -1;
		
	         try {
			pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, getTrxName());
			pstmt.setString(1, Country);
			rs = pstmt.executeQuery();
			
	
			while (rs.next()) {
				C_Country_ID = rs.getInt(1);
			}
		} catch (SQLException e) {
			fail(e.getLocalizedMessage());
		} finally {
			DB.close( rs, pstmt );
		}
	
	    return C_Country_ID;
    }

    public void testCreateMBPartner()
    {
    	try {
			m_partner = new MBPartner (getCtx(), 0, getTrxName());
			m_partner.setValue ("");
			m_partner.setName ("Test MBPartner");
			m_partner.setName2 (null);
			m_partner.setDUNS("");
			m_partner.setFirstSale(null);
			//
			m_partner.setSO_CreditLimit (Env.ZERO);
			m_partner.setSO_CreditUsed (Env.ZERO);
			m_partner.setTotalOpenBalance (Env.ZERO);
			//      s_m_partner.setRating(null);
			//
			m_partner.setActualLifeTimeValue(Env.ZERO);
			m_partner.setPotentialLifeTimeValue(Env.ZERO);
			m_partner.setAcqusitionCost(Env.ZERO);
			m_partner.setShareOfCustomer(0);
			m_partner.setSalesVolume(0);
	
			MBPGroup m_group = new MBPGroup (getCtx(), 0, getTrxName());
	        m_group.setName ("Test Group Name");  // N
	        m_group.setIsConfidentialInfo (false);  // N
	        m_group.setIsDefault (false);
	
	        m_group.setPriorityBase(MBPGroup.PRIORITYBASE_Same);
	
	        m_group.saveEx();
	
			m_partner.setBPGroup(m_group);
			// Reset Created, Updated to current system time ( teo_sarca )
			m_partner.saveEx();
	 
			commit();
    	} catch(Exception e) {
    		fail(e.getLocalizedMessage());
    	}

    } */
public void testBPartner() {
    MBPartner test = MBPartner.getBPartnerCashTrx(getCtx(), 11);
    assertTrue("Confirming right BPartner record", test.getC_BPartner_ID() == 112);
}
Also used : MBPartner(org.compiere.model.MBPartner)

Aggregations

MBPartner (org.compiere.model.MBPartner)97 BigDecimal (java.math.BigDecimal)30 ResultSet (java.sql.ResultSet)20 MLocation (org.compiere.model.MLocation)20 MBPartnerLocation (org.compiere.model.MBPartnerLocation)18 MOrder (org.compiere.model.MOrder)17 PreparedStatement (java.sql.PreparedStatement)16 MInvoice (org.compiere.model.MInvoice)15 MOrderLine (org.compiere.model.MOrderLine)14 AdempiereException (org.adempiere.exceptions.AdempiereException)13 MUser (org.compiere.model.MUser)12 SQLException (java.sql.SQLException)11 MDocType (org.compiere.model.MDocType)11 MInvoiceLine (org.compiere.model.MInvoiceLine)10 MOrg (org.compiere.model.MOrg)9 Query (org.compiere.model.Query)9 AdempiereUserError (org.compiere.util.AdempiereUserError)9 MClient (org.compiere.model.MClient)8 MWarehouse (org.compiere.model.MWarehouse)8 Timestamp (java.sql.Timestamp)6