|
@@ -184,6 +184,9 @@ public class StockMovementTimberlineSettings : TimberlinePosterSettings<StockMov
|
|
|
[TextBoxEditor]
|
|
|
public string StockTakeGL { get; set; }
|
|
|
|
|
|
+ [CheckBoxEditor]
|
|
|
+ public bool IgnoreNetZeroTransfers { get; set; }
|
|
|
+
|
|
|
protected override string DefaultScript()
|
|
|
{
|
|
|
return @"
|
|
@@ -314,7 +317,6 @@ public class StockMovementTimberlinePoster : ITimberlinePoster<StockMovement, St
|
|
|
line.Description = product.Name;
|
|
|
line.Amount = Math.Round(movement.Value, 4);
|
|
|
line.CreditAccount = product.PurchaseGL.Code;
|
|
|
- line.DebitAccount = product.SellGL.Code;
|
|
|
return line;
|
|
|
}
|
|
|
|
|
@@ -322,6 +324,14 @@ public class StockMovementTimberlinePoster : ITimberlinePoster<StockMovement, St
|
|
|
{
|
|
|
var mvts = transaction.ToArray();
|
|
|
|
|
|
+ var ignorableTransfer = Settings.IgnoreNetZeroTransfers
|
|
|
+ && mvts.Length == 2
|
|
|
+ && mvts.Any(x => x.Type == StockMovementType.TransferOut)
|
|
|
+ && mvts.Any(x => x.Type == StockMovementType.TransferIn)
|
|
|
+ && mvts[0].Job.ID == mvts[1].Job.ID
|
|
|
+ && mvts.Sum(x => x.Qty).IsEffectivelyEqual(0)
|
|
|
+ && mvts.Sum(x => x.Qty * x.Cost).IsEffectivelyEqual(0);
|
|
|
+
|
|
|
// I think we will fail all the movements if any one movement in the transaction failed. All the successful ones,
|
|
|
// rather than saving them with AddSuccess immediately, we will put here first, and only succeed them if every movement succeeded.
|
|
|
var successful = new List<(StockMovement mvt, IStockMovementTimberlineLine? line)>();
|
|
@@ -335,7 +345,8 @@ public class StockMovementTimberlinePoster : ITimberlinePoster<StockMovement, St
|
|
|
// Issue to General Stock
|
|
|
var gl = new StockMovementTimberlineGL { };
|
|
|
gl = ModifyLine(gl, mvt);
|
|
|
- gl.DebitAccount = Settings.StockTakeGL;
|
|
|
+ var product = products[mvt.Product.ID];
|
|
|
+ gl.DebitAccount = product.SellGL.Code.NotWhiteSpaceOr(Settings.StockTakeGL);
|
|
|
if (ProcessGLLine(model, mvt, gl))
|
|
|
{
|
|
|
successful.Add((mvt, gl));
|
|
@@ -360,7 +371,8 @@ public class StockMovementTimberlinePoster : ITimberlinePoster<StockMovement, St
|
|
|
// StockTake in General Stock
|
|
|
var gl = new StockMovementTimberlineGL { };
|
|
|
gl = ModifyLine(gl, mvt);
|
|
|
- gl.DebitAccount = Settings.StockTakeGL;
|
|
|
+ var product = products[mvt.Product.ID];
|
|
|
+ gl.DebitAccount = product.SellGL.Code.NotWhiteSpaceOr(Settings.StockTakeGL);
|
|
|
if (ProcessGLLine(model, mvt, gl))
|
|
|
{
|
|
|
successful.Add((mvt, gl));
|
|
@@ -386,7 +398,7 @@ public class StockMovementTimberlinePoster : ITimberlinePoster<StockMovement, St
|
|
|
break;
|
|
|
case StockMovementType.TransferOut:
|
|
|
case StockMovementType.TransferIn:
|
|
|
- if(mvt.Job.ID != Guid.Empty)
|
|
|
+ if(mvt.Job.ID != Guid.Empty && !ignorableTransfer)
|
|
|
{
|
|
|
var directCost = CreateDirectCost(mvt);
|
|
|
if(ProcessDirectCostLine(model, mvt, directCost))
|
|
@@ -398,6 +410,10 @@ public class StockMovementTimberlinePoster : ITimberlinePoster<StockMovement, St
|
|
|
result.AddFailed(mvt, "Failed by script.");
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ successful.Add((mvt, null));
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|