Items get their own archive and record (mockup 017): codes from the per-category mask, EAN and NC8 checks, alternative units and bar codes, suppliers with the usual one, substitutes, notes and history. Only goods can be stocked; stock itself comes with the warehouse in M6. Costs are hidden from users without items.cost.read and kept as they were when those users save. A used item is disabled instead of deleted. Prices live in one item_prices table, either for a price list or as a customer's net price, each valid from a date, so documents keep the price of their day. Derived lists compute a price from their base list with markup and rounding when they have none of their own. The price grid (mockup 018) edits every list at one validity date, keeps changes pending and highlighted until saved, and computes mass updates as a preview. PriceListService.QuoteAsync gives documents (M5) the price search order net, list, base, item price with its source. Parties get the "Articoli e codici" tab: the codes a customer or supplier uses for our items, found by the item search in that party's documents. Demo data adds 120 items of a plumbing wholesaler, the PUBB and RIV lists, last year's prices, suppliers, units, codes and a customer's net prices; seed --demo [--scale N] loads them from the command line and repeats the catalogue for performance tests. ADR 0030 records the decisions; wiki, data model, CHANGELOG and STATUS are updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
2.1 KiB
C#
46 lines
2.1 KiB
C#
using Khaemhat.Core.Items;
|
|
|
|
namespace Khaemhat.Core.Tests.Common;
|
|
|
|
/// <summary>The rounding of the prices of a list (issue #42, mockup 018): steps of 0.10, 0.50, 1.00, up or down.</summary>
|
|
[TestClass]
|
|
public sealed class PriceRoundingTests
|
|
{
|
|
[TestMethod]
|
|
[DataRow("46.43", "0.10", RoundingDirection.Nearest, "46.40")]
|
|
[DataRow("46.45", "0.10", RoundingDirection.Nearest, "46.50")]
|
|
[DataRow("46.41", "0.10", RoundingDirection.Up, "46.50")]
|
|
[DataRow("46.49", "0.10", RoundingDirection.Down, "46.40")]
|
|
[DataRow("12.345", "0.50", RoundingDirection.Nearest, "12.50")]
|
|
[DataRow("12.345", "0.50", RoundingDirection.Down, "12.00")]
|
|
[DataRow("12.01", "1.00", RoundingDirection.Up, "13.00")]
|
|
[DataRow("12.00", "1.00", RoundingDirection.Up, "12.00")]
|
|
[DataRow("1.23456", "0", RoundingDirection.Nearest, "1.23")]
|
|
[DataRow("0.123456", "0.0001", RoundingDirection.Nearest, "0.1235")]
|
|
public void Round_GoesToTheStep(string value, string step, RoundingDirection direction, string expected) =>
|
|
Assert.AreEqual(decimal.Parse(expected, System.Globalization.CultureInfo.InvariantCulture),
|
|
PriceRounding.Round(decimal.Parse(value, System.Globalization.CultureInfo.InvariantCulture), decimal.Parse(step, System.Globalization.CultureInfo.InvariantCulture), direction));
|
|
|
|
[TestMethod]
|
|
public void Round_KeepsTwoDecimals_WhenTheRestAreZeros() =>
|
|
Assert.AreEqual("46.40", PriceRounding.Round(46.4000m, 0.10m).ToString(System.Globalization.CultureInfo.InvariantCulture));
|
|
|
|
[TestMethod]
|
|
public void Change_AddsOrTakesOffAPercent()
|
|
{
|
|
Assert.AreEqual(46.4m, PriceRounding.Change(32m, 45m));
|
|
Assert.AreEqual(28.8m, PriceRounding.Change(32m, -10m));
|
|
Assert.AreEqual(32m, PriceRounding.Change(32m, 0m));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Margin_IsOnThePrice()
|
|
{
|
|
Assert.AreEqual(45m, PriceRounding.Margin(32m, 17.60m));
|
|
Assert.AreEqual(-10m, PriceRounding.Margin(10m, 11m));
|
|
Assert.IsNull(PriceRounding.Margin(0m, 5m));
|
|
Assert.IsNull(PriceRounding.Margin(10m, null));
|
|
Assert.IsNull(PriceRounding.Margin(null, 5m));
|
|
}
|
|
}
|