feat: provinces and municipalities from the ISTAT list in the base data (#45)
New companies now get the 110 provinces and 7,894 municipalities in force (ISTAT list of 26/02/2026, CC BY 4.0), so the tax code calculation and the municipality lookups work without loading anything. The list lives in the Italian pack behind a new IPlaceDirectory feature and is added by the base seeder like the rest of the base data: missing codes only, never touching existing rows. The pack data version moves to IT 2026.3 so existing companies receive the lists at the next start. Postal codes are left out: the only candidate source (comuni-json) has no licence for them and stops at 2020 (ADR 0028). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
07555de700
commit
321aae7e81
19 files changed
+8249
-25
No files matched your search
@@ -0,0 +1,51 @@
|
||||
using Khaemhat.Fiscal.Abstractions;
|
||||
|
||||
namespace Khaemhat.Fiscal.Italy.Tests;
|
||||
|
||||
/// <summary>The provinces and municipalities of the ISTAT list shipped with the pack (ADR 0028).</summary>
|
||||
[TestClass]
|
||||
public sealed class ItalianPlacesTests
|
||||
{
|
||||
private static readonly IPlaceDirectory Places = new ItalyFiscalPack().Require<IPlaceDirectory>();
|
||||
|
||||
[TestMethod]
|
||||
public void List_HasEveryProvinceAndMunicipality_WithUniqueCodes()
|
||||
{
|
||||
Assert.HasCount(110, Places.Provinces);
|
||||
Assert.HasCount(7894, Places.Municipalities);
|
||||
Assert.HasCount(Places.Provinces.Count, Places.Provinces.Select(p => p.Code).Distinct(StringComparer.Ordinal));
|
||||
Assert.HasCount(Places.Municipalities.Count, Places.Municipalities.Select(m => m.Code).Distinct(StringComparer.Ordinal));
|
||||
Assert.Contains("ISTAT", Places.Source);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EveryMunicipality_BelongsToAProvinceOfItsRegion()
|
||||
{
|
||||
var provinces = Places.Provinces.ToDictionary(p => p.Code, StringComparer.Ordinal);
|
||||
|
||||
foreach (var municipality in Places.Municipalities)
|
||||
{
|
||||
Assert.IsTrue(provinces.TryGetValue(municipality.ProvinceCode, out var province), municipality.Code);
|
||||
Assert.AreEqual(province.Region, municipality.Region, municipality.Code);
|
||||
Assert.MatchesRegex("^[A-Z][0-9]{3}$", municipality.Code);
|
||||
Assert.MatchesRegex("^[0-9]{6}$", municipality.StatisticalCode!);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("L219", "Torino", "TO", "Piemonte", "001272")]
|
||||
[DataRow("H501", "Roma", "RM", "Lazio", "058091")]
|
||||
[DataRow("A952", "Bolzano", "BZ", "Trentino-Alto Adige/Südtirol", "021008")]
|
||||
public void Municipality_HasTheCadastralCodeOfTheTaxCode(string code, string name, string province, string region, string istat)
|
||||
{
|
||||
Assert.AreEqual(new MunicipalityTemplate(code, name, province, region, istat, null), Places.Municipalities.Single(m => m.Code == code));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Provinces_FollowTheSardinianReform()
|
||||
{
|
||||
var sardinia = Places.Provinces.Where(p => p.Region == "Sardegna").Select(p => p.Code).Order(StringComparer.Ordinal).ToArray();
|
||||
|
||||
CollectionAssert.AreEqual(new[] { "CA", "CI", "NU", "OG", "OR", "OT", "SS", "VS" }, sardinia);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ public sealed class ItalyFiscalPackTests
|
||||
public void Pack_IsItalianWithItsDataVersion()
|
||||
{
|
||||
Assert.AreEqual("IT", Pack.CountryCode);
|
||||
Assert.AreEqual("IT 2026.2", Pack.DataVersion);
|
||||
Assert.AreEqual("IT 2026.3", Pack.DataVersion);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -123,13 +123,21 @@ public sealed class CodeRulesTests
|
||||
var tables = services.GetRequiredService<TableService>();
|
||||
var autoFill = services.GetRequiredService<AutoFillService>();
|
||||
|
||||
await tables.SaveAsync(Root, company, new Province { Code = "TO", Description = "Torino", Region = "Piemonte" });
|
||||
await tables.SaveAsync(Root, company, new Municipality { Code = "L219", Description = "Torino", ProvinceCode = "TO", Region = "Piemonte", PostalCodes = "10121-10156" });
|
||||
await tables.SaveAsync(Root, company, new Municipality { Code = "G674", Description = "Pinerolo", ProvinceCode = "TO", Region = "Piemonte", PostalCodes = "10064" });
|
||||
// The base data brings every municipality of the ISTAT list, without postal codes: the users add them.
|
||||
var municipalities = await tables.ActiveAsync<Municipality>(Root, company);
|
||||
Assert.HasCount(7894, municipalities);
|
||||
Assert.IsEmpty(await autoFill.PlacesByPostalCodeAsync(Root, company, "10128"));
|
||||
var turinRow = municipalities.Single(m => m.Code == "L219");
|
||||
turinRow.PostalCodes = "10121-10156";
|
||||
await tables.SaveAsync(Root, company, turinRow);
|
||||
var pinerolo = municipalities.Single(m => m.Code == "G674");
|
||||
pinerolo.PostalCodes = "10064";
|
||||
await tables.SaveAsync(Root, company, pinerolo);
|
||||
|
||||
var turin = (await autoFill.PlacesByPostalCodeAsync(Root, company, "10128")).Single();
|
||||
Assert.AreEqual(new PlaceSuggestion("L219", "Torino", "TO", "Piemonte", "10128"), turin);
|
||||
Assert.AreEqual("10064", (await autoFill.PlacesByNameAsync(Root, company, "pin")).Single().PostalCode);
|
||||
Assert.AreEqual("10064", (await autoFill.PlacesByNameAsync(Root, company, "pinerolo")).Single().PostalCode);
|
||||
Assert.IsTrue((await autoFill.PlacesByNameAsync(Root, company, "pin")).Count > 1);
|
||||
Assert.IsEmpty(await autoFill.PlacesByPostalCodeAsync(Root, company, "1012"));
|
||||
Assert.IsEmpty(await autoFill.PlacesByPostalCodeAsync(Root, company, "10157"));
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public sealed class CompanyTablesTests
|
||||
Assert.HasCount(12, years[0].Periods);
|
||||
|
||||
var runner = services.GetRequiredService<SeedRunner>();
|
||||
Assert.AreEqual("IT 2026.2", await runner.VersionAsync(company));
|
||||
Assert.AreEqual("IT 2026.3", await runner.VersionAsync(company));
|
||||
var again = await runner.UpdateBaseAsync(Root, company);
|
||||
Assert.AreEqual(0, again.Total, string.Join(", ", again.Added.Select(a => a.Key + "=" + a.Value)));
|
||||
await app.StopAsync();
|
||||
|
||||
Reference in new issue
Block a user