feat(company): Child brands inherit NIP from parent for display and registry enrichment
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

Child companies (with parent_company_id) now show parent's NIP and can
fetch data from KRS/CEIDG using inherited NIP. Fixes Alter Energy showing
no NIP despite sharing one with Fiume Studio.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-02-12 16:39:36 +01:00
parent 5497a9d7b0
commit d4d50a31ef
3 changed files with 32 additions and 7 deletions

View File

@ -378,7 +378,19 @@ def api_enrich_company_registry(company_id):
message_parts = []
details = {}
# For child brands (parent_company_id set, no own NIP/KRS) — inherit from parent
effective_nip = company.nip
effective_krs = company.krs
if not effective_nip and not effective_krs and company.parent_company_id:
parent = db.query(Company).filter_by(id=company.parent_company_id).first()
if parent:
effective_nip = parent.nip
effective_krs = parent.krs
# Strategy 1: Company has KRS — fetch directly
if effective_krs and not company.krs:
company.krs = effective_krs
db.flush()
if company.krs:
from blueprints.admin.routes_membership import _enrich_company_from_krs
success = _enrich_company_from_krs(company, db)
@ -403,9 +415,9 @@ def api_enrich_company_registry(company_id):
}), 404
# Strategy 2: No KRS but has NIP — try Biała Lista to find KRS
elif company.nip:
elif effective_nip:
krs_service = krs_api_service.KRSApiService()
biala_lista_result = krs_service.search_by_nip(company.nip)
biala_lista_result = krs_service.search_by_nip(effective_nip)
if biala_lista_result and biala_lista_result.get('krs'):
# Found KRS via Biała Lista — save it and enrich
@ -433,7 +445,7 @@ def api_enrich_company_registry(company_id):
message_parts.append(f'znaleziono KRS: {company.krs} (dane KRS niedostępne)')
else:
# No KRS found — try CEIDG (likely JDG)
ceidg_data = fetch_ceidg_by_nip(company.nip)
ceidg_data = fetch_ceidg_by_nip(effective_nip)
if ceidg_data:
source = 'CEIDG'
updated_fields = []
@ -481,7 +493,7 @@ def api_enrich_company_registry(company_id):
else:
return jsonify({
'success': False,
'error': 'Firma nie ma numeru NIP ani KRS — nie można pobrać danych z rejestrów'
'error': 'Firma nie ma numeru NIP ani KRS (również w firmie nadrzędnej) — nie można pobrać danych z rejestrów'
}), 400
db.commit()

View File

@ -257,9 +257,17 @@ def company_detail(company_id):
for m in company_managers:
_ = m.name, m.email # force-load before session close
# For child brands — inherit NIP from parent for display/enrichment
effective_nip = company.nip
if not effective_nip and company.parent_company_id:
parent = db.query(Company).filter_by(id=company.parent_company_id).first()
if parent:
effective_nip = parent.nip
return render_template('company_detail.html',
company=company,
company_id=company.id, # For analytics conversion tracking
effective_nip=effective_nip,
maturity_data=maturity_data,
website_analysis=website_analysis,
quality_data=quality_data,

View File

@ -660,7 +660,7 @@
id="registryEnrichBtn"
class="registry-enrich-btn"
data-company-id="{{ company.id }}"
data-nip="{{ company.nip or '' }}"
data-nip="{{ effective_nip or company.nip or '' }}"
data-krs="{{ company.krs or '' }}"
>
<span class="spinner"></span>
@ -1720,7 +1720,8 @@
</div>
<!-- NIP Card -->
{% if company.nip %}
{% set display_nip = effective_nip or company.nip %}
{% if display_nip %}
<div style="background: var(--background); border-radius: var(--radius-lg); padding: var(--spacing-lg); border: 2px solid #3b82f6;">
<div style="display: flex; align-items: center; gap: var(--spacing-md);">
<div style="width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: #3b82f6; color: white;">
@ -1730,11 +1731,15 @@
</div>
<div>
<div style="font-size: var(--font-size-sm); color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em;">NIP</div>
<div style="font-size: var(--font-size-xl); font-weight: 700; color: #3b82f6; font-family: monospace;">{{ company.nip[:3] }}-{{ company.nip[3:6] }}-{{ company.nip[6:8] }}-{{ company.nip[8:] }}</div>
<div style="font-size: var(--font-size-xl); font-weight: 700; color: #3b82f6; font-family: monospace;">{{ display_nip[:3] }}-{{ display_nip[3:6] }}-{{ display_nip[6:8] }}-{{ display_nip[8:] }}</div>
</div>
</div>
<div style="font-size: var(--font-size-sm); color: var(--text-secondary); padding-left: 60px; margin-top: var(--spacing-sm);">
{% if not company.nip and company.parent_company_id %}
NIP firmy nadrzędnej
{% else %}
Źródło: <strong style="color: #10b981;">Rejestr KRS</strong>
{% endif %}
</div>
</div>
{% endif %}