使销售员 ID 成为 SOLine 上的必填字段

Make Salesperson ID a Required field on SOLine

我需要将 SOLine 上的销售员 ID 作为必填字段。但是由于转移订单没有销售人员,因此它应该只在我创建转移订单以外的订单时才有效。

我尝试使用以下代码,但似乎无法正常工作。可能是它被一些现有代码覆盖了。如果有人有任何建议,请告诉我。

public PXSetup<SOOrderTypeOperation,
 Where<SOOrderTypeOperation.orderType, Equal<Optional<SOOrderType.orderType>>,
 And<SOOrderTypeOperation.operation, Equal<Optional<SOOrderType.defaultOperation>>>>> sooperation;
   
protected bool IsTransferOrder
{
 get
 {
  return (sooperation.Current.INDocType == INTranType.Transfer);
 }
}

protected virtual void SOLine_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
 var row = (SOLine)e.Row;
 if (row == null) return;

 PXDefaultAttribute.SetPersistingCheck<SOLine.salesPersonID>(sender, row, IsTransferOrder ? PXPersistingCheck.Nothing : PXPersistingCheck.Null);
}

我通常会在条件存在时在 Row Persisting 中抛出适当的异常。

下面是 SOShipmentEntry 检查传输和检查字段空值的示例:

protected virtual void SOShipment_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
    SOShipment doc = (SOShipment)e.Row;
    if (doc.ShipmentType == SOShipmentType.Transfer && doc.DestinationSiteID == null)
    {
        throw new PXRowPersistingException(typeof(SOOrder.destinationSiteID).Name, null, ErrorMessages.FieldIsEmpty, typeof(SOOrder.destinationSiteID).Name);
    }
}

我也在 RowPersisting

中调用了类似于此示例的 RaiseExceptionHandling
// sender = PXCache
if (row.OrderQty == Decimal.Zero)
    sender.RaiseExceptionHandling<POLine.orderQty>(row, row.OrderQty, new PXSetPropertyException(Messages.POLineQuantityMustBeGreaterThanZero, PXErrorLevel.Error));

两个示例都应停止保存页面。调用 Raise Exception 处理应该用红色 X 指出字段,这是更好的方法,用户更容易找到有问题的字段。

以你的例子为例:

protected virtual void SOLine_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
    SOLine row = (SOLine)e.Row;
    if (row == null)
    {
        return;
    }

    if (!IsTransferOrder && row.SalesPersonID == null)
    {
        sender.RaiseExceptionHandling<SOLine.salesPersonID>(row, row.SalesPersonID, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, PXErrorLevel.Error));
    }
}