How do I return data for other branches for a user with access to only one branch?

馋奶兔 提交于 2021-02-11 13:32:05

问题


I found it very odd that the base installation of Acumatica did not contain the ability to document approved Manufacturer/part number for Stock Items, so I added this functionality to my customization project. The design allows each branch to define their own approved manufacturers and part number, but I need to allow a user with access to only one branch to see the approved manufacturers from other branches.

My DAC's are SSINManufacturer (the manufacturer master) and SSINItemManufacturer (the individual branch specific manufacturer part number record for the Stock Item).

The customization was added as a new tab under Stocked Items as a grid view. Access control by branch (across the system) is handled via a user role for the branch, but I need allow any user with access to Stocked Items to see all manufacturer part numbers from any branch.

I found a post in AsiaBlog (https://asiablog.acumatica.com/2015/11/using-scopes-in-acumatica.html) that mentions the use of PXReadBranchRestrictedScope to "remove restriction by branches that will be automatically applied by the system core, if you have BranchID attribute in the selected DAC". I was advised not to use BranchID, but rather UsrBranchID in my custom DAC's, but I suspect this is the underlying reason that I'm still restricted to just the current branch data in this view.

I am just starting to learn to use a constructor to override the default results that a view would generate, and I'm not sure that this definition is correct.

public PXSelectJoin<SSINItemManufacturer,
    InnerJoin<SSINManufacturer, On<SSINManufacturer.manufacturerID, Equal<SSINItemManufacturer.manufacturerID>>>,
    Where<SSINItemManufacturer.inventoryID, Equal<Current<InventoryItem.inventoryID>>
    >> ItemManufacturerXrefs;

public virtual IEnumerable itemmanufacturerxrefs()
{
    using (new PXReadBranchRestrictedScope())
    {
        PXResult<SSINItemManufacturer> Results = PXSelectJoin<SSINItemManufacturer,
            InnerJoin<SSINManufacturer, On<SSINManufacturer.manufacturerID, Equal<SSINItemManufacturer.manufacturerID>>>,
            Where<SSINItemManufacturer.inventoryID, Equal<Current<InventoryItem.inventoryID>>
            >>.Select(Base);
        yield return Results;
    }
}

Is the constructor defined correctly to leverage PXReadBranchRestrictedScope? And do I need to add BranchID to my DAC to make this return all records for the Stocked Item in the tenant?


回答1:


Two issues found which resolved the problem. First, the PXResultset was defined as PXResult which returned only 1 value, and the subsequent method of returning the result needed to be expanded to more explicitly build the results to be returned.

public virtual IEnumerable itemmanufacturerxrefs()
{
    using (new PXReadBranchRestrictedScope())
    {
        PXResultset<SSINItemManufacturer> Results = PXSelectJoin<SSINItemManufacturer,
                        InnerJoin<SSINManufacturer, On<SSINManufacturer.manufacturerID, Equal<SSINItemManufacturer.manufacturerID>>>,
                        Where<SSINItemManufacturer.inventoryID, Equal<Current<InventoryItem.inventoryID>>
                         >>.Select(Base);

        foreach (PXResult<SSINItemManufacturer, SSINManufacturer> result in Results)
        {
            SSINItemManufacturer mfgitem = result;
            SSINManufacturer mfg = result;

            yield return new PXResult<SSINItemManufacturer, SSINManufacturer>(mfgitem, mfg); 
        }
    }
}

Secondly, upon closer review of the post on AsiaBlog, the BranchID (actually Branch) ATTRIBUTE needed to be added to the field of the DAC. UsrBranchID is fine for a field name, provided the [Branch] attribute was added.

#region UsrBranchID
[Branch(IsKey = true)]
[PXDefault(typeof(AccessInfo.branchID))]
[PXUIField(DisplayName = Messages.FldUsrBranchID)]
public virtual int? UsrBranchID { get; set; }
public abstract class usrBranchID : PX.Data.BQL.BqlInt.Field<usrBranchID> { }
#endregion

The scope override works well. The use of the constructor on the view allows me to grant visibility to the data from all branches "as advertised".



来源:https://stackoverflow.com/questions/58980178/how-do-i-return-data-for-other-branches-for-a-user-with-access-to-only-one-branc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!