public I_C_DocType createDocType(final String docBaseType) { final I_C_DocType docType = InterfaceWrapperHelper.newInstance(I_C_DocType.class, contextProvider); docType.setAD_Org_ID(adOrg01.getAD_Org_ID()); docType.setDocBaseType(docBaseType); docType.setName(docBaseType); InterfaceWrapperHelper.save(docType); return docType; }
@Override public I_C_DocType createDocType( final Properties ctx, final String entityType, final String Name, final String PrintName, final String DocBaseType, final String DocSubType, final int C_DocTypeShipment_ID, final int C_DocTypeInvoice_ID, final int StartNo, final int GL_Category_ID, final String trxName) { final MSequence sequence; if (StartNo != 0) { sequence = new MSequence(ctx, Env.getAD_Client_ID(ctx), Name, StartNo, trxName); sequence.saveEx(); } else { sequence = null; } final MDocType dt = new MDocType(ctx, DocBaseType, Name, trxName); if (PrintName != null && PrintName.length() > 0) { dt.setPrintName(PrintName); // Defaults to Name } if (DocSubType != null) { dt.setDocSubType(DocSubType); } if (C_DocTypeShipment_ID != 0) { dt.setC_DocTypeShipment_ID(C_DocTypeShipment_ID); } if (C_DocTypeInvoice_ID != 0) { dt.setC_DocTypeInvoice_ID(C_DocTypeInvoice_ID); } if (GL_Category_ID != 0) { dt.setGL_Category_ID(GL_Category_ID); } if (sequence == null) { dt.setIsDocNoControlled(false); } else { dt.setIsDocNoControlled(true); dt.setDocNoSequence_ID(sequence.getAD_Sequence_ID()); } dt.setIsSOTrx(); final I_C_DocType result = POWrapper.create(dt, I_C_DocType.class); result.setEntityType(entityType); return result; } // createDocType
private final String getDocBaseType() { Check.assume(_docTypeSet, "DocType or DocbaseType was set"); if (_docType != null) { return _docType.getDocBaseType(); } else if (_docBaseType != null) { return _docBaseType; } else { // throw new AdempiereException("DocBaseType not found"); // can be null return null; } }
/** * Creates a counter document for an order. The counter document is also processed, if there is a * {@link I_C_DocTypeCounter} with a <code>DocAction</code> configured. * * <p>This implementation partially uses legacy code. I didn't yet get to refactor/remove/replace * it all. */ @Override public DocAction createCounterDocument(final DocAction document) { final I_C_Order order = InterfaceWrapperHelper.create(document, I_C_Order.class); final MOrder orderPO = LegacyAdapters.convertToPO(order); final I_C_DocType counterDocType = retrieveCounterDocTypeOrNull(document); final I_AD_Org counterOrg = retrieveCounterOrgOrNull(document); final de.metas.adempiere.model.I_C_Order counterOrder = InterfaceWrapperHelper.newInstance( de.metas.adempiere.model.I_C_Order.class, document.getCtx()); final MOrder counterOrderPO = (MOrder) LegacyAdapters.convertToPO(counterOrder); counterOrder.setAD_Org(counterOrg); // 09700 // counterOrder.setC_DocTypeTarget(counterDocType); counterOrder.setIsSOTrx(counterDocType.isSOTrx()); // the new order needs to figure out the pricing by itself counterOrder.setM_PricingSystem(null); counterOrder.setM_PriceList(null); counterOrder.setDateOrdered(order.getDateOrdered()); counterOrder.setDateAcct(order.getDateAcct()); counterOrder.setDatePromised(order.getDatePromised()); counterOrder.setRef_Order_ID(order.getC_Order_ID()); final I_C_BPartner counterBP = retrieveCounterPartnerOrNull(document); counterOrderPO.setBPartner(counterBP); final I_M_Warehouse counterWarehouse = Services.get(IWarehouseAdvisor.class).evaluateOrderWarehouse(counterOrder); counterOrder.setM_Warehouse(counterWarehouse); // References (should not be required) counterOrder.setSalesRep_ID(order.getSalesRep_ID()); InterfaceWrapperHelper.save(counterOrder); // copy the order lines final boolean counter = true; final boolean copyASI = true; counterOrderPO.copyLinesFrom(orderPO, counter, copyASI); // Update copied lines final boolean requery = true; final MOrderLine[] counterLines = counterOrderPO.getLines(requery, null); for (int i = 0; i < counterLines.length; i++) { final MOrderLine counterLine = counterLines[i]; counterLine.setOrder(counterOrderPO); // copies header values (BP, etc.) counterLine.setPrice(); counterLine.setTax(); InterfaceWrapperHelper.save(counterLine); } logger.debug(counterOrder.toString()); // Document Action final MDocTypeCounter counterDT = MDocTypeCounter.getCounterDocType(document.getCtx(), order.getC_DocType_ID()); if (counterDT != null) { if (counterDT.getDocAction() != null) { counterOrder.setDocAction(counterDT.getDocAction()); Services.get(IDocActionBL.class) .processEx( counterOrder, counterDT.getDocAction(), null); // not expecting a particular docStatus (e.g. for prepay orders, it might be // "waiting to payment") } } return counterOrderPO; }
/** * Invoke the form VCreateFromPackage * * @param ctx context * @param WindowNo window no * @param mTab tab * @param mField field * @param value value * @return null or error message */ public String createFrom( final Properties ctx, final int WindowNo, final GridTab mTab, final GridField mField, final Object value) { final I_C_Invoice invoice = InterfaceWrapperHelper.create(mTab, I_C_Invoice.class); if (invoice.getC_Invoice_ID() <= 0) { return ""; } final I_C_DocType dt = invoice.getC_DocTypeTarget(); if (!Constants.DOCBASETYPE_AEInvoice.equals(dt.getDocBaseType()) || !CommissionConstants.COMMISSON_INVOICE_DOCSUBTYPE_CORRECTION.equals( dt.getDocSubType())) { // nothing to do final IDocumentPA docPA = Services.get(IDocumentPA.class); final I_C_DocType dtCorr = docPA.retrieve( ctx, invoice.getAD_Org_ID(), Constants.DOCBASETYPE_AEInvoice, CommissionConstants.COMMISSON_INVOICE_DOCSUBTYPE_CORRECTION, true, null); if (dtCorr != null) { final String msg = Msg.getMsg( ctx, MSG_INVOICECORR_CREATEFROM_WRONG_DOCTYPE_1P, new Object[] {dtCorr.getName()}); return msg; } else { throw new AdempiereException( "Missing C_DocType with DocBaseType='" + Constants.DOCBASETYPE_AEInvoice + "' and DocSubType='" + CommissionConstants.COMMISSON_INVOICE_DOCSUBTYPE_CORRECTION + "'"); } } final String swingclassname = "de.metas.commission.form.VCreateCorrections"; final String zkclassname = "not.yet.implemented"; final String classname; if (Ini.isClient()) { classname = swingclassname; } else { classname = zkclassname; return ""; } ICreateFrom cf = null; Class cl; try { if (Ini.isClient()) { cl = Class.forName(classname); } else { cl = Thread.currentThread().getContextClassLoader().loadClass(classname); } } catch (final ClassNotFoundException e) { log.error(e.getLocalizedMessage(), e); return e.getLocalizedMessage(); } if (cl != null) { try { java.lang.reflect.Constructor<? extends ICreateFrom> ctor = cl.getConstructor(I_C_Invoice.class, int.class); cf = ctor.newInstance(invoice, WindowNo); } catch (Throwable e) { log.error(e.getLocalizedMessage(), e); return e.getLocalizedMessage(); } } if (cf != null) { if (cf.isInitOK()) { cf.showWindow(); cf.closeWindow(); mTab.dataRefresh(); } else cf.closeWindow(); } return ""; } // createShippingPackages