Ejemplo n.º 1
0
  /**
   * Descripción de Método
   *
   * @return
   * @throws Exception
   */
  protected String doIt() throws Exception {
    // JOptionPane.showMessageDialog( null,"En CopyFromOrder.doit() :=","-...Fin",
    // JOptionPane.INFORMATION_MESSAGE );
    int To_C_Order_ID = getRecord_ID();

    log.info("From C_Order_ID=" + p_C_Order_ID + " to " + To_C_Order_ID);

    if (To_C_Order_ID == 0) {
      throw new IllegalArgumentException("Target C_Order_ID == 0");
    }

    // Buscar el pedido de la factura
    MInvoice invoice = null;
    if (p_C_Invoice_ID != 0 && p_C_Order_ID == 0) {
      invoice = new MInvoice(getCtx(), p_C_Invoice_ID, get_TrxName());
      p_C_Order_ID = invoice.getC_Order_ID();
    }

    if (p_C_Order_ID == 0) {
      throw new IllegalArgumentException("Source C_Order_ID == 0");
    }

    MOrder from = new MOrder(getCtx(), p_C_Order_ID, get_TrxName());
    MOrder to = new MOrder(getCtx(), To_C_Order_ID, get_TrxName());

    // Si el tipo de documento del order from es un presupuesto vencido, hay
    // que verificar si a configuración del tipo de documento destino
    // permite crear a partir de presupuestos vencidos
    MDocType docTypeTo = new MDocType(getCtx(), to.getC_DocTypeTarget_ID(), get_TrxName());
    if (from.isExpiredProposal(Env.getDate()) && !docTypeTo.isAllowProposalDue()) {
      throw new Exception(Msg.getMsg(getCtx(), "NotAllowedProposalDue"));
    }

    // Copiar la cabecera si así lo requiere
    if (copyHeader) {
      // Datos a setear luego de la copia de campos
      Integer docTypeID = to.getC_DocTypeTarget_ID();
      String docAction = to.getDocAction();
      String docStatus = to.getDocStatus();
      PO.copyValues(from, to);
      to.setC_DocTypeTarget_ID(docTypeID);
      to.setDocStatus(docStatus);
      to.setDocAction(docAction);
      to.setProcessed(false);
      to.setRef_Order_ID(from.getC_Order_ID());
      if (!to.save()) {
        throw new Exception(CLogger.retrieveErrorAsString());
      }
    }

    int no = to.copyLinesFrom(from, false, false); // no Attributes

    //

    return "@Copied@=" + no;
  } // doIt