当用户向发货发送订单时,我需要调用“上传IN”操作。我已经自动确认了订单。这是我的代码,它基于不同的问题的答案(Auto confirm shipment when create shipment from Sales Order by Automation Step):
public delegate void CreateShipmentDelegate(SOOrder order, int? SiteID, DateTime? ShipDate, bool? useOptimalShipDate, string operation, DocumentList<SOShipment> list);
[PXOverride]
public virtual void CreateShipment(SOOrder order, int? SiteID, DateTime? ShipDate, bool? useOptimalShipDate, string operation, DocumentList<SOShipment> list, CreateShipmentDelegate baseMethod)
{
baseMethod(order, SiteID, ShipDate, useOptimalShipDate, operation, list);
foreach (var action in (Base.action.GetState(null) as PXButtonState).Menus)
{
if (action.Command == "Confirm Shipment")
{
PXAdapter adapter2 = new PXAdapter(new DummyView(Base, Base.Document.View.BqlSelect, new List<object> { Base.Document.Current }));
adapter2.Menu = action.Command;
Base.action.PressButton(adapter2);
TimeSpan timespan;
Exception ex;
while (PXLongOperation.GetStatus(Base.UID, out timespan, out ex) == PXLongRunStatus.InProcess)
{ }
break;
}
}
}
我试图复制foreach循环,而是搜索“Upload IN”但是没有产生所需的结果:
foreach (var action in (Base.action.GetState(null) as PXButtonState).Menus)
{
if (action.Command == "Update IN")
{
PXAdapter adapter3 = new PXAdapter(new DummyView(Base, Base.Document.View.BqlSelect, new List<object> { Base.Document.Current }));
adapter3.Menu = action.Command;
Base.action.PressButton(adapter3);
TimeSpan timespan;
Exception ex;
while (PXLongOperation.GetStatus(Base.UID, out timespan, out ex) == PXLongRunStatus.InProcess)
{ }
break;
}
}
是否还有其他方法可以调用Actions?
我注意到这个特定操作的一件事是我在版本6实例的源代码中找不到它的代码,但是在2017版本中,我发现它是自己的动作,但是Visibility = false。此操作在2017年是否已过时,或者是否有设置在配置中显示/隐藏此操作?
答案 0 :(得分:1)
There's a known bug in early 2017 versions where that action is actually not visible on screen:
此错误应在2017年最新版本中修复。与此同时,解决方法是在SOShipmentEntry图表扩展中重新定义该操作。使用该代码,操作将是可见的,因此可以调用:
[PXUIField(DisplayName = "Update IN", Visible = false, MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXButton]
protected virtual IEnumerable updateIN(PXAdapter adapter, List<SOShipment> shipmentList = null)
{
List<SOShipment> list = new List<SOShipment>();
if (shipmentList == null)
{
foreach (SOShipment order in adapter.Get<SOShipment>())
{
list.Add(order);
}
}
else
{
list = shipmentList;
}
if (!Base.UnattendedMode && sosetup.Current.UseShippedNotInvoiced != true && sosetup.Current.UseShipDateForInvoiceDate != true && list.Any(shipment =>
{
IReadOnlyDictionary<string, object> fills = PXAutomation.GetFills(shipment);
object fillStatus = null;
fills?.TryGetValue(typeof(SOShipment.status).Name, out fillStatus);
return shipment.Status != SOShipmentStatus.Completed && fillStatus?.ToString() != SOShipmentStatus.Completed;
}))
{
WebDialogResult result = Base.Document.View.Ask(Base.Document.Current, PX.Objects.GL.Messages.Confirmation,
PX.Objects.SO.Messages.ShipNotInvoicedUpdateIN, MessageButtons.YesNo, MessageIcon.Question);
if (result != WebDialogResult.Yes)
return list;
}
Base.Save.Press();
PXLongOperation.StartOperation(this, delegate ()
{
INIssueEntry ie = PXGraph.CreateInstance<INIssueEntry>();
SOShipmentEntry docgraph = PXGraph.CreateInstance<SOShipmentEntry>();
docgraph.Caches[typeof(SiteStatus)] = ie.Caches[typeof(SiteStatus)];
docgraph.Caches[typeof(LocationStatus)] = ie.Caches[typeof(LocationStatus)];
docgraph.Caches[typeof(LotSerialStatus)] = ie.Caches[typeof(LotSerialStatus)];
docgraph.Caches[typeof(SiteLotSerial)] = ie.Caches[typeof(SiteLotSerial)];
docgraph.Caches[typeof(ItemLotSerial)] = ie.Caches[typeof(ItemLotSerial)];
docgraph.Views.Caches.Remove(typeof(SiteStatus));
docgraph.Views.Caches.Remove(typeof(LocationStatus));
docgraph.Views.Caches.Remove(typeof(LotSerialStatus));
docgraph.Views.Caches.Remove(typeof(SiteLotSerial));
docgraph.Views.Caches.Remove(typeof(ItemLotSerial));
DocumentList<INRegister> created = new DocumentList<INRegister>(docgraph);
foreach (SOShipment order in list)
{
try
{
if (adapter.MassProcess) PXProcessing<SOShipment>.SetCurrentItem(order);
docgraph.PostShipment(ie, order, created);
}
catch (Exception ex)
{
if (!adapter.MassProcess)
{
throw;
}
PXProcessing<SOShipment>.SetError(ex);
}
}
if (docgraph.sosetup.Current.AutoReleaseIN == true && created.Count > 0 && created[0].Hold == false)
{
INDocumentRelease.ReleaseDoc(created, false);
}
});
return list;
}