如何将“站点ID(Whse)”选择限制为仅当前分支?

时间:2019-08-26 16:56:50

标签: acumatica

虽然将记录限制为INSite.branchID = AccessInfo.branchID很容易,但是需要稍微复杂一些。我以为在查看INTran的DAC时找到了一个简单的解决方案:

<!DOCTYPE html>
<html lang="en">
  <head>
  ...
  ...
  </head>

  <body>
    ...
    <div id="app">..</div>
    ...
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script src="js/my-component.umd.js"></script> 
    <script type="module">
      var app = new Vue({
        el: '#app',
        data: {
          message: 'Hello Vue!'
        },
        components: {
          myComponent: my-component   
        }
      })
    </script>
  </body>
</html>

具有InterBranchRestrictor的有趣属性。稍加挖掘后,我发现此属性实际上在Acumatica中得到了广泛使用,但似乎仅限于“报告图”并为分支间事务启用了该功能。很容易,我启用了该功能,然后再次尝试了库存问题。没运气。我仍然可以为其他分支机构选择站点ID。

到目前为止,我只能通过在INIssueEntry上创建图形扩展来设置和验证站点ID的控制有限。但是我真正想要的是将选择器限制为仅当前分支的站点ID。

    #region SiteID
    public abstract class siteID : PX.Data.BQL.BqlInt.Field<siteID> { }
    protected Int32? _SiteID;
    [IN.SiteAvail(typeof(INTran.inventoryID), typeof(INTran.subItemID))]
    [PXDefault(typeof(INRegister.siteID))]
    [PXForeignReference(typeof(FK.Site))]
    [InterBranchRestrictor(typeof(Where<SameOrganizationBranch<INSite.branchID, Current<INRegister.branchID>>>))]
    public virtual Int32? SiteID
    {
        get
        {
            return this._SiteID;
        }
        set
        {
            this._SiteID = value;
        }
    }
    #endregion

我真的很想利用它的外观

    protected void _(Events.FieldDefaulting<INTran.siteID> e)
    {

        PXResultset<INSite> Results = PXSelect<INSite, Where<INSite.branchID, Equal<Current<AccessInfo.branchID>>>>.Select(Base);
        if (Results.Count == 1)
        {
            foreach (PXResult<INSite> result in Results)
            {
                INSite site = result;
                e.NewValue = site.SiteID;
                e.Cancel = true;
            }
        }
    }

    protected void _(Events.FieldVerifying<INTran.siteID> e)
    {
        int? siteID = (int?)e.NewValue;
        INTran row = (INTran)e.Row;

        INSite site = PXSelect<INSite, Where<INSite.siteID, Equal<Required<INSite.siteID>>,
            And<INSite.branchID, Equal<Current<AccessInfo.branchID>>>>>.Select(Base, siteID);

        if(siteID != null && site?.SiteID == null)
        {
            PXUIFieldAttribute.SetError<INTran.siteID>(e.Cache, row, "Invalid Warehouse for Branch");
        }
    }

可以,但是很明显我只是不明白它的作用。或者,如果我可以在其中添加where子句

[InterBranchRestrictor(typeof(Where<SameOrganizationBranch<INSite.branchID, Current<INRegister.branchID>>>))]

然后我可以通过这种方式将列表限制为当前分支,但是我也在努力使该列表正常工作。 (有关在扩展程序中实现PXForeignReference属性的问题,以覆盖字段定义。)

如何将分支特定记录(以一种可以在Acumatica中有效复制的方式)限制为仅当前分支的站点ID?

1 个答案:

答案 0 :(得分:1)

InterBranchRestrictorAttribute正在从报告中检查图形是否正常运行,或者要在IsReportOrInterBranchFeatureEnabled方法中打开分支间事务功能,因此您需要从实现中删除它。 您可以按照下面的示例所示的方式编写自己的PXResrictorAttribute

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = true)]
public class CustomRestrictorAttribute: PXRestrictorAttribute
{
    public CustomRestrictorAttribute(Type where) : base(CustomRestrictorAttribute.EmptyWhere, "Restrictor Message.", Array.Empty<Type>())
    {
      this._interBranchWhere = where;
    }

    protected override BqlCommand WhereAnd(PXCache sender, PXSelectorAttribute selattr, Type Where)
    {
      return base.WhereAnd(sender, selattr, this._interBranchWhere);
    }

    private static readonly Type EmptyWhere = typeof(Where<True, Equal<True>>);

    protected Type _interBranchWhere;
}

并将其应用于DAC字段,如下所示:

[SiteAvail(typeof(SOLine.inventoryID), typeof(SOLine.subItemID))]
[PXParent(typeof(Select<SOOrderSite, Where<SOOrderSite.orderType, Equal<Current<SOLine.orderType>>, And<SOOrderSite.orderNbr, Equal<Current<SOLine.orderNbr>>, And<SOOrderSite.siteID, Equal<Current2<SOLine.siteID>>>>>>), LeaveChildren = true, ParentCreate = true)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIRequired(typeof(IIf<Where<SOLine.lineType, NotEqual<SOLineType.miscCharge>>, True, False>))]
[InterBranchRestrictor(typeof(Where2<SameOrganizationBranch<INSite.branchID, Current<SOOrder.branchID>>,
Or<Current<SOOrder.behavior>, Equal<SOBehavior.qT>>>))]
[CustomInterBranchRestrictor(typeof(Where<INSite.branchID,Equal<Current<SOOrder.branchID>>>))]
protected virtual void SOLine_SiteID_CacheAttached(PXCache cache)
{

}