Source code for viiapackage.reporting.helper_functions.viia_get_ontwerpnotitie_report_data

### ===================================================================================================================
###   FUNCTION: Get data for the design note
### ===================================================================================================================
# Copyright ©VIIA 2025

### ===================================================================================================================
###   1. Import modules
### ===================================================================================================================

# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, Optional, List

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject
from viiapackage.database import myviia_get_eng_measure
from viiapackage.strengthening import GMCMeasures
from viiapackage.reporting.helper_functions.viia_get_address_info import viia_get_address_info
from viiapackage.reporting.helper_functions.viia_report_date import viia_report_date


### ===================================================================================================================
###   2. Function to collect the data required for the design note (Ontwerpnotitie)
### ===================================================================================================================

[docs]def get_ontwerpnotitie_report_data(project: ViiaProject, extra_object_parts: Optional[List[str]] = None) -> dict: """ This function will generate dictionary keys for ontwerpnotitie report data that can later be used as jinja tags for templating. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - extra_object_parts (list of str): List of names of extra object parts to include in the report. Default value is None. Output: - Dictionary of jinja tags assigned to corresponding info. """ # Collect the general info which is retrieved from MYVIIA at project initialisation general_info = project.project_information # Check if general info is retrieved from MYVIIA if 'id' not in general_info: project.write_log( f"WARNING: No general information is retrieved from MYVIIA database for this object. General information " f"is not replaced in the design note.") return {} # Collect the data for the template of the design note context = { 'objectnaam': general_info.get('objectnaam', ''), 'projectnaam': general_info['opdracht_id'].get('projectnaam', '').replace('&', 'en'), 'datum': viia_report_date(), 'status': general_info.get('object_status_id', {}).get('status', 'ONBEKEND').capitalize(), 'AD_nummer': general_info.get('projectnummer_og', 'ONBEKEND'), 'npr_versie': general_info.get('npr_versie', 'ONBEKENDE NPR'), 'tijdsperiode': general_info.get('reference_period', 'ONBEKENDE TIJDSPERIODE'), 'PGA': general_info.get('pga', 'onbekend'), 'gevolgklasse': general_info.get('gevolgklasse', 'onbekend'), 'datum_bewoners_overleg': None} # Find the required deliverables of this object in MYVIIA design_note_deliverables = [] tva_deliverables = {} if 'objectdelen' in general_info and general_info['objectdelen']: for object_part in general_info['objectdelen']: object_part_name = object_part['naam'] for deliverable in object_part['deliverables']: if deliverable['deliverable_id']['deliverable'] == 'Ontwerpnotitie': design_note_deliverables.append(deliverable) if deliverable['deliverable_id']['deliverable'] == 'TVA': if object_part_name not in tva_deliverables: tva_deliverables[object_part_name] = [] tva_deliverables[object_part_name].append(deliverable) # Check the deliverable for the design note, it should be one only if len(design_note_deliverables) == 0: raise ValueError( f"ERROR: The design note deliverable in MYVIIA for {project.name} could not be retrieved. Inform the " f"projectleader that the deliverable should be added in MYVIIA.") elif len(design_note_deliverables) > 1: raise ValueError( f"ERROR: Multiple design note deliverables are found in MYVIIA for {project.name}. Inform the " f"projectleader that there is something wrong in MYVIIA.") context['versienummer'] = design_note_deliverables[0].get('versienummer', 'ONBEKEND') # Collect the address(es) and related info for the object address_string, address_list, dossier_nrs, postcode, municipality = \ viia_get_address_info(project=project, myviia_data_object_address=general_info.get('object_adressen', [])) context['adres'] = address_string context['postcode'] = postcode context['woonplaats'] = municipality context['monument'] = general_info.get('erfgoed_status', 'ONBEKEND') context['rekenmethodiek'] = ','.join( set([ deel['rekenmethodiek_id'].get('rekenmethodiek', '') for deel in general_info.get('objectdelen', []) if deel.get('rekenmethodiek_id', None)])) # Check the agency that generated the TVA context['bureau_opsteller'] = 'VIIA' if not tva_deliverables: context['bureau_opsteller'] = None context['tva_deliverables'] = [] if len(tva_deliverables.keys()) > 1: for object_part_name, tva in tva_deliverables.items(): if len(tva) != 1: raise ValueError( f"ERROR: Multiple TVA reports found on MYVIIA for {project.name}. Inform the projectleader that " f"there is something wrong in MYVIIA. ") context['tva_deliverables'].append(f'TVA - {object_part_name}') else: context['tva_deliverables'].append('TVA') # Check the category of strengthening (small, medium or large) strengthening_category = general_info.get('conclusie_analyse', 'ONBEKEND') if 'versterking benodigd' in strengthening_category: if 'klein' in strengthening_category: strengthening_category = 'Klein' elif 'gemiddeld' in strengthening_category: strengthening_category = 'Gemiddeld' elif 'zwaar' in strengthening_category: strengthening_category = 'Zwaar' else: strengthening_category = 'Versterking benodigd, CATEGORIE NIET INGEVULD' else: strengthening_category = strengthening_category.upper() context['categorie_versterking_KMG'] = strengthening_category # Check strengthening advice report discussed with resident context['bvva'] = None if general_info.get('vg_projectleider_fase3') and len(fase3 := general_info.get('vg_projectleider_fase3')) > 0: if fase3[-1].get('eerste_gespreksverslag') and fase3[-1].get('vrijgave_bevindingenrapport') and \ fase3[-1].get('vrijgave_ontwerpnotitie'): context['bvva'] = 'ja' else: context['bvva'] = 'nee' # Get the strengthening measures iteration = 0 engineering_measures = [] if 'objectdelen' in general_info and general_info['objectdelen']: for object_part in general_info['objectdelen']: if object_part['iteratie'] and object_part['iteratie'] > iteration: iteration = object_part['iteratie'] for object_part in general_info['objectdelen']: if object_part['iteratie'] in [0, iteration]: engineering_measures.extend( myviia_get_eng_measure(object_deel_id=object_part['id'], token=project.token)) context['engineering_measures'] = engineering_measures measure_description = GMCMeasures().get_strengthening_measures(project) for measure in context['engineering_measures']: measure['description'] = measure_description.get(measure['name'], {}).get('description_nl', '') # Return collected data return context
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================