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
@@ -11,7 +11,8 @@ namespace Khaemhat.Application.Seeding;
|
||||
/// The base tables of SPEC §14 available from M4: countries, currencies, units, VAT codes (from the fiscal pack),
|
||||
/// payment methods and terms and document types (from the pack's <see cref="IBaseTablesTemplate"/>), transport tables,
|
||||
/// warehouse reasons, the main warehouse, categories, the base price list, the numerators and the fiscal year of the
|
||||
/// current year. Provinces, municipalities and banks come from datasets loaded separately (ADR 0026).
|
||||
/// current year, and the provinces and municipalities of the pack's <see cref="IPlaceDirectory"/> (ADR 0028). Banks
|
||||
/// come from a dataset loaded separately (ADR 0026).
|
||||
/// </summary>
|
||||
/// <param name="years">Creates the current fiscal year.</param>
|
||||
public sealed class BaseTablesSeeder(FiscalYearService years) : ISeeder
|
||||
@@ -58,6 +59,24 @@ public sealed class BaseTablesSeeder(FiscalYearService years) : ISeeder
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
await context.EnsureAsync("countries", ReadCountries(), cancellationToken).ConfigureAwait(false);
|
||||
if (context.Pack.GetFeature<IPlaceDirectory>() is { } places)
|
||||
{
|
||||
await context.EnsureAsync("provinces", places.Provinces.Select(p => new Province { Code = p.Code, Description = p.Name, Region = p.Region }), cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
await context.EnsureAsync(
|
||||
"municipalities",
|
||||
places.Municipalities.Select(m => new Municipality
|
||||
{
|
||||
Code = m.Code,
|
||||
Description = m.Name,
|
||||
ProvinceCode = m.ProvinceCode,
|
||||
Region = m.Region,
|
||||
IstatCode = m.StatisticalCode,
|
||||
PostalCodes = m.PostalCodes,
|
||||
}),
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await context.EnsureAsync("currencies", Currencies.Select(c => new Currency { Code = c.Code, Description = c.Name, Symbol = c.Symbol, Decimals = c.Decimals }), cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
await context.EnsureAsync("units_of_measure", Units(), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -240,3 +240,34 @@ public interface IBaseTablesTemplate
|
||||
/// <summary>The document types.</summary>
|
||||
IReadOnlyList<DocumentTypeTemplate> DocumentTypes { get; }
|
||||
}
|
||||
|
||||
/// <summary>A province (or equivalent first-level area) of the country's official list.</summary>
|
||||
/// <param name="Code">The abbreviation, such as <c>TO</c>.</param>
|
||||
/// <param name="Name">The name.</param>
|
||||
/// <param name="Region">The region.</param>
|
||||
public sealed record ProvinceTemplate(string Code, string Name, string Region);
|
||||
|
||||
/// <summary>A municipality of the country's official list.</summary>
|
||||
/// <param name="Code">The code used by the tax rules (the Italian cadastral code, such as <c>L219</c>).</param>
|
||||
/// <param name="Name">The name.</param>
|
||||
/// <param name="ProvinceCode">The province (a <see cref="ProvinceTemplate.Code"/>).</param>
|
||||
/// <param name="Region">The region.</param>
|
||||
/// <param name="StatisticalCode">The code of the national statistics office, if any.</param>
|
||||
/// <param name="PostalCodes">The postal codes, comma separated, when the list has them.</param>
|
||||
public sealed record MunicipalityTemplate(string Code, string Name, string ProvinceCode, string Region, string? StatisticalCode, string? PostalCodes);
|
||||
|
||||
/// <summary>
|
||||
/// The official list of provinces and municipalities shipped with the pack, loaded into the base tables (ADR 0026,
|
||||
/// ADR 0028). Like the rest of the base data it only adds the codes a company is missing.
|
||||
/// </summary>
|
||||
public interface IPlaceDirectory
|
||||
{
|
||||
/// <summary>Where the list comes from and its date, shown in the documentation and the logs.</summary>
|
||||
string Source { get; }
|
||||
|
||||
/// <summary>The provinces.</summary>
|
||||
IReadOnlyList<ProvinceTemplate> Provinces { get; }
|
||||
|
||||
/// <summary>The municipalities.</summary>
|
||||
IReadOnlyList<MunicipalityTemplate> Municipalities { get; }
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,111 @@
|
||||
sigla;denominazione;regione
|
||||
AG;Agrigento;Sicilia
|
||||
AL;Alessandria;Piemonte
|
||||
AN;Ancona;Marche
|
||||
AO;Valle d'Aosta/Vallée d'Aoste;Valle d'Aosta/Vallée d'Aoste
|
||||
AP;Ascoli Piceno;Marche
|
||||
AQ;L'Aquila;Abruzzo
|
||||
AR;Arezzo;Toscana
|
||||
AT;Asti;Piemonte
|
||||
AV;Avellino;Campania
|
||||
BA;Bari;Puglia
|
||||
BG;Bergamo;Lombardia
|
||||
BI;Biella;Piemonte
|
||||
BL;Belluno;Veneto
|
||||
BN;Benevento;Campania
|
||||
BO;Bologna;Emilia-Romagna
|
||||
BR;Brindisi;Puglia
|
||||
BS;Brescia;Lombardia
|
||||
BT;Barletta-Andria-Trani;Puglia
|
||||
BZ;Bolzano/Bozen;Trentino-Alto Adige/Südtirol
|
||||
CA;Cagliari;Sardegna
|
||||
CB;Campobasso;Molise
|
||||
CE;Caserta;Campania
|
||||
CH;Chieti;Abruzzo
|
||||
CI;Sulcis Iglesiente;Sardegna
|
||||
CL;Caltanissetta;Sicilia
|
||||
CN;Cuneo;Piemonte
|
||||
CO;Como;Lombardia
|
||||
CR;Cremona;Lombardia
|
||||
CS;Cosenza;Calabria
|
||||
CT;Catania;Sicilia
|
||||
CZ;Catanzaro;Calabria
|
||||
EN;Enna;Sicilia
|
||||
FC;Forlì-Cesena;Emilia-Romagna
|
||||
FE;Ferrara;Emilia-Romagna
|
||||
FG;Foggia;Puglia
|
||||
FI;Firenze;Toscana
|
||||
FM;Fermo;Marche
|
||||
FR;Frosinone;Lazio
|
||||
GE;Genova;Liguria
|
||||
GO;Gorizia;Friuli-Venezia Giulia
|
||||
GR;Grosseto;Toscana
|
||||
IM;Imperia;Liguria
|
||||
IS;Isernia;Molise
|
||||
KR;Crotone;Calabria
|
||||
LC;Lecco;Lombardia
|
||||
LE;Lecce;Puglia
|
||||
LI;Livorno;Toscana
|
||||
LO;Lodi;Lombardia
|
||||
LT;Latina;Lazio
|
||||
LU;Lucca;Toscana
|
||||
MB;Monza e della Brianza;Lombardia
|
||||
MC;Macerata;Marche
|
||||
ME;Messina;Sicilia
|
||||
MI;Milano;Lombardia
|
||||
MN;Mantova;Lombardia
|
||||
MO;Modena;Emilia-Romagna
|
||||
MS;Massa-Carrara;Toscana
|
||||
MT;Matera;Basilicata
|
||||
NA;Napoli;Campania
|
||||
NO;Novara;Piemonte
|
||||
NU;Nuoro;Sardegna
|
||||
OG;Ogliastra;Sardegna
|
||||
OR;Oristano;Sardegna
|
||||
OT;Gallura Nord-Est Sardegna;Sardegna
|
||||
PA;Palermo;Sicilia
|
||||
PC;Piacenza;Emilia-Romagna
|
||||
PD;Padova;Veneto
|
||||
PE;Pescara;Abruzzo
|
||||
PG;Perugia;Umbria
|
||||
PI;Pisa;Toscana
|
||||
PN;Pordenone;Friuli-Venezia Giulia
|
||||
PO;Prato;Toscana
|
||||
PR;Parma;Emilia-Romagna
|
||||
PT;Pistoia;Toscana
|
||||
PU;Pesaro e Urbino;Marche
|
||||
PV;Pavia;Lombardia
|
||||
PZ;Potenza;Basilicata
|
||||
RA;Ravenna;Emilia-Romagna
|
||||
RC;Reggio Calabria;Calabria
|
||||
RE;Reggio nell'Emilia;Emilia-Romagna
|
||||
RG;Ragusa;Sicilia
|
||||
RI;Rieti;Lazio
|
||||
RM;Roma;Lazio
|
||||
RN;Rimini;Emilia-Romagna
|
||||
RO;Rovigo;Veneto
|
||||
SA;Salerno;Campania
|
||||
SI;Siena;Toscana
|
||||
SO;Sondrio;Lombardia
|
||||
SP;La Spezia;Liguria
|
||||
SR;Siracusa;Sicilia
|
||||
SS;Sassari;Sardegna
|
||||
SV;Savona;Liguria
|
||||
TA;Taranto;Puglia
|
||||
TE;Teramo;Abruzzo
|
||||
TN;Trento;Trentino-Alto Adige/Südtirol
|
||||
TO;Torino;Piemonte
|
||||
TP;Trapani;Sicilia
|
||||
TR;Terni;Umbria
|
||||
TS;Trieste;Friuli-Venezia Giulia
|
||||
TV;Treviso;Veneto
|
||||
UD;Udine;Friuli-Venezia Giulia
|
||||
VA;Varese;Lombardia
|
||||
VB;Verbano-Cusio-Ossola;Piemonte
|
||||
VC;Vercelli;Piemonte
|
||||
VE;Venezia;Veneto
|
||||
VI;Vicenza;Veneto
|
||||
VR;Verona;Veneto
|
||||
VS;Medio Campidano;Sardegna
|
||||
VT;Viterbo;Lazio
|
||||
VV;Vibo Valentia;Calabria
|
||||
|
@@ -0,0 +1,41 @@
|
||||
using Khaemhat.Fiscal.Abstractions;
|
||||
using Khaemhat.Infrastructure.Files;
|
||||
|
||||
namespace Khaemhat.Fiscal.Italy;
|
||||
|
||||
/// <summary>
|
||||
/// The Italian provinces and municipalities from the ISTAT list of municipality codes (ADR 0028): abbreviation, name and
|
||||
/// region of the 110 provinces, and cadastral code, name, province, region and ISTAT code of every municipality. The
|
||||
/// list has no postal codes. The files are read once, the first time they are needed.
|
||||
/// </summary>
|
||||
public sealed class ItalianPlaces : IPlaceDirectory
|
||||
{
|
||||
/// <summary>The source of the embedded files.</summary>
|
||||
public const string ListSource = "ISTAT, Codici statistici delle unità amministrative territoriali, 26/02/2026 (CC BY 4.0)";
|
||||
|
||||
private readonly Lazy<IReadOnlyList<ProvinceTemplate>> _provinces = new(ReadProvinces);
|
||||
private readonly Lazy<IReadOnlyList<MunicipalityTemplate>> _municipalities = new(ReadMunicipalities);
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Source => ListSource;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<ProvinceTemplate> Provinces => _provinces.Value;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<MunicipalityTemplate> Municipalities => _municipalities.Value;
|
||||
|
||||
private static IReadOnlyList<ProvinceTemplate> ReadProvinces() =>
|
||||
[.. Read("province.csv").Select(l => new ProvinceTemplate(l[0], l[1], l[2]))];
|
||||
|
||||
private static IReadOnlyList<MunicipalityTemplate> ReadMunicipalities() =>
|
||||
[.. Read("comuni.csv").Select(l => new MunicipalityTemplate(l[0], l[1], l[2], l[3], l[4], null))];
|
||||
|
||||
private static List<IReadOnlyList<string>> Read(string file)
|
||||
{
|
||||
using var stream = typeof(ItalianPlaces).Assembly.GetManifestResourceStream("Khaemhat.Fiscal.Italy.Data." + file)
|
||||
?? throw new InvalidOperationException($"The file {file} is missing from the assembly.");
|
||||
using var reader = new StreamReader(stream);
|
||||
return [.. CsvReader.Parse(reader.ReadToEnd(), ';').Skip(1)];
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace Khaemhat.Fiscal.Italy;
|
||||
public sealed class ItalyFiscalPack : FiscalPackBase
|
||||
{
|
||||
/// <summary>The version of the Italian base data and code lists.</summary>
|
||||
public const string Version = "IT 2026.2";
|
||||
public const string Version = "IT 2026.3";
|
||||
|
||||
/// <summary>Creates the pack with every feature this version delivers.</summary>
|
||||
public ItalyFiscalPack()
|
||||
@@ -20,6 +20,7 @@ public sealed class ItalyFiscalPack : FiscalPackBase
|
||||
AddFeature<ITaxPaymentFormExporter>(new F24Exporter());
|
||||
AddFeature<ITaxIdentifierRules>(new ItalianTaxIdentifierRules());
|
||||
AddFeature<IBaseTablesTemplate>(new ItalianBaseTables());
|
||||
AddFeature<IPlaceDirectory>(new ItalianPlaces());
|
||||
|
||||
// ABI and CAB are read from every Italian IBAN; bank names and BICs arrive with the ABI list (ADR 0026).
|
||||
AddFeature<IBankDirectory>(new ItalianBankDirectory([]));
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
<RootNamespace>Khaemhat.Fiscal.Italy</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Provinces and municipalities from the ISTAT list (ADR 0028). -->
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Data/*.csv" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../Khaemhat.Core/Khaemhat.Core.csproj" />
|
||||
<ProjectReference Include="../Khaemhat.Fiscal.Abstractions/Khaemhat.Fiscal.Abstractions.csproj" />
|
||||
|
||||
Reference in new issue
Block a user