improvements, fixes...

This commit is contained in:
Loretta 2025-11-14 15:04:17 +01:00
parent ad5f27a77c
commit f2e99f3050
2 changed files with 49 additions and 33 deletions

View File

@ -309,11 +309,11 @@ public class FruitBankDbContext : MgDbContextBase,
{
weightToChange = productIdChanged ? shippingItem.MeasuredNetWeight : shippingItem.MeasuredNetWeight - dbShippingItem.MeasuredNetWeight;
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(productDto.Id, weightToChange, shippingItem.IsMeasurable, true);
//await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(productDto.Id, weightToChange, shippingItem.IsMeasurable, true);
}
await UpdateStockQuantityAndWeightAsync(productDto, quantityInc, $"Bejövő mérés, shippingItem: #{shippingItem.Id}", weightToChange);
productDto!.StockQuantity += quantityInc;
//productDto!.StockQuantity += quantityInc;
}
//if (productIdUnchanged || !dbShippingItem.IsMeasured) return true;
@ -336,14 +336,17 @@ public class FruitBankDbContext : MgDbContextBase,
(productDto.Id, nameof(IIncomingQuantity.IncomingQuantity), incomingQuantity.Value + dbShippingItem.MeasuredQuantity);
}
if (productIsMeasurable)
{
var measuringValues = new MeasuringAttributeValues(productDto.Id, -dbShippingItem.MeasuredNetWeight, dbShippingItem.IsMeasurable);
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(measuringValues, true);
}
//if (productIsMeasurable)
//{
// var measuringValues = new MeasuringAttributeValues(productDto.Id, -dbShippingItem.MeasuredNetWeight, dbShippingItem.IsMeasurable);
// await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(measuringValues, true);
//}
await UpdateStockQuantityAndWeightAsync(productDto, -dbShippingItem.MeasuredQuantity, $"Bejövő mérés, ShippingItem.Id: #{shippingItem.Id}. Product.Id megváltozott, #{productDto.Id}->#{shippingItem.ProductId}!", -dbShippingItem.MeasuredNetWeight);
productDto!.StockQuantity -= dbShippingItem.MeasuredQuantity;
await UpdateStockQuantityAndWeightAsync(productDto, -dbShippingItem.MeasuredQuantity,
$"Bejövő mérés, ShippingItem.Id: #{shippingItem.Id}. Product.Id megváltozott, #{productDto.Id}->#{shippingItem.ProductId}!",
-dbShippingItem.MeasuredNetWeight);
//productDto!.StockQuantity -= dbShippingItem.MeasuredQuantity;
}
else Logger.Warning($"product == null; dbShippingItem.ProductId: {dbShippingItem.ProductId}");
//else //TODO: productIdUnchanged-et lekezelni! - J.
@ -499,18 +502,18 @@ public class FruitBankDbContext : MgDbContextBase,
if (!orderItemDto.IsMeasurable) continue;
var prevNetWeightFromGa = orderItemDto.GenericAttributes.GetValueOrDefault<double>(nameof(IMeasuringNetWeight.NetWeight), 0);
var prevOrderItemNetWeightFromGa = orderItemDto.GenericAttributes.GetValueOrDefault<double>(nameof(IMeasuringNetWeight.NetWeight), 0);
//var gaNetWeight = CommonHelper.To<double>(orderItemDto.GenericAttributes.FirstOrDefault(x => x.Key == nameof(IMeasuringNetWeight.NetWeight))?.Value ?? "0");
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<OrderItem, double>
(orderItemDto.Id, nameof(IMeasuringNetWeight.NetWeight), orderItemDto.NetWeight);
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<OrderItem, double>(orderItemDto.Id, nameof(IMeasuringNetWeight.NetWeight), orderItemDto.NetWeight);
var weightToChange = -(orderItemDto.NetWeight - prevNetWeightFromGa);
var productWeightToChange = -(orderItemDto.NetWeight - prevOrderItemNetWeightFromGa);
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>
(orderItemDto.ProductId, weightToChange, orderItemDto.IsMeasurable, true);
//await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(orderItemDto.ProductId, productWeightToChange, orderItemDto.IsMeasurable, true);
await UpdateStockQuantityAndWeightAsync(orderItemDto.ProductId, 0, $"Kimenő mérés, OrderStatus set to complete. Rendelés: #{orderDto.Id}, rendelés tétel: #{orderItemDto.Id}", weightToChange, prevNetWeightFromGa + weightToChange);
await UpdateStockQuantityAndWeightAsync(orderItemDto.ProductId, 0,
$"Kimenő mérés, OrderStatus set to complete. Rendelés: #{orderDto.Id}, rendelés tétel: #{orderItemDto.Id}",
productWeightToChange);
}
//await _eventPublisher.PublishAsync(new OrderStatusChangedEvent(order, prevOrderStatus));
@ -644,19 +647,30 @@ public class FruitBankDbContext : MgDbContextBase,
// //return await Task.FromResult(false);
//}
public async Task UpdateStockQuantityAndWeightAsync(int productId, int quantityToChange, string message, double weightToChange = 0, double stockWeight = 0)
public async Task UpdateStockQuantityAndWeightAsync(int productId, int quantityToChange, string message, double weightToChange = 0)
{
var product = await Products.GetByIdAsync(productId);
if (weightToChange != 0 && stockWeight == 0) stockWeight = await _fruitBankAttributeService.GetGenericAttributeValueAsync<Product, double>(productId, nameof(IMeasuringNetWeight.NetWeight));
if (quantityToChange == 0 && weightToChange == 0) return;
await UpdateStockQuantityAndWeightAsync(product, quantityToChange, message, weightToChange, stockWeight);
var product = await Products.GetByIdAsync(productId);
await UpdateStockQuantityAndWeightAsync(product, quantityToChange, message, weightToChange);
}
public Task UpdateStockQuantityAndWeightAsync(ProductDto productDto, int quantityToChange, string message, double weightToChange = 0)
=> UpdateStockQuantityAndWeightAsync(productDto.Id, quantityToChange, message, weightToChange, productDto.NetWeight + weightToChange);
public async Task UpdateStockQuantityAndWeightAsync(Product product, int quantityToChange, string message, double weightToChange = 0, double stockWeight = 0)
public async Task UpdateStockQuantityAndWeightAsync(ProductDto productDto, int quantityToChange, string message, double weightToChange = 0)
{
if (quantityToChange == 0 && weightToChange == 0) return;
await UpdateStockQuantityAndWeightAsync(productDto.Id, quantityToChange, message, weightToChange);
productDto.StockQuantity += quantityToChange;
if (weightToChange == 0) return;
productDto.GenericAttributes = await GenericAttributes.Table.Where(x => x.EntityId == productDto.Id && x.KeyGroup == nameof(Product) && x.StoreId == _storeContext.GetCurrentStore().Id).ToListAsync();
}
public async Task UpdateStockQuantityAndWeightAsync(Product product, int quantityToChange, string message, double weightToChange = 0)
{
weightToChange = double.Round(weightToChange, 1);
if (quantityToChange == 0 && weightToChange == 0) return;
var latStockQuantityHistoryId = 0;
if (quantityToChange != 0) await _productService.AdjustInventoryAsync(product, quantityToChange, string.Empty, message);
@ -679,10 +693,10 @@ public class FruitBankDbContext : MgDbContextBase,
await StockQuantityHistories.InsertAsync(historyEntry);
latStockQuantityHistoryId = historyEntry.Id;
}
else return;
//await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight), netWeight);
//if (weightToChange == 0 && stockWeight == 0) return;
if (weightToChange == 0) return;
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, weightToChange, true, true);
if (latStockQuantityHistoryId <= 0)
{
@ -695,11 +709,13 @@ public class FruitBankDbContext : MgDbContextBase,
}
}
var stockWeight = double.Round(await _fruitBankAttributeService.GetGenericAttributeValueAsync<Product, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight)), 1);
var stockQuantityHistoryExt = new StockQuantityHistoryExt
{
StockQuantityHistoryId = latStockQuantityHistoryId,
NetWeightAdjustment = double.Round(weightToChange, 1),
NetWeight = double.Round(stockWeight, 1),
NetWeightAdjustment = weightToChange,
NetWeight = stockWeight,
};
await StockQuantityHistoriesExt.InsertAsync(stockQuantityHistoryExt, false);

View File

@ -45,7 +45,7 @@ public class FruitBankEventConsumer :
_measurementService = measurementService;
_fruitBankAttributeService = fruitBankAttributeService;
}
public override async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage)
{
var product = await CheckAndUpdateProductManageInventoryMethodToManageStock(eventMessage.Entity);
@ -118,8 +118,8 @@ public class FruitBankEventConsumer :
if (productDtoNetWeight == null || double.Round(productDtoNetWeight.Value, 1) != netWeight)
{
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight), netWeight);
await _ctx.UpdateStockQuantityAndWeightAsync(productDto, 0, $"Manuális készlet súly változtatás az admin felületen.", netWeight - productDtoNetWeight.Value);
//await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight), netWeight);
await _ctx.UpdateStockQuantityAndWeightAsync(productDto, 0, $"Manuális készlet súly változtatás az admin felületen.", netWeight - productDtoNetWeight.GetValueOrDefault(0));
}
//Tára
@ -277,7 +277,7 @@ public class FruitBankEventConsumer :
await _measurementService.OrderItemInsertedOrUpdatedPostProcess(eventMessage.Entity);
}
}
#endregion Delete