feat: parties with radar, record, checks, VIES and demo data (#41)
Customers, suppliers, prospects and leads live in one parties archive with a kind and a subject type (ADR 0029). A customer that also supplies carries is_also_supplier, so it shows in both radars with one code. - Three radars (/anagrafiche/clienti, /fornitori, /contatti) with search, quick filters and bulk disable/enable; the record has eight tabs (main data, addresses, contacts, terms, fiscal and SDI, banks, notes and attachments, history) on the MasterDataPage base. - PartyService saves the whole record in one transaction, checks it with the fiscal pack (VAT number, tax code, recipient code, country), treats a duplicate VAT number or a consumer without tax code as warnings, fills the default recipient code, runs VIES after commit for EU companies, and converts prospects/leads (new customer code, old one kept as previous_code) and suppliers (become customers that also supply). - Delete falls back to disable when the party is referenced. - DemoPartiesSeeder adds 3 salespeople and 21 parties with fictitious but formally valid identifiers; SeedAsync now runs demo seeders when asked. - Test host accepts service overrides so VIES can be stubbed. Docs: ADR 0029, wiki Anagrafiche and demo data pages, regenerated data model, CHANGELOG and STATUS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a9eda510f2
commit
3401271483
28 files changed
+4600
-85
No files matched your search
@@ -0,0 +1,68 @@
|
||||
using Khaemhat.Application.Parties;
|
||||
using Khaemhat.Application.Querying;
|
||||
using Khaemhat.Application.Security;
|
||||
using Khaemhat.Application.Seeding;
|
||||
using Khaemhat.Core.Parties;
|
||||
using Khaemhat.Core.Security;
|
||||
using Khaemhat.Fiscal.Italy;
|
||||
using Khaemhat.Web.Tests.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Khaemhat.Web.Tests.Parties;
|
||||
|
||||
/// <summary>The demo parties (SPEC §14, issue #41): loaded once, every kind of subject, and each one passes the checks of a save.</summary>
|
||||
[TestClass]
|
||||
public sealed class DemoPartiesTests
|
||||
{
|
||||
private static readonly Actor Root = new(TestInstance.SuperUser, UserLevel.SuperUser, 1, null, null);
|
||||
|
||||
[TestMethod]
|
||||
public void FictitiousNumbers_AreValid()
|
||||
{
|
||||
var rules = new ItalianTaxIdentifierRules();
|
||||
foreach (var vat in DemoPartiesSeeder.VatNumbers)
|
||||
{
|
||||
Assert.IsTrue(rules.IsValidVatNumber(vat), vat);
|
||||
}
|
||||
|
||||
Assert.IsTrue(rules.IsValidTaxCode(DemoPartiesSeeder.AdministrationTaxCode));
|
||||
foreach (var iban in DemoPartiesSeeder.Ibans)
|
||||
{
|
||||
Assert.IsTrue(Khaemhat.Core.Validation.IbanValidator.IsValid(iban), iban);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task DemoSeed_FillsAnEmptyCompanyOnce_WithPartiesThatPassTheChecks()
|
||||
{
|
||||
var (app, _, company) = await TestInstance.StartAsync(CancellationToken.None);
|
||||
await using (app)
|
||||
{
|
||||
var runner = app.Services.GetRequiredService<SeedRunner>();
|
||||
var parties = app.Services.GetRequiredService<PartyService>();
|
||||
var first = await runner.RunAsync(company, SeedKind.Demo);
|
||||
Assert.AreEqual(21, first.Added["parties"]);
|
||||
Assert.IsEmpty((await runner.RunAsync(company, SeedKind.Demo)).Added, "Only an empty company gets the demo data.");
|
||||
|
||||
var customers = (await parties.ListAsync(Root, company, PartyArchive.Customers, new ListQuery { Limit = 100 })).Items;
|
||||
var suppliers = (await parties.ListAsync(Root, company, PartyArchive.Suppliers, new ListQuery { Limit = 100 })).Items;
|
||||
var contacts = (await parties.ListAsync(Root, company, PartyArchive.Contacts, new ListQuery { Limit = 100 })).Items;
|
||||
Assert.HasCount(12, customers);
|
||||
Assert.HasCount(6, suppliers, "Five suppliers and a customer that is also a supplier.");
|
||||
Assert.HasCount(4, contacts);
|
||||
CollectionAssert.IsSubsetOf(Enum.GetValues<SubjectType>(), customers.Select(c => c.SubjectType).Distinct().ToList());
|
||||
Assert.AreEqual("C000001", customers.Single(c => c.Name == "Rossi Impianti S.r.l.").Code);
|
||||
Assert.IsTrue(customers.Any(c => c.Terms is { Blocked: true }) && customers.Any(c => c.Terms is { SplitPayment: true }) && customers.Any(c => c.Disabled));
|
||||
|
||||
foreach (var row in customers.Concat(suppliers).Concat(contacts).DistinctBy(r => r.Id))
|
||||
{
|
||||
var record = (await parties.GetAsync(Root, company, row.Id))!;
|
||||
Assert.IsTrue(record.Party.IsDemo);
|
||||
var errors = (await parties.ValidateAsync(Root, company, record)).Where(p => !p.IsWarning).Select(p => p.Field + ":" + p.Code).ToList();
|
||||
Assert.IsEmpty(errors, row.Name + ": " + string.Join(", ", errors));
|
||||
}
|
||||
|
||||
await app.StopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user