PO Acumatica -AnpassungC#

Ein Treffpunkt für C#-Programmierer
Guest
 PO Acumatica -Anpassung

Post by Guest »

Ich habe dem Bestellbildschirm ein Barcode-Feld hinzugefügt. Die Funktionalität funktioniert einwandfrei, aber ich habe ein Problem, bei dem die Bestellmenge automatisch auf 2 gesetzt wird, wenn ich ein Produkt zum ersten Mal scanne. Wenn ich dasselbe Produkt erneut scanne, erhöht sich die Bestellmenge auf 3, was korrekt ist.< /p>
Aber zum ersten Mal sollte es 1 und nicht 2 sein.
Für ein anderes Produkt ist die Bestellmenge jedoch korrekt auf 1 eingestellt erster Scan (zweiter Bestellposten). Ich habe versucht, dieses Problem zu beheben, war aber noch nicht erfolgreich.
Bitte geben Sie mir Hinweise, wie ich das Problem beheben kann.
Vielen Dank!
Hier ist mein Code:

Code: Select all

   using PX.Data;
using PX.Objects.PO;
using PX.Objects.IN;
using PX.Objects.CS;
using System.Linq;

namespace PX.Objects.PO
{
public class POOrderEntry_Extension : PXGraphExtension
{
#region Event Handlers

protected virtual void POOrder_UsrInventoryBarCode_FieldUpdated(
PXCache cache,
PXFieldUpdatedEventArgs e,
PXFieldUpdated BaseMethod)
{
// Call base event handler if it exists
BaseMethod?.Invoke(cache, e);

// Get the current POOrder
POOrder order = e.Row as POOrder;
if (order == null) return;

POOrderExt orderExt = cache.GetExtension(order);
if (string.IsNullOrEmpty(orderExt?.UsrInventoryBarCode))
return;

// Lookup the INItemXRef record using the scanned barcode
INItemXRef xRef = PXSelectJoin<
INItemXRef,
InnerJoin,
Where>
.Select(Base, INAlternateType.Barcode, orderExt.UsrInventoryBarCode);

if (xRef == null)
{
throw new PXSetPropertyException(
"Barcode not found in the system.");
}

// Retrieve the InventoryItem from the cross-reference
InventoryItem item = PXSelect<
InventoryItem,
Where>
.Select(Base, xRef.InventoryID);

if (item == null)
{
throw new PXSetPropertyException(
"Inventory Item not found.");
}

// Check vendor compatibility via POVendorInventory
POVendorInventory vendorItem = PXSelect<
POVendorInventory,
Where>
.Select(Base, item.InventoryID);

if (vendorItem != null)
{
if (order.VendorID == null)
{
order.VendorID = vendorItem.VendorID;
cache.RaiseFieldUpdated(order, order.VendorID);
Base.Document.Update(order);
}
else if (order.VendorID != vendorItem.VendorID)
{
throw new PXSetPropertyException(
"Scanned item belongs to a different vendor.");
}
}

// Check if a POLine for this InventoryID already exists (accumulate quantity).
var existingLine = Base.Transactions
.Select()
.RowCast()
.FirstOrDefault(l => l.InventoryID == item.InventoryID);

if (existingLine != null)
{
PXTrace.WriteInformation($"Existing Line Found: {existingLine.InventoryID}, Current Qty: {existingLine.OrderQty}");

if (existingLine.OrderQty == 0)
{
PXTrace.WriteInformation("First Scan Detected, Setting OrderQty to 1");
existingLine.OrderQty = 1;
}
else
{
PXTrace.WriteInformation("Incrementing Quantity by 1");
existingLine.OrderQty += 1;
}

Base.Transactions.Update(existingLine);
}
else
{
// Otherwise, insert a new POLine with a default Qty = 1
PXTrace.WriteInformation("No Existing Line Found.  Creating New Line.");

POLine newLine = new POLine
{
InventoryID  = item.InventoryID,
OrderQty     = 1,
CuryUnitCost = item.BasePrice
};

Base.Transactions.Insert(newLine);
}

// Refresh the transaction lines to show the updated quantity
Base.Transactions.View.RequestRefresh();

// Clear the Barcode field after processing
cache.SetValueExt(order, null);
Base.Document.Update(order);
cache.IsDirty = true;
}

#endregion

#region Persist Override

public delegate void PersistDelegate();

[PXOverride]
public void Persist(PersistDelegate basePersist)
{
try
{
POOrder order = Base.Document.Current;
if (order != null && order.Status == POOrderStatus.Hold)
{
Base.releaseFromHold.Press();
}

basePersist();
}
catch (PXException ex)
{
throw new PXException(ex.Message);
}
}

#endregion
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post