Пример #1
0
 public static int procesProduction(
     MProduction production, Timestamp movementDate, boolean mustBeStocked) {
   ProcessInfo pi = MWorkflow.runDocumentActionWorkflow(production, "CO");
   if (pi.isError()) {
     throw new RuntimeException(pi.getSummary());
   } else {
     if (production.isUseProductionPlan()) {
       Query planQuery =
           new Query(
               Env.getCtx(),
               I_M_ProductionPlan.Table_Name,
               "M_ProductionPlan.M_Production_ID=?",
               production.get_TrxName());
       List<MProductionPlan> plans =
           planQuery.setParameters(production.getM_Production_ID()).list();
       int linesCount = 0;
       for (MProductionPlan plan : plans) {
         MProductionLine[] lines = plan.getLines();
         linesCount += lines.length;
       }
       return linesCount;
     } else {
       return production.getLines().length;
     }
   }
 }
Пример #2
0
  protected void updateHelpWidthPreference(String width) {

    if (width != null) {
      Query query =
          new Query(
              Env.getCtx(),
              MTable.get(Env.getCtx(), I_AD_Preference.Table_ID),
              " Attribute=? AND AD_User_ID=? AND AD_Process_ID IS NULL AND PreferenceFor = 'W'",
              null);

      int userId = Env.getAD_User_ID(Env.getCtx());
      MPreference preference =
          query
              .setOnlyActiveRecords(true)
              .setApplyAccessFilter(true)
              .setParameters("HelpController.Width", userId)
              .first();

      if (preference == null || preference.getAD_Preference_ID() <= 0) {

        preference = new MPreference(Env.getCtx(), 0, null);
        preference.set_ValueOfColumn("AD_User_ID", userId); // required set_Value for System=0 user
        preference.setAttribute("HelpController.Width");
      }
      preference.setValue(width);
      preference.saveEx();
    }
  }
Пример #3
0
 @Test
 public void testAggregate() throws Exception {
   final String sqlFrom = "FROM C_InvoiceLine WHERE IsActive='Y'";
   final Query query =
       new Query(getCtx(), "C_InvoiceLine", null, getTrxName()).setOnlyActiveRecords(true);
   //
   // Test COUNT:
   assertEquals(
       "COUNT not match",
       DB.getSQLValueBDEx(getTrxName(), "SELECT COUNT(*) " + sqlFrom),
       query.aggregate(null, Query.AGGREGATE_COUNT));
   //
   // Test SUM:
   assertEquals(
       "SUM not match",
       DB.getSQLValueBDEx(getTrxName(), "SELECT COALESCE(SUM(LineNetAmt+TaxAmt),0) " + sqlFrom),
       query.aggregate("LineNetAmt+TaxAmt", Query.AGGREGATE_SUM));
   //
   // Test MIN:
   assertEquals(
       "MIN not match",
       DB.getSQLValueBDEx(getTrxName(), "SELECT MIN(LineNetAmt) " + sqlFrom),
       query.aggregate("LineNetAmt", Query.AGGREGATE_MIN));
   //
   // Test MAX:
   assertEquals(
       "MAX not match",
       DB.getSQLValueBDEx(getTrxName(), "SELECT MAX(LineNetAmt) " + sqlFrom),
       query.aggregate("LineNetAmt", Query.AGGREGATE_MAX));
   //
   // Test aggregate (String) - FR [ 2726447 ]
   assertEquals(
       "MAX not match (String)",
       DB.getSQLValueStringEx(getTrxName(), "SELECT MAX(Description) " + sqlFrom),
       query.aggregate("Description", Query.AGGREGATE_MAX, String.class));
   //
   // Test aggregate (Timestamp) - FR [ 2726447 ]
   assertEquals(
       "MAX not match (Timestamp)",
       DB.getSQLValueTSEx(getTrxName(), "SELECT MAX(Updated) " + sqlFrom),
       query.aggregate("Updated", Query.AGGREGATE_MAX, Timestamp.class));
 }
Пример #4
0
  @Test
  public void test_addWhereClause() throws Exception {
    final String whereClause = "TableName IN (?,?)";
    final Query query =
        new Query(getCtx(), "AD_Table", whereClause, getTrxName())
            .setParameters(new Object[] {"C_Invoice", "M_InOut"})
            .setOrderBy("TableName");
    {
      final I_AD_Table table = query.first(I_AD_Table.class);
      assertEquals("Invalid object", "C_Invoice", table.getTableName());
    }

    Assert.assertNotSame("Query shall be cloned", query, query.addWhereClause(true, null));
    Assert.assertNotSame("Query shall be cloned", query, query.addWhereClause(false, null));
    Assert.assertNotSame("Query shall be cloned", query, query.addWhereClause(true, ""));
    Assert.assertNotSame("Query shall be cloned", query, query.addWhereClause(true, "   "));

    {
      final String whereClause2 = "TableName='M_InOut'";
      final Query query2 = query.addWhereClause(true, whereClause2);
      Assert.assertNotSame("New query shall be created", query, query2);

      Assert.assertEquals(
          "Invalid whereClause was build",
          "(" + whereClause + ") AND (" + whereClause2 + ")",
          query2.getWhereClause());

      final I_AD_Table table = query2.first(I_AD_Table.class);
      assertEquals("Invalid object", "M_InOut", table.getTableName());
    }

    {
      final String whereClause2 = "TableName='M_InOut'";
      final Query query2 = query.addWhereClause(false, whereClause2);
      Assert.assertNotSame("New query shall be created", query, query2);

      Assert.assertEquals(
          "Invalid whereClause was build",
          "(" + whereClause + ") OR (" + whereClause2 + ")",
          query2.getWhereClause());

      final I_AD_Table table = query2.first(I_AD_Table.class);
      assertEquals("Invalid object", "C_Invoice", table.getTableName());
    }
  }