fix: complete KRS enrichment mapping (REGON, address, PKD, NIP)
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions

The KRS enrichment function was only mapping forma_prawna, legal_name
and capital. Now maps REGON, address (ulica + nr_domu), city, postal,
primary PKD code on Company model, and NIP if missing. Fixed field
name mismatches: nr_domu (not numer), opis (not nazwa), glowna (not
glowny). City names are title-cased from KRS uppercase format.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-02-20 13:38:34 +01:00
parent e92accc1ed
commit 4b325cc483

View File

@ -76,15 +76,52 @@ def _enrich_company_from_krs(company, db):
# Additional fields from KRS
if data_dict.get('forma_prawna'):
company.legal_form = data_dict['forma_prawna']
if data_dict.get('nazwa_pełna'):
company.legal_name = data_dict['nazwa_pełna']
if data_dict.get('nazwa'):
company.legal_name = data_dict['nazwa']
if data_dict.get('sposob_reprezentacji'):
company.krs_representation = data_dict['sposob_reprezentacji']
# REGON
regon = data_dict.get('regon', '')
if regon:
# KRS returns 14-digit REGON, strip trailing zeros for 9-digit form
company.regon = regon.rstrip('0') if len(regon) > 9 else regon
# NIP (if missing)
if not company.nip and data_dict.get('nip'):
company.nip = data_dict['nip']
# Address
adres = data_dict.get('adres', {})
if adres:
ulica = adres.get('ulica', '')
nr_domu = adres.get('nr_domu', '')
nr_lokalu = adres.get('nr_lokalu', '')
addr_street = ulica
if nr_domu:
addr_street += f' {nr_domu}'
if nr_lokalu:
addr_street += f'/{nr_lokalu}'
if addr_street and not company.address_street:
company.address_street = addr_street
miasto = adres.get('miejscowosc') or adres.get('poczta')
if miasto and not company.address_city:
company.address_city = miasto.title()
if adres.get('kod_pocztowy') and not company.address_postal:
company.address_postal = adres['kod_pocztowy']
# Capital
kapital = data_dict.get('kapital', {})
if kapital.get('zakladowy'):
company.capital_amount = kapital['zakladowy']
# Primary PKD on Company model
pkd_list = data_dict.get('przedmiot_dzialalnosci', [])
primary_pkd = next((p for p in pkd_list if p.get('glowna')), pkd_list[0] if pkd_list else None)
if primary_pkd and not company.pkd_code:
company.pkd_code = primary_pkd.get('kod', '')
company.pkd_description = primary_pkd.get('opis', '')
# Import board members (zarząd)
with db.no_autoflush:
for osoba in data_dict.get('zarzad', []):
@ -124,8 +161,8 @@ def _enrich_company_from_krs(company, db):
# Import PKD codes
for pkd in data_dict.get('przedmiot_dzialalnosci', []):
kod = pkd.get('kod', '')
nazwa = pkd.get('nazwa', '')
is_primary = pkd.get('glowny', False)
nazwa = pkd.get('opis', '') or pkd.get('nazwa', '')
is_primary = pkd.get('glowna', False) or pkd.get('glowny', False)
if not kod:
continue