fix(enrichment): apply approved AI data to Company fields, not just CompanyAIInsights
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
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
Approved proposals were only written to company_ai_insights table. Now also writes to Company.description_short, services_offered, core_values, industry_sector — but ONLY when the field is currently empty. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3ac323d500
commit
328c9b703c
@ -1136,6 +1136,38 @@ def api_get_proposals(company_id):
|
||||
db.close()
|
||||
|
||||
|
||||
def _apply_ai_to_company(company, ai_data, fields):
|
||||
"""Apply approved AI enrichment data to Company fields (only empty ones)."""
|
||||
def _empty(val):
|
||||
return not val or (isinstance(val, str) and not val.strip())
|
||||
|
||||
if 'business_summary' in fields and _empty(company.description_short):
|
||||
company.description_short = ai_data.get('business_summary')
|
||||
|
||||
if 'services_list' in fields and _empty(company.services_offered):
|
||||
services = ai_data.get('services_list', [])
|
||||
if isinstance(services, list):
|
||||
company.services_offered = ', '.join(services)
|
||||
elif services:
|
||||
company.services_offered = services
|
||||
|
||||
if 'company_values' in fields and _empty(company.core_values):
|
||||
values = ai_data.get('company_values', [])
|
||||
if isinstance(values, list):
|
||||
company.core_values = ', '.join(values)
|
||||
elif values:
|
||||
company.core_values = values
|
||||
|
||||
if 'industry_tags' in fields and _empty(company.industry_sector):
|
||||
tags = ai_data.get('industry_tags', [])
|
||||
if isinstance(tags, list):
|
||||
company.industry_sector = ', '.join(tags[:3])
|
||||
elif tags:
|
||||
company.industry_sector = tags
|
||||
|
||||
company.last_updated = datetime.utcnow()
|
||||
|
||||
|
||||
@bp.route('/company/<int:company_id>/proposals/<int:proposal_id>/approve', methods=['POST'])
|
||||
@login_required
|
||||
def api_approve_proposal(company_id, proposal_id):
|
||||
@ -1220,6 +1252,9 @@ def api_approve_proposal(company_id, proposal_id):
|
||||
)
|
||||
db.add(new_insights)
|
||||
|
||||
# Also apply approved data to Company fields (only if currently empty)
|
||||
_apply_ai_to_company(company, ai_data, fields_to_apply)
|
||||
|
||||
# Update proposal status
|
||||
proposal.status = 'approved'
|
||||
proposal.reviewed_at = datetime.utcnow()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user