Acumatica - Enable field in AP Bill while in Pending Approval status - acumatica

I have been trying to enable the APTran.tranDesc field in the AP Bill Entry screen while the invoice is in the Pending Approval Status. I tried the below (which does not work)
public void APTran_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
{
APTran line = (APTran)e.Row;
APInvoice invoice = Base.Document.Current;
if (invoice == null || line == null || Base.IsExport) return;
if (invoice.Status != APDocStatus.Open)
{
PXUIFieldAttribute.SetEnabled<APTran.tranDesc>(sender, line, true);
}
}
I believe this is happening because of this line in APInvoiceEntry:
Transactions.Cache.SetAllEditPermissions(allowEdit: false);
Is there an easy way to override just the one tranDesc field to allow the edit within the grid?

try this :
protected void APTran_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
var row = (APTran)e.Row;
if (row == null) return;
APInvoice invoice = Base.Document.Current;
if (invoice.Status == APDocStatus.PendingApproval)
{
cache.AllowUpdate = true;
PXUIFieldAttribute.SetEnabled(cache, row, false);
PXUIFieldAttribute.SetEnabled<APTran.tranDesc>(cache, row, true);
}
}
you must enable cache for updating. disable all fields. then re-enable the field you want editable.

Related

Default Branch on Payments and Applications (AR302000)

I want to display the 'Default Branch' (screenshot 1) from the Customers' (AR303000) Shipping tab to the Payment and Applications'(AR302000) 'LOAD DOCUMENTS' dialog box's, 'Company Branch'(screenshot 2)
Screenshot 1: Customers Default Branch
Screenshot 2: Load Document Company Branch (Payments and Applications)
The code I have does not seem to be displaying the Default Branch from the Customers Shipping tab to the Payments and Applications Company Branch.
Code snippet:
public class ARPaymentEntry_Extension : PXGraphExtension<PX.Objects.AR.ARPaymentEntry>
{
#region Event Handlers
protected void LoadOptions_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
var row = (LoadOptions)e.Row;
if (row == null)
{
return;
}
ARPayment aRPayment = Base.Document.Current;
if (aRPayment == null)
{
return;
}
Customer customer = PXSelect<Customer,
Where<Customer.bAccountID, Equal<Required<ARPayment.customerID>>>>
.Select(Base, aRPayment.CustomerID);
if (customer == null)
{
return;
}
Location location = PXSelect<Location,
Where<Location.bAccountID, Equal<Required<ARPayment.customerID>>,
And<Location.locationID, Equal<Required<Customer.defLocationID>>>>>
.Select(Base, aRPayment.CustomerID, customer.DefLocationID);
if (location == null)
{
return;
}
row.BranchID = location.CBranchID;
}
[PXMergeAttributes(Method = MergeMethod.Replace)]
// [OrganizationTree(typeof(organizationID), typeof(branchID), onlyActive: true)]
protected virtual void LoadOptions_OrgBAccountID_CacheAttached(PXCache cache)
{
}
I would move your code into FieldDefaulting for the LoadOptions, rather than row selected.
protected virtual void LoadOptions_OrgBAccountID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs args, PXFieldDefaulting del)
{
var row = (LoadOptions)e.Row;
if (row == null)
{
return;
}
ARPayment aRPayment = Base.Document.Current;
if (aRPayment == null)
{
return;
}
Customer customer = PXSelect<Customer,
Where<Customer.bAccountID, Equal<Required<ARPayment.customerID>>>>
.Select(Base, aRPayment.CustomerID);
if (customer == null)
{
return;
}
Location location = PXSelect<Location,
Where<Location.bAccountID, Equal<Required<ARPayment.customerID>>,
And<Location.locationID, Equal<Required<Customer.defLocationID>>>>>
.Select(Base, aRPayment.CustomerID, customer.DefLocationID);
if (location == null)
{
return;
}
//set the default with customers branch
args.NewValue = location.CBranchID;
}

Enable Custom Field on Project Quote Screen

I am using Acumatica 2020 R1. I have a custom text field on the PMQuote DAC. This field is in a custom tab on the project quotes screen. I want that field to always be editable. I put the following in my RowSelected event:
protected virtual void PMQuote_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected del)
{
del?.Invoke(cache, e);
PMQuote quote = e.Row as PMQuote;
cache.AllowUpdate = true;
PXUIFieldAttribute.SetEnabled(cache, e.Row, true);
PXUIFieldAttribute.SetEnabled<PMQuoteExt.usrMyCustomField>(cache, e.Row, true);
}
This didn't work, so I also looked in the automation steps. I didn't see any automation steps available to modify.
I then looked at Workflow. I didn't see any workflows to edit either. I tried creating a new one based on the status field. I added the user field for each status and made sure disabled was unchecked. This didn't work either.
Any ideas on how I can get that field to be enabled regardless of the document status?
Thanks for your help!
AllowUpdate is called only on the cache object, add it for the data view, example:
Base.Quote.AllowUpdate = true
Also, try to extend PXQuoteMaintExt graph extension:
public class PMQuoteMaintExtExtension : PXGraphExtension<PMQuoteMaintExt, PMQuoteMaint>
{
protected virtual void PMQuote_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected sel)
{
sel?.Invoke(sender, e);
}
}
It manages visibility with RowSelected event:
namespace PX.Objects.PM
{
public class PMQuoteMaintExt : PXGraphExtension<PMDiscount, PMQuoteMaint>
{
protected virtual void PMQuote_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected sel)
{
sel?.Invoke(sender, e);
var row = e.Row as PMQuote;
if (row == null) return;
VisibilityHandler(sender, row);
}
private void VisibilityHandler(PXCache sender, PMQuote row)
{
CR.Standalone.CROpportunityRevision revisionInDb = PXSelectReadonly<CR.Standalone.CROpportunityRevision,
Where<CR.Standalone.CROpportunityRevision.noteID, Equal<Required<CR.Standalone.CROpportunityRevision.noteID>>>>.Select(Base, row.QuoteID).FirstOrDefault();
CR.Standalone.CROpportunity opportunityInDb = (revisionInDb == null) ? null : PXSelectReadonly<CR.Standalone.CROpportunity,
Where<CR.Standalone.CROpportunity.opportunityID, Equal<Required<CR.Standalone.CROpportunity.opportunityID>>>>.Select(Base, revisionInDb.OpportunityID).FirstOrDefault();
CR.Standalone.CROpportunity opportunity = PXSelect<CR.Standalone.CROpportunity,
Where<CR.Standalone.CROpportunity.opportunityID, Equal<Required<CR.Standalone.CROpportunity.opportunityID>>>>.Select(Base, row.OpportunityID).FirstOrDefault();
var opportunityIsClosed = opportunity?.IsActive == false;
bool allowUpdate = row.IsDisabled != true && !opportunityIsClosed && row.Status != PMQuoteStatusAttribute.Closed;
if (opportunityInDb?.OpportunityID == opportunity?.OpportunityID)
Base.Caches[typeof(PMQuote)].AllowUpdate = allowUpdate;
else
{
var quoteCache = Base.Caches[typeof(PMQuote)];
foreach (var field in quoteCache.Fields)
{
if (!quoteCache.Keys.Contains(field) &&
field != quoteCache.GetField(typeof(PMQuote.opportunityID)) &&
field != quoteCache.GetField(typeof(PMQuote.isPrimary)))
PXUIFieldAttribute.SetEnabled(sender, row, field, allowUpdate);
}
}
PXUIFieldAttribute.SetEnabled<PMQuote.bAccountID>(sender, row, row.OpportunityID == null);
Base.Caches[typeof(PMQuote)].AllowDelete = !opportunityIsClosed;
foreach (var type in new[]
{
typeof(CR.CROpportunityDiscountDetail),
typeof(CR.CROpportunityProducts),
typeof(CR.CRTaxTran),
typeof(CR.CRAddress),
typeof(CR.CRContact),
typeof(CR.CRPMTimeActivity),
typeof(PM.PMQuoteTask)
})
{
Base.Caches[type].AllowInsert = Base.Caches[type].AllowUpdate = Base.Caches[type].AllowDelete = allowUpdate;
}
Base.Caches[typeof(CopyQuoteFilter)].AllowUpdate = true;
Base.Caches[typeof(RecalcDiscountsParamFilter)].AllowUpdate = true;
Base.Actions[nameof(Base.Approval.Submit)]
.SetVisible(row.Status == PMQuoteStatusAttribute.Draft);
Base.actionsFolder
.SetVisible(nameof(Base.Approval.Approve), Base.Actions[nameof(Base.Approval.Approve)].GetVisible());
Base.actionsFolder
.SetVisible(nameof(Base.Approval.Reject), Base.Actions[nameof(Base.Approval.Reject)].GetVisible());
Base.Actions[nameof(EditQuote)]
.SetVisible(row.Status != PMQuoteStatusAttribute.Draft);
Base.Actions[nameof(Base.Approval.Submit)]
.SetEnabled(row.Status == PMQuoteStatusAttribute.Draft && !opportunityIsClosed);
Base.Actions[nameof(Base.Approval.Approve)]
.SetEnabled(row.Status == PMQuoteStatusAttribute.PendingApproval);
Base.Actions[nameof(Base.Approval.Reject)]
.SetEnabled(row.Status == PMQuoteStatusAttribute.PendingApproval);
Base.Actions[nameof(EditQuote)]
.SetEnabled(row.Status != PMQuoteStatusAttribute.Draft && row.Status != PMQuoteStatusAttribute.Closed);
Base.Actions[nameof(Base.CopyQuote)]
.SetEnabled(Base.Caches[typeof(PMQuote)].AllowInsert);
Base.Actions[nameof(PMDiscount.GraphRecalculateDiscountsAction)]
.SetEnabled((row.Status == PMQuoteStatusAttribute.Draft));
Base.Actions[nameof(Base.PrimaryQuote)].SetEnabled(!String.IsNullOrEmpty(row.OpportunityID) && row.IsPrimary == false && row.Status != PMQuoteStatusAttribute.Closed);
Base.Actions[nameof(Base.SendQuote)].SetEnabled(row.Status.IsIn<string>(PMQuoteStatusAttribute.Approved, PMQuoteStatusAttribute.Sent, PMQuoteStatusAttribute.Closed));
Base.Actions[nameof(Base.PrintQuote)].SetEnabled(true);
Base.convertToProject.SetEnabled( (row.OpportunityID == null || row.IsPrimary == true) && row.QuoteProjectID == null && row.Status.IsIn<string>(PMQuoteStatusAttribute.Approved, PMQuoteStatusAttribute.Sent));
PXUIFieldAttribute.SetEnabled<PMQuote.subject>(sender, row, true);
PXUIFieldAttribute.SetEnabled<PMQuote.status>(sender, row, false);
}
}
}

Changing the Freight Tax Category in Sales order screen is not re- calculating the freight tax

I am changing Freight tax category pragmatically based on the tax category of the item selected in the detail tab
protected virtual void SOOrder_CustomerLocationID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e, PXFieldUpdated del)
{
if (del != null)
del(sender, e);
var row = (SOOrder)e.Row;
Location location = PXSelect<Location, Where<Location.locationID, Equal<Required<Location.locationID>>>>.Select(Base, Base.Document.Current.CustomerLocationID);
if (location != null)
{
string custtaxzone = location.CTaxZoneID;
bool taxableitem = false;
if (custtaxzone == "TAXABLE")
{
foreach (SOLine line in Base.Transactions.Select())
{
if (line.TaxCategoryID == "PATAX")
{
taxableitem = true;
break;
}
}
if (taxableitem)
Base.Document.Current.FreightTaxCategoryID = "PATAX";
else
Base.Document.Current.FreightTaxCategoryID = null;
}
}
}
The value is properly updating but the freight tax is not calculating.
In RowUpdated event, update the DataView after changing the value and invoke calculation of the tax attribute:
public void SOOrder_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
SOOrder row = e.Row as SOOrder;
if (!sender.ObjectsEqual<SOOrder.customerLocationID, SOOrder.customerLocationID>(e.OldRow, e.Row))
{
Base.Document.Current.FreightTaxCategoryID = "PATAX";
Base.Document.Update(Document.Current);
SOOrderTaxAttribute.Calculate<SOOrder.freightTaxCategoryID>(sender, e);
}
}
Invoke the Default attribute to clear the freight tax:
Base.Document.Current.FreightTaxCategoryID = null;
Base.Document.Update(Document.Current);
sender.SetDefaultExt<SOOrder.freightTaxCategoryID>(e.Row);

Acumatica-sales order default customer

Am trying to set a default customer for CS but am am getting an error "RevisionID' cannot be empty" please assist
protected void SOOrder_CustomerID_FieldUpdating(PXCache cache, PXFieldUpdatingEventArgs e)
{
SOOrder row = (SOOrder)e.Row;
if(row == null) return;
if (row.OrderType == "CS" || row.OrderType == "SS")
{
row.CustomerID = 7211;
}
else
{
row.CustomerID = null;
}
}
In your specific case FieldDefaulting event must be used instead of FieldUpdating to generate default value for the Customer ID field. According to the API Reference, in FieldDefaulting event handlers the new value must be assigned to the NewValue property of PXFieldDefaultingEventArgs and never directly to the DAC field:
protected void SOOrder_CustomerID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
SOOrder row = (SOOrder)e.Row;
if(row == null) return;
if (row.OrderType == "CS" || row.OrderType == "SS")
{
e.NewValue = 7211;
}
}

Payment Ref(Payment Settings tab) got blocked after customized on SOOrderEntry (Sales Orders)

My coding here after I added it on Code Editor: SOOrderEntry (Sales Orders) the Payment Ref(Payment Settings tab) got blocked.
protected void SOOrder_OrderType_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
PXResult<PX.SM.UsersInRoles> user = PXSelect<PX.SM.UsersInRoles,
Where<PX.SM.UsersInRoles.username, Equal<Current<AccessInfo.userName>>>>.Select(Base);
SOOrder row = (SOOrder)e.Row;
if(row != null)
{
if(user != null)
{
PX.SM.UsersInRoles role = user;
if(role.Rolename == "Administrator")
{
e.NewValue = "CS";
e.Cancel = true;
}
else
if(role.Rolename == "Sales 01Ao")
{
e.NewValue = "C1";
e.Cancel = true;
}
if(role.Rolename == "Sales 01Do")
{
e.NewValue = "C2";
e.Cancel = true;
}
}
}
}
Payment Ref is enabled only for Order Types of the Cash Sale or the Cash Return AR Document Type:
Please make sure to accordingly set up your C1 and C2 order types.

Resources