コード例 #1
0
ファイル: MProduct.java プロジェクト: makezjdq/adempiere-1
  @Override
  protected boolean afterSave(boolean newRecord, boolean success) {
    if (!success) return success;

    //	Value/Name change in Account
    if (!newRecord && (is_ValueChanged("Value") || is_ValueChanged("Name")))
      MAccount.updateValueDescription(getCtx(), "M_Product_ID=" + getM_Product_ID(), get_TrxName());

    //	Name/Description Change in Asset	MAsset.setValueNameDescription
    if (!newRecord && (is_ValueChanged("Name") || is_ValueChanged("Description"))) {
      String sql =
          "UPDATE A_Asset a "
              + "SET (Name, Description)="
              + "(SELECT SUBSTR((SELECT bp.Name FROM C_BPartner bp WHERE bp.C_BPartner_ID=a.C_BPartner_ID) || ' - ' || p.Name,1,60), p.Description "
              + "FROM M_Product p "
              + "WHERE p.M_Product_ID=a.M_Product_ID) "
              + "WHERE IsActive='Y'"
              //	+ " AND GuaranteeDate > SysDate"
              + "  AND M_Product_ID="
              + getM_Product_ID();
      int no = DB.executeUpdate(sql, get_TrxName());
      log.fine("Asset Description updated #" + no);
    }

    //	New - Acct, Tree, Old Costing
    if (newRecord) {
      insert_Accounting(
          "M_Product_Acct",
          "M_Product_Category_Acct",
          "p.M_Product_Category_ID=" + getM_Product_Category_ID());
      insert_Tree(X_AD_Tree.TREETYPE_Product);
      //
      MAcctSchema[] mass =
          MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID(), get_TrxName());
      for (int i = 0; i < mass.length; i++) {
        //	Old
        MProductCosting pcOld = new MProductCosting(this, mass[i].getC_AcctSchema_ID());
        pcOld.saveEx();
      }
    }

    //	New Costing
    if (newRecord || is_ValueChanged("M_Product_Category_ID")) MCost.create(this);

    return success;
  } //	afterSave