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>
83 lines
4.0 KiB
C#
83 lines
4.0 KiB
C#
using Khaemhat.Application.Items;
|
|
using Khaemhat.Application.Querying;
|
|
using Khaemhat.Application.Security;
|
|
using Khaemhat.Application.Seeding;
|
|
using Khaemhat.Core.Items;
|
|
using Khaemhat.Core.Security;
|
|
using Khaemhat.Core.Validation;
|
|
using Khaemhat.Web.Tests.Hosting;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Khaemhat.Web.Tests.Items;
|
|
|
|
/// <summary>The demo items (SPEC §14, issue #42): 120 per scale, valid bar codes, derived lists, and every item passes the checks.</summary>
|
|
[TestClass]
|
|
public sealed class DemoItemsTests
|
|
{
|
|
private static readonly Actor Root = new(TestInstance.SuperUser, UserLevel.SuperUser, 1, null, null);
|
|
|
|
[TestMethod]
|
|
public void Catalogue_HasTheItemsOfTheSpecification_WithValidBarCodes()
|
|
{
|
|
var catalogue = DemoItemsSeeder.Catalogue();
|
|
Assert.HasCount(DemoItemsSeeder.ItemsPerScale, catalogue);
|
|
Assert.HasCount(catalogue.Count, catalogue.Select(i => i.Description).Distinct().ToList(), "No description twice.");
|
|
Assert.IsTrue(catalogue.All(i => i.Kind != ItemKind.Goods || i.Price > 0));
|
|
Assert.IsTrue(catalogue.Any(i => i.Kind == ItemKind.Service) && catalogue.Any(i => i.Kind == ItemKind.Expense) && catalogue.Any(i => i.Kind == ItemKind.Text));
|
|
foreach (var n in new[] { 1, 99, 500_123 })
|
|
{
|
|
Assert.IsTrue(EanValidator.IsValid(DemoItemsSeeder.Ean(n)), DemoItemsSeeder.Ean(n));
|
|
Assert.StartsWith("200", DemoItemsSeeder.Ean(n));
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task DemoSeed_FillsAnEmptyCompanyOnce_WithItemsThatPassTheChecks()
|
|
{
|
|
var (app, _, company) = await TestInstance.StartAsync(CancellationToken.None);
|
|
await using (app)
|
|
{
|
|
var runner = app.Services.GetRequiredService<SeedRunner>();
|
|
var items = app.Services.GetRequiredService<ItemService>();
|
|
var prices = app.Services.GetRequiredService<PriceListService>();
|
|
var first = await runner.RunAsync(company, SeedKind.Demo);
|
|
Assert.AreEqual(DemoItemsSeeder.ItemsPerScale, first.Added["items"]);
|
|
Assert.AreEqual(2, first.Added["price_lists"]);
|
|
Assert.IsGreaterThan(0, first.Added["item_suppliers"]);
|
|
Assert.IsGreaterThan(0, first.Added["party_item_codes"]);
|
|
Assert.IsEmpty((await runner.RunAsync(company, SeedKind.Demo)).Added, "Only an empty company gets the demo data.");
|
|
|
|
var lists = await prices.ListsAsync(Root, company);
|
|
CollectionAssert.AreEqual(new[] { "BASE", "PUBB", "RIV" }, lists.Select(l => l.Code).ToArray());
|
|
var grid = await prices.GridAsync(Root, company, new ListQuery { Search = "sfera 1/2", Limit = 10 }, DateOnly.FromDateTime(DateTime.Today), null);
|
|
var lever = grid.Page.Items[0];
|
|
Assert.IsTrue(lever.Prices[lists[1].Id].Derived, "The public list is derived from the base one.");
|
|
Assert.IsNotNull(lever.AverageCost);
|
|
|
|
var all = (await items.ListAsync(Root, company, new ListQuery { Limit = 200 })).Items;
|
|
Assert.HasCount(DemoItemsSeeder.ItemsPerScale, all);
|
|
foreach (var row in all)
|
|
{
|
|
var record = (await items.GetAsync(Root, company, row.Id))!;
|
|
Assert.IsTrue(record.Item.IsDemo);
|
|
var errors = (await items.ValidateAsync(Root, company, record)).Where(p => !p.IsWarning).Select(p => p.Field + ":" + p.Code).ToList();
|
|
Assert.IsEmpty(errors, row.Code + " " + row.Description + ": " + string.Join(", ", errors));
|
|
}
|
|
|
|
await app.StopAsync();
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task Scale_RepeatsTheCatalogue()
|
|
{
|
|
var (app, _, company) = await TestInstance.StartAsync(CancellationToken.None);
|
|
await using (app)
|
|
{
|
|
var report = await app.Services.GetRequiredService<SeedRunner>().RunAsync(company, SeedKind.Demo, 2);
|
|
Assert.AreEqual(2 * DemoItemsSeeder.ItemsPerScale, report.Added["items"]);
|
|
await app.StopAsync();
|
|
}
|
|
}
|
|
}
|