/**
  * Get from Cache
  *
  * @param ctx context
  * @param M_Product_Category_ID id
  * @return category or null
  */
 public static MProductCategory get(Properties ctx, int M_Product_Category_ID) {
   if (M_Product_Category_ID <= 0) {
     return null;
   }
   final I_M_Product_Category pc =
       InterfaceWrapperHelper.create(
           ctx, M_Product_Category_ID, I_M_Product_Category.class, ITrx.TRXNAME_None);
   return LegacyAdapters.convertToPO(pc);
 } //	get
예제 #2
0
 private void processCostDetail(I_M_CostDetail cd) {
   if (!cd.isProcessed()) {
     final Properties ctx = InterfaceWrapperHelper.getCtx(cd);
     final I_C_AcctSchema as = MAcctSchema.get(ctx, cd.getC_AcctSchema_ID());
     final I_AD_Client client = MClient.get(ctx, as.getAD_Client_ID());
     if (client.isCostImmediate()) {
       final MCostDetail cdPO = LegacyAdapters.convertToPO(cd);
       cdPO.process();
     }
   }
 }
예제 #3
0
  private void createTestModel0(final I_EXP_Format exportFormat) throws Exception {
    final File directory = getTestModelDirectory();
    final File file = new File(directory, getTestModelFileName(exportFormat));

    final ExportHelper expHelper = new ExportHelper(getCtx(), getAD_Client_ID());
    final IReplicationAccessContext racCtx =
        new ReplicationAccessContext(10, false); // TODO hardcoded

    final Document doc =
        expHelper.exportRecord(
            (MEXPFormat) LegacyAdapters.convertToPO(exportFormat),
            "",
            MReplicationStrategy.REPLICATION_TABLE,
            X_AD_ReplicationTable.REPLICATIONTYPE_Merge,
            ModelValidator.TYPE_AFTER_CHANGE,
            racCtx);
    if (doc == null) {
      addLog(
          "Not creating test XML for format '"
              + exportFormat.getName()
              + "', because with AD_Client_ID="
              + getAD_Client_ID()
              + "the system can't access any '"
              + exportFormat.getAD_Table().getName()
              + "'-record");
      return;
    }
    // Save the document to the disk file
    final TransformerFactory tranFactory = TransformerFactory.newInstance();

    final Transformer aTransformer = tranFactory.newTransformer();
    aTransformer.setOutputProperty(OutputKeys.METHOD, "xml");
    aTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
    final Source src = new DOMSource(doc);

    // =================================== Write to String
    final Writer writer = new StringWriter();
    final Result dest2 = new StreamResult(writer);
    aTransformer.transform(src, dest2);
    // =================================== Write to Disk
    try {
      final Result dest = new StreamResult(file);
      aTransformer.transform(src, dest);
      writer.flush();
      writer.close();

    } catch (TransformerException ex) {
      ex.printStackTrace();
      throw ex;
    }
    addLog("Created test model: " + file);
  }
예제 #4
0
 /**
  * Get Parent
  *
  * @return parent
  */
 public MOrder getParent() {
   return LegacyAdapters.convertToPO(getC_Order());
 } // getParent
  /**
   * 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;
  }