Reputation: 17
How can I execute via REST API in Acumatica AddInvoice Action on the Sales Order screen? I'm using default endpoint version 20.200.001, and the action is mapped with parameters endpoint version
On the UI I can add the Invoice through the dialog box. But, on postman I've tried to send this parameters to the POST request and I get error response.
This is my request:
{
"entity": {"OrderType":{"value":"CM"}, "OrderNbr":{"value":"CC00000013"}},
"parameters":{
"DocumentType": {"value": "Invoice"},
"ReferenceNbr":{"value": "CC00000010"}
}}
And this is the response message:
"exceptionMessage": "SalesOrder.Details[0].Allocations[0].Qty: Item '754502039173
0' in invoice 'CC00000010' lot/serial number '000001' quantity returned is greater than quantity invoiced. SalesOrder.Details[0].OrderQty: The return quantity exceeds the quantity available for return for the related invoice line CC00000010, 754502039173.
Decrease the quantity in the current line, or in the corresponding line of another return document or documents CC00000011 that exist for the invoice line. \nInserting 'Sales Order Line' record raised at least one error. Please review the errors."
How can I specify the exact Invoice Line and the lot/serial nbr. and quantity of the product like I'm doing it on the UI? add invoice dialog
I already tried to add an Detail[] section on the action but the error says that this type of parameter is unsupported.
I hope you can help me.
Upvotes: 1
Views: 528
Reputation: 1712
It is not supported in the current version of the endpoint. What you can do is use some customization to adjust qty on lines considering already returned items so it is not failing but adjusting returned qty instead. e.g.
//SOOrderEntryExtension
[PXOverride]
public virtual IEnumerable AddInvoice(PXAdapter adapter, Func<PXAdapter, IEnumerable> baseDelegate)
{
var result = baseDelegate.Invoke(adapter);
if (Base.IsContractBasedAPI && Base.Document.Current.Behavior == SOBehavior.RM)
{
foreach (SOLine line in Base.Transactions.Select().Where(line => ((SOLine)line).InvoiceNbr != null))
{
if (Base.Transactions.Cache.GetStatus(line) != PXEntryStatus.Inserted)
continue;
PXSelectBase<SOLine> selectReturnSOLines = new PXSelectJoin<SOLine,
LeftJoin<SOOrder, On<SOOrder.orderType, Equal<SOLine.orderType>, And<SOOrder.orderNbr, Equal<SOLine.orderNbr>>>>,
Where<SOLine.invoiceType, Equal<Required<SOLine.invoiceType>>,
And<SOLine.invoiceNbr, Equal<Required<SOLine.invoiceNbr>>,
And<SOLine.invoiceLineNbr, Equal<Required<SOLine.invoiceLineNbr>>,
And<Where<SOLine.behavior, Equal<SOOrderTypeConstants.rmaOrder>,
Or<SOLine.behavior, Equal<SOOrderTypeConstants.creditMemo>, And<SOOrder.cancelled, Equal<False>>>>>>>>>(Base);
var returnSOLines = selectReturnSOLines.Select(line.InvoiceType, line.InvoiceNbr, line.InvoiceLineNbr).RowCast<SOLine>().Where(_ => _.OrderNbr != line.OrderNbr || _.OrderType != line.OrderType || _.LineNbr != line.LineNbr);
SOLine copy = (SOLine)Base.Transactions.Cache.CreateCopy(line);
foreach (var otherline in returnSOLines)
{
copy.OrderQty -= otherline.OrderQty;
}
if (copy.OrderQty > 0)
{
Base.Transactions.Cache.RaiseExceptionHandling<SOLine.orderQty>(line, line.OrderQty, null);
Base.Transactions.Update(copy);
}
else
{
Base.Transactions.Cache.RaiseExceptionHandling<SOLine.orderQty>(line, line.OrderQty, null);
Base.Transactions.Delete(copy);
}
}
}
return result;
}
Upvotes: 0