Dev #114

Merged
ashan_rusiru merged 5 commits from Dev into production 2026-10-17 18:25:55 +05:30
Showing only changes of commit c27db06880 - Show all commits
@@ -25,6 +25,7 @@ public sealed class PriceAdjustmentService : IPriceAdjustmentService
public const string ApprovalNavCode = "products.price-adjustments";
private readonly IRepository<PriceAdjustment> _adjustments;
private readonly IRepository<PriceAdjustmentLine> _lines;
private readonly IRepository<Item> _items;
private readonly IRepository<ItemPriceHistory> _history;
private readonly IRepository<User> _users;
@@ -36,11 +37,13 @@ public sealed class PriceAdjustmentService : IPriceAdjustmentService
private readonly IUnitOfWork _uow;
public PriceAdjustmentService(
IRepository<PriceAdjustment> adjustments, IRepository<Item> items, IRepository<ItemPriceHistory> history,
IRepository<User> users, IRepository<ApprovalConfig> config, IApprovalService approvals,
INotificationService notifications, INumberSequenceService numbers, ICurrentUser currentUser, IUnitOfWork uow)
IRepository<PriceAdjustment> adjustments, IRepository<PriceAdjustmentLine> lines, IRepository<Item> items,
IRepository<ItemPriceHistory> history, IRepository<User> users, IRepository<ApprovalConfig> config,
IApprovalService approvals, INotificationService notifications, INumberSequenceService numbers,
ICurrentUser currentUser, IUnitOfWork uow)
{
_adjustments = adjustments;
_lines = lines;
_items = items;
_history = history;
_users = users;
@@ -92,10 +95,14 @@ public sealed class PriceAdjustmentService : IPriceAdjustmentService
var ids = request.Lines.Select(l => l.ItemId).ToList();
var items = await _items.Query().Where(i => ids.Contains(i.ItemId)).ToDictionaryAsync(i => i.ItemId, ct);
var pendingItemIds = await _adjustments.Query().AsNoTracking()
.Where(p => p.Status == PriceAdjustmentStatus.PendingApproval || p.Status == PriceAdjustmentStatus.PendingSecondApproval)
.SelectMany(p => p.Lines.Select(l => new { l.ItemId, p.DocNo }))
.Where(x => ids.Contains(x.ItemId))
// Queried from the line side (not PriceAdjustment.Lines via SelectMany) so this stays a
// plain join — a SelectMany over a to-many navigation generates a CROSS APPLY that
// Pomelo/MySQL can't translate (it works fine against PostgreSQL, which is what this
// predates — 2026-10-16 MySQL-port regression).
var pendingItemIds = await _lines.Query().AsNoTracking()
.Where(l => ids.Contains(l.ItemId)
&& (l.PriceAdjustment!.Status == PriceAdjustmentStatus.PendingApproval || l.PriceAdjustment!.Status == PriceAdjustmentStatus.PendingSecondApproval))
.Select(l => new { l.ItemId, DocNo = l.PriceAdjustment!.DocNo })
.ToListAsync(ct);
var lines = new List<PriceAdjustmentLine>();