如果满足条件并引发自定义错误,则限制发票下达

时间:2019-07-19 13:26:27

标签: acumatica acumatica-kb

如果我的条件得到满足并且引发了自定义错误,我已经覆盖了“发票”屏幕,以限制发票的发布,但是即使引发了错误,并且在关闭该错误之后,发票仍会被释放,但是我想限制发票如果引发错误,则释放。

    [PXOverride]
    public virtual IEnumerable Release(PXAdapter adapter)
    {            
        if (Base.Document.Current != null)
        {
            var paymentSetup = PaySetup.SelectSingle(Base.Document.Current.PaymentMethodID);
            var paymentSettings = PaySettingDetails.SelectSingle(Base.Document.Current.PaymentMethodID);

            if (paymentSettings != null && paymentSetup != null && paymentSetup.IsActive == true)
            {
                if (this.PayCurrentInvoice.Current != null && this.PayCurrentInvoice.Current.PayStatus.ToUpper() != KNPIConstants.PAID)
                {
                    throw new PXException(KNPIMessages.NotPaid);
                }
            }                  
            else
            {
                return Base.release.Press(adapter);
            }
        }
        return null;
    }

如果引发了错误,则不应释放发票,但是即使引发了错误,在关闭该错误后仍会释放发票。

1 个答案:

答案 0 :(得分:0)

您的替代错误!

 public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
 [PXOverride]
 public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
  {
      var paymentSetup = PaySetup.SelectSingle(Base.Document.Current.PaymentMethodID);
      var paymentSettings = PaySettingDetails.SelectSingle(Base.Document.Current.PaymentMethodID);

      if (paymentSettings != null && paymentSetup != null && paymentSetup.IsActive == true)
      {
          if (this.PayCurrentInvoice.Current != null && this.PayCurrentInvoice.Current.PayStatus.ToUpper() != KNPIConstants.PAID)
          {
              throw new PXException(KNPIMessages.NotPaid);
          }
      }
      return baseMethod(adapter);
  }