Ejemplo n.º 1
0
  public I_AD_Org createOrg(final String name) {
    final I_AD_Org org = InterfaceWrapperHelper.create(ctx, I_AD_Org.class, ITrx.TRXNAME_None);
    org.setValue(name);
    org.setName(name);
    InterfaceWrapperHelper.save(org);

    final I_AD_OrgInfo orgInfo = InterfaceWrapperHelper.newInstance(I_AD_OrgInfo.class, org);
    orgInfo.setAD_Org_ID(org.getAD_Org_ID());

    //
    // InTransit Warehouse
    final I_M_Warehouse warehouseInTransit = createWarehouse(name + "_InTransit", org);
    warehouseInTransit.setIsInTransit(true);
    InterfaceWrapperHelper.save(warehouseInTransit);

    //
    // BP Org Link
    final I_C_BPartner bpartner = createBPartner("BPOrg_" + name);
    // bpartner.setAD_OrgBP_ID(String.valueOf(org.getAD_Org_ID()));
    bpartner.setAD_OrgBP_ID(org.getAD_Org_ID());
    InterfaceWrapperHelper.save(bpartner);
    //
    final I_C_BPartner_Location bpLocation = createBPLocation(bpartner);
    orgInfo.setOrgBP_Location(bpLocation);
    InterfaceWrapperHelper.save(orgInfo);

    return org;
  }
Ejemplo n.º 2
0
  public void markUnprocessed(final I_C_Queue_WorkPackage workpackage) {
    workpackage.setIsReadyForProcessing(false);
    InterfaceWrapperHelper.save(workpackage);

    workpackage.setProcessed(false);
    workpackage.setIsError(false);
    workpackage.setSkippedAt(null);
    workpackage.setAD_Issue(null);

    InterfaceWrapperHelper.save(workpackage);
  }
  private final void save(final I_C_TaxDeclarationLine taxDeclarationLine) {
    final int line = lineNoOffset_TaxDeclarationLine + (countLinesCreated + 1) * 10;

    taxDeclarationLine.setLine(line);
    InterfaceWrapperHelper.save(taxDeclarationLine);
    countLinesCreated++;
  }
Ejemplo n.º 4
0
  /**
   * Creates a dummy MRP firm demand.
   *
   * <p>NOTE:
   *
   * <ul>
   *   <li>DocStatus will be Completed
   *   <li>OrderType will be SalesOrder
   * </ul>
   *
   * @param product
   * @param qty
   * @param date
   * @param plant
   * @param warehouse
   * @return demand MRP record
   */
  public I_PP_MRP createMRPDemand(
      final I_M_Product product,
      final BigDecimal qty,
      final Date date,
      final I_S_Resource plant,
      final I_M_Warehouse warehouse,
      final I_C_BPartner bpartner) {
    final I_PP_MRP mrp = InterfaceWrapperHelper.newInstance(I_PP_MRP.class, contextProvider);
    mrp.setAD_Org_ID(warehouse.getAD_Org_ID());
    mrp.setS_Resource(plant);
    mrp.setM_Warehouse(warehouse);
    mrp.setC_BPartner(bpartner);
    //
    final Timestamp dateTS = TimeUtil.asTimestamp(date);
    mrp.setDatePromised(dateTS);
    mrp.setDateStartSchedule(dateTS);
    mrp.setDateFinishSchedule(dateTS);
    //
    mrp.setTypeMRP(X_PP_MRP.TYPEMRP_Demand);
    mrp.setDocStatus(X_PP_MRP.DOCSTATUS_Completed); // Firm Demand
    mrp.setOrderType(X_PP_MRP.ORDERTYPE_SalesOrder); // Sales Order
    mrp.setIsAvailable(true);
    //
    mrp.setM_Product(product);
    Services.get(IMRPBL.class).setQty(mrp, qty, qty, product.getC_UOM());
    //
    // mrp.setC_BPartner(C_BPartner);

    InterfaceWrapperHelper.save(mrp);

    return mrp;
  }
  private final I_C_TaxDeclarationAcct createTaxDeclarationAcct(
      final I_C_TaxDeclarationLine taxDeclarationLine, final I_Fact_Acct fact) {
    final I_C_TaxDeclaration taxDeclaration = getC_TaxDeclaration();

    final I_C_TaxDeclarationAcct taxDeclarationAcct =
        InterfaceWrapperHelper.create(
            getCtx(), I_C_TaxDeclarationAcct.class, ITrx.TRXNAME_ThreadInherited);
    taxDeclarationAcct.setAD_Org_ID(fact.getAD_Org_ID());
    taxDeclarationAcct.setC_TaxDeclaration(taxDeclaration);

    // Link to C_TaxDeclarationLine ONLY if the Fact_Acct record is about tax booking
    // NOTE: very important, reports are relying on this (e.g. see RV_TaxDeclarationLine)
    if (taxDeclarationLine != null && taxDeclarationLine.getC_Tax_ID() == fact.getC_Tax_ID()) {
      taxDeclarationAcct.setC_TaxDeclarationLine(taxDeclarationLine);
    } else {
      taxDeclarationAcct.setC_TaxDeclarationLine(null);
    }

    taxDeclarationAcct.setFact_Acct_ID(
        fact.getFact_Acct_ID()); // this FK shall block Fact_Acct to be deleted
    taxDeclarationAcct.setC_AcctSchema_ID(fact.getC_AcctSchema_ID());

    //
    // Save
    final int line = lineNoOffset_TaxDeclarationAcct + (countAcctLinesCreated + 1) * 10;
    taxDeclarationAcct.setLine(line);
    InterfaceWrapperHelper.save(taxDeclarationAcct);
    countAcctLinesCreated++;

    return taxDeclarationAcct;
  }
Ejemplo n.º 6
0
  @Override
  public void process(final I_C_OLCand olCand) throws Exception {
    if (olCand.isProcessed()) {
      result.incSkipped();
      return;
    }

    final IParams params = processorCtx.getParams();
    Check.errorIf(params == null, "Given processorCtx {0} needs to contain params", processorCtx);

    // Partner
    final int bpartnerId = params.getParameterAsInt(I_C_OLCand.COLUMNNAME_C_BPartner_Override_ID);
    olCand.setC_BPartner_Override_ID(bpartnerId);

    // Location
    final int bpartnerLocationId =
        params.getParameterAsInt(I_C_OLCand.COLUMNNAME_C_BP_Location_Override_ID);
    olCand.setC_BP_Location_Override_ID(bpartnerLocationId);

    // DatePrommissed
    final Timestamp datePromissed =
        params.getParameterAsTimestamp(I_C_OLCand.COLUMNNAME_DatePromised_Override);
    olCand.setDatePromised_Override(datePromissed);

    InterfaceWrapperHelper.save(olCand);
    result.incUpdated();
  }
Ejemplo n.º 7
0
  /**
   * Recalculate order tax
   *
   * @param oldTax true if the old C_Tax_ID should be used
   * @return true if success, false otherwise
   * @author teo_sarca [ 1583825 ]
   */
  private boolean updateOrderTax(final boolean oldTax) {
    // NOTE: keep in sync with org.compiere.model.MInvoiceLine.updateInvoiceTax(boolean)

    final String trxName = get_TrxName();
    final int taxPrecision = getPrecision();
    final MOrderTax tax = MOrderTax.get(this, taxPrecision, oldTax, trxName);
    if (tax == null) {
      return true;
    }

    if (!tax.calculateTaxFromLines()) {
      return false;
    }

    //
    // If tax has invoice lines behind => fine, save it
    if (tax.isActive()) {
      InterfaceWrapperHelper.save(tax, trxName);
    }
    // Tax has no longer any invoice lines behind => deleted it if it's not new
    else {
      if (!InterfaceWrapperHelper.isNew(tax)) {
        InterfaceWrapperHelper.delete(tax);
      }
    }

    return true;
  }
Ejemplo n.º 8
0
  private void setupContext(final boolean initEnvironment) {
    ctx = Env.getCtx();
    trxName = ITrx.TRXNAME_None;

    //
    // Setup context: #AD_Client_ID
    int adClientId = Env.getAD_Client_ID(ctx);
    if (adClientId <= 0) {
      adClient = InterfaceWrapperHelper.create(ctx, I_AD_Client.class, ITrx.TRXNAME_None);
      InterfaceWrapperHelper.save(adClient);
      adClientId = adClient.getAD_Client_ID();
      Env.setContext(ctx, Env.CTXNAME_AD_Client_ID, adClientId);
    } else {
      adClient =
          InterfaceWrapperHelper.create(ctx, adClientId, I_AD_Client.class, ITrx.TRXNAME_None);
    }

    int adOrgId = Env.getAD_Org_ID(ctx);
    if (adOrgId <= 0) {
      adOrg01 = createOrg("Org01");
      adOrgId = adOrg01.getAD_Org_ID();
      Env.setContext(ctx, Env.CTXNAME_AD_Org_ID, adOrgId);
    } else {
      adOrg01 = InterfaceWrapperHelper.create(ctx, adOrgId, I_AD_Org.class, ITrx.TRXNAME_None);
    }

    SystemTime.setTimeSource(
        new TimeSource() {
          @Override
          public long millis() {
            return _today.getTime();
          }
        });
  }
Ejemplo n.º 9
0
  public I_AD_WF_Node createWorkflowNode(
      final I_AD_Workflow wf, final String nodeName, final boolean startNode) {
    final I_AD_WF_Node node =
        InterfaceWrapperHelper.newInstance(I_AD_WF_Node.class, contextProvider);
    node.setAD_Workflow_ID(wf.getAD_Workflow_ID());
    node.setValue(nodeName);
    node.setName(nodeName);

    InterfaceWrapperHelper.save(node);

    if (startNode) {
      wf.setAD_WF_Node_ID(node.getAD_WF_Node_ID());
      InterfaceWrapperHelper.save(wf);
    }

    return node;
  }
Ejemplo n.º 10
0
 public I_C_BP_Group createBPGroup(final String name) {
   final I_C_BP_Group bpGroup =
       InterfaceWrapperHelper.newInstance(I_C_BP_Group.class, contextProvider);
   bpGroup.setValue(name);
   bpGroup.setName(name);
   InterfaceWrapperHelper.save(bpGroup);
   return bpGroup;
 }
Ejemplo n.º 11
0
  public I_M_Shipper createShipper(final I_C_BPartner bpartner) {
    final I_M_Shipper shipper =
        InterfaceWrapperHelper.newInstance(I_M_Shipper.class, contextProvider);
    shipper.setName(bpartner.getName());
    shipper.setC_BPartner_ID(bpartner.getC_BPartner_ID());

    InterfaceWrapperHelper.save(shipper);
    return shipper;
  }
Ejemplo n.º 12
0
 public void createMRPMessage(final String code) {
   final I_AD_Message message =
       InterfaceWrapperHelper.newInstance(I_AD_Message.class, contextProvider);
   InterfaceWrapperHelper.setValue(message, "AD_Client_ID", 0);
   message.setAD_Org_ID(0);
   message.setValue(code);
   message.setMsgText(code);
   InterfaceWrapperHelper.save(message);
 }
Ejemplo n.º 13
0
  public I_M_Product_Category createProductCategory(final String name) {
    final I_M_Product_Category productCategory =
        InterfaceWrapperHelper.newInstance(I_M_Product_Category.class, contextProvider);
    productCategory.setValue(name);
    productCategory.setName(name);
    InterfaceWrapperHelper.save(productCategory);

    return productCategory;
  }
Ejemplo n.º 14
0
 public I_AD_Workflow createWorkflow(final String name) {
   final I_AD_Workflow wf =
       InterfaceWrapperHelper.newInstance(I_AD_Workflow.class, contextProvider);
   wf.setValue(name);
   wf.setName(name);
   wf.setWorkflowType(X_AD_Workflow.WORKFLOWTYPE_Manufacturing);
   InterfaceWrapperHelper.save(wf);
   return wf;
 }
Ejemplo n.º 15
0
  private final I_M_HU createHU_InTrx(final I_M_HU_Item parentHUItem) {
    //
    // Get HUStatus to set
    final String huStatus;
    if (isHUStatusSet()) {
      huStatus = getHUStatus();
    } else if (parentHUItem != null) {
      huStatus = parentHUItem.getM_HU().getHUStatus();
    } else {
      huStatus = null;
    }

    //
    // Get M_Locator to set
    final I_M_Locator locator;
    if (_locatorSet) {
      locator = _locator;
    } else if (parentHUItem != null) {
      locator = parentHUItem.getM_HU().getM_Locator();
    } else {
      locator = null;
    }

    //
    // Create and save HU
    final I_M_HU hu = InterfaceWrapperHelper.newInstance(I_M_HU.class, getContext());
    POJOWrapper.setInstanceName(hu, _instanceName);
    hu.setM_HU_PI_Version(getM_HU_PI_Version());
    hu.setM_HU_Item_Parent(parentHUItem);
    hu.setC_BPartner(_bpartner);
    hu.setC_BPartner_Location(_bpartnerLocation);
    hu.setHUStatus(huStatus);
    hu.setM_Locator(locator);
    InterfaceWrapperHelper.save(hu);

    //
    // Create HU Attributes
    if (attributesExpectations != null) {
      attributesExpectations.createHUAttributes(hu);
    }

    //
    // Create HU Items
    if (huItemExpectations != null) {
      for (final HUItemExpectation<HUExpectation<ParentExpectationType>> huItemExpectation :
          huItemExpectations) {
        huItemExpectation.createHUItem(hu);
      }
    }

    // Capture the HU if required
    if (_huToSetRef != null) {
      _huToSetRef.setValue(hu);
    }

    return hu;
  }
Ejemplo n.º 16
0
 public I_C_Queue_Processor createQueueProcessor(
     final String name, final int poolSize, final int maxPoolSize, final int keepAliveTimeMillis) {
   final I_C_Queue_Processor queueProcessorDef =
       InterfaceWrapperHelper.create(ctx, I_C_Queue_Processor.class, ITrx.TRXNAME_None);
   queueProcessorDef.setName(name);
   queueProcessorDef.setPoolSize(poolSize);
   queueProcessorDef.setKeepAliveTimeMillis(keepAliveTimeMillis);
   InterfaceWrapperHelper.save(queueProcessorDef);
   return queueProcessorDef;
 }
Ejemplo n.º 17
0
  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;
  }
Ejemplo n.º 18
0
 public I_C_UOM createUOM(final String name, final int stdPrecision) {
   final I_C_UOM uom = InterfaceWrapperHelper.newInstance(I_C_UOM.class, contextProvider);
   uom.setName(name);
   uom.setUOMSymbol(name);
   uom.setX12DE355(name);
   uom.setStdPrecision(stdPrecision);
   uom.setCostingPrecision(0);
   InterfaceWrapperHelper.save(uom);
   return uom;
 }
Ejemplo n.º 19
0
  public I_C_Queue_PackageProcessor createPackageProcessor(
      Properties ctx,
      Class<? extends IWorkpackageProcessor> packageProcessorClass,
      String trxName) {
    final I_C_Queue_PackageProcessor packageProcessorDef =
        InterfaceWrapperHelper.create(ctx, I_C_Queue_PackageProcessor.class, trxName);
    packageProcessorDef.setClassname(packageProcessorClass.getCanonicalName());
    InterfaceWrapperHelper.save(packageProcessorDef);

    return packageProcessorDef;
  }
Ejemplo n.º 20
0
 public I_C_BPartner_Location createBPLocation(final I_C_BPartner bpartner) {
   final I_C_BPartner_Location bpLocation =
       InterfaceWrapperHelper.newInstance(I_C_BPartner_Location.class, bpartner);
   bpLocation.setC_BPartner_ID(bpartner.getC_BPartner_ID());
   bpLocation.setIsBillToDefault(true);
   bpLocation.setIsBillTo(true);
   bpLocation.setIsShipToDefault(true);
   bpLocation.setIsShipTo(true);
   InterfaceWrapperHelper.save(bpLocation);
   return bpLocation;
 }
Ejemplo n.º 21
0
  public I_S_ResourceType createResourceType(final String name) {
    final I_S_ResourceType resourceType =
        InterfaceWrapperHelper.newInstance(I_S_ResourceType.class, contextProvider);
    resourceType.setIsActive(true);
    resourceType.setName(name);
    resourceType.setValue(name);
    resourceType.setIsDateSlot(false);
    resourceType.setIsTimeSlot(false);
    InterfaceWrapperHelper.save(resourceType);

    return resourceType;
  }
Ejemplo n.º 22
0
  public void assignPackageProcessor(
      final I_C_Queue_Processor queueProcessorDef,
      final I_C_Queue_PackageProcessor packageProcessorDef) {
    final Properties ctx = InterfaceWrapperHelper.getCtx(queueProcessorDef);
    final String trxName = InterfaceWrapperHelper.getTrxName(queueProcessorDef);

    final I_C_Queue_Processor_Assign assignment =
        InterfaceWrapperHelper.create(ctx, I_C_Queue_Processor_Assign.class, trxName);
    assignment.setC_Queue_Processor(queueProcessorDef);
    assignment.setC_Queue_PackageProcessor(packageProcessorDef);
    InterfaceWrapperHelper.save(assignment);
  }
Ejemplo n.º 23
0
  private void test_GuaranteedPOBufferedIterator_changingData(final String trxName)
      throws Exception {
    final Properties ctx = Env.getCtx();

    for (int i = 1; i <= 100; i++) {
      createTestRecord(i, trxName);
    }

    final int iteratorBufferSize = 10;

    final TypedSqlQuery<I_Test> query =
        new TypedSqlQuery<I_Test>(
                ctx, I_Test.class, I_Test.COLUMNNAME_T_Integer + " BETWEEN ? AND ?", trxName)
            .setParameters(20, 60)
            .setOption(Query.OPTION_IteratorBufferSize, iteratorBufferSize)
            .setOrderBy(I_Test.COLUMNNAME_T_Integer);

    final List<I_Test> expectedList = query.list(I_Test.class);
    Assert.assertEquals(60 - 20 + 1, expectedList.size());
    for (int i = 0; i < expectedList.size(); i++) {
      final I_Test item = expectedList.get(i);
      final int expectedInt = 20 + i;
      Assert.assertEquals("Invalid item: " + item, expectedInt, item.getT_Integer());
    }

    @SuppressWarnings("unchecked")
    final POBufferedIterator<I_Test, I_Test> itNotGuaranteed =
        (POBufferedIterator<I_Test, I_Test>) query.iterate(I_Test.class, false);
    Assert.assertEquals(
        "BufferSize not set for " + itNotGuaranteed,
        iteratorBufferSize,
        itNotGuaranteed.getBufferSize());

    @SuppressWarnings("unchecked")
    final GuaranteedPOBufferedIterator<I_Test, I_Test> itGuaranteed =
        (GuaranteedPOBufferedIterator<I_Test, I_Test>) query.iterate(I_Test.class, true);
    Assert.assertEquals(
        "BufferSize not set for " + itGuaranteed, iteratorBufferSize, itGuaranteed.getBufferSize());

    // Change item value (which is included in where clause) and item is not in first buffer:
    {
      final I_Test item = expectedList.get(30);
      item.setT_Integer(10000 + item.getT_Integer());
      InterfaceWrapperHelper.save(item);
    }

    final List<I_Test> itGuaranteedList = getList(itGuaranteed);
    Assert.assertEquals("Guaranteed list shall not be changed", expectedList, itGuaranteedList);

    final List<I_Test> itNotGuaranteedList = getList(itNotGuaranteed);
    Assert.assertThat(
        "Not guaranteed list shall be changed", expectedList, not(equalTo(itNotGuaranteedList)));
  }
Ejemplo n.º 24
0
  public I_M_Warehouse createWarehouse(
      final String name, final I_AD_Org org, final I_S_Resource plant) {
    final I_M_Warehouse warehouse =
        InterfaceWrapperHelper.newInstance(I_M_Warehouse.class, contextProvider);
    warehouse.setAD_Org_ID(org.getAD_Org_ID());
    warehouse.setValue(name);
    warehouse.setName(name);
    warehouse.setIsInTransit(false);
    warehouse.setPP_Plant(plant);
    InterfaceWrapperHelper.save(warehouse);

    return warehouse;
  }
Ejemplo n.º 25
0
  public I_M_Product createProduct(final String name, final I_C_UOM uom) {
    final I_M_Product product =
        InterfaceWrapperHelper.newInstance(I_M_Product.class, contextProvider);
    product.setValue(name);
    product.setName(name);
    product.setM_Product_Category_ID(
        productCategoryDefault == null ? -1 : productCategoryDefault.getM_Product_Category_ID());
    product.setC_UOM_ID(uom.getC_UOM_ID());
    product.setLowLevel(0);
    InterfaceWrapperHelper.save(product);

    return product;
  }
Ejemplo n.º 26
0
  public I_C_BPartner createBPartner(final String name) {
    final I_C_BPartner bpartner =
        InterfaceWrapperHelper.newInstance(I_C_BPartner.class, contextProvider);
    bpartner.setValue(name);
    bpartner.setName(name);
    bpartner.setIsCustomer(true);
    bpartner.setIsVendor(true);
    bpartner.setAD_OrgBP_ID(-1);
    bpartner.setC_BP_Group_ID(bpGroupDefault == null ? -1 : bpGroupDefault.getC_BP_Group_ID());

    InterfaceWrapperHelper.save(bpartner);
    return bpartner;
  }
  @Before
  public void beforeTest() {
    //
    // Create a dummy attribute
    AdempiereTestHelper.get()
        .init(); // NOTE: the only reason why we init adempiere is because we need to create 1
                 // f*****g attribute
    attribute = InterfaceWrapperHelper.create(Env.getCtx(), I_M_Attribute.class, ITrx.TRXNAME_None);
    InterfaceWrapperHelper.save(attribute);

    //
    // Create splitter strategy
    splitter = new LinearDistributionAttributeSplitterStrategy();
  }
 @Override
 public void save(
     final I_M_HU_LUTU_Configuration lutuConfiguration,
     final boolean disableChangeCheckingOnSave) {
   final Object disableChangeCheckingOnSaveOld =
       InterfaceWrapperHelper.setDynAttribute(
           lutuConfiguration, DYNATTR_DisableChangeCheckingOnSave, disableChangeCheckingOnSave);
   try {
     InterfaceWrapperHelper.save(lutuConfiguration);
   } finally {
     InterfaceWrapperHelper.setDynAttribute(
         lutuConfiguration, DYNATTR_DisableChangeCheckingOnSave, disableChangeCheckingOnSaveOld);
   }
 }
Ejemplo n.º 29
0
  /**
   * Simulate receiving from an manufacturing order
   *
   * @param ppOrder
   * @param qtyToReceive
   */
  public void receiveFromPPOrder(final I_PP_Order ppOrder, final BigDecimal qtyToReceive) {
    //
    // Receive from MO: i.e. increase QtyDelivered
    final BigDecimal qtyDeliveredOld = ppOrder.getQtyDelivered();
    final BigDecimal qtyDelivered = qtyDeliveredOld.add(qtyToReceive);
    ppOrder.setQtyDelivered(qtyDelivered);
    InterfaceWrapperHelper.save(ppOrder);

    //
    // Add received qty to QtyOnHand
    final I_M_Warehouse warehouse = ppOrder.getM_Warehouse();
    final I_M_Product product = ppOrder.getM_Product();
    mrpDAO.addQtyOnHand(warehouse, product, qtyToReceive);
  }
Ejemplo n.º 30
0
 private I_PP_Cost_Collector createVarianceCostCollector(
     I_PP_Cost_Collector cc, String CostCollectorType) {
   final I_PP_Cost_Collector ccv =
       InterfaceWrapperHelper.newInstance(I_PP_Cost_Collector.class, cc);
   InterfaceWrapperHelper.copyValues(cc, ccv);
   ccv.setProcessing(false);
   ccv.setProcessed(false);
   ccv.setDocStatus(X_PP_Cost_Collector.DOCSTATUS_Drafted);
   ccv.setDocAction(X_PP_Cost_Collector.DOCACTION_Complete);
   ccv.setCostCollectorType(CostCollectorType);
   ccv.setDocumentNo(null); // reset
   cc.setPP_Cost_Collector_Parent(cc); // link to parent
   InterfaceWrapperHelper.save(ccv);
   return ccv;
 }