Skip to content
Snippets Groups Projects

Cristin64

Merged Petr.Kalashnikov requested to merge cristin64 into master
2 unresolved threads
Files
2
+ 30
28
@@ -127,10 +127,9 @@ def add_persons(root: ET.Element,
stedskoder: typing.List = []) -> None:
"""Add persons to the Element"""
personer = ET.SubElement(root, 'personer')
all_ansettelser = {}
for person_data in persons:
all_ansettelser = []
if '_stillinger' in person_data and len(person_data['_stillinger']) > 0:
num_ansettelser = 0
for stilling in person_data['_stillinger']:
# Verify employment info good enough for export
stil_model = Stilling(**stilling)
@@ -150,10 +149,12 @@ def add_persons(root: ET.Element,
avd, undavd, gruppe = get_stedkode(context, org.id)
if not avd or not undavd or not gruppe:
continue
stedskode = str(avd) + str(undavd) + str(gruppe)
if not stedskode in stedskoder:
continue
# Don't create the ansettelser element until we know we can add at least
# one element to it
num_ansettelser += 1
all_ansettelser[num_ansettelser] = {'institusjonsnr': str(
all_ansettelser.append({'institusjonsnr': str(
context.config.source_info.institusjonsnr),
'avd': avd,
'undavd': undavd,
@@ -165,7 +166,10 @@ def add_persons(root: ET.Element,
'datoTil': stil_model.innehaver[
0].innehaver_sluttdato,
'stillingsbetegnelse': stil_model.stillingsnavn
}
})
if not all_ansettelser:
continue
# Validate and adjust values if possible, otherwise skip person
values = {
@@ -199,29 +203,27 @@ def add_persons(root: ET.Element,
for k, v in values_none_okay.items():
if v is not None:
set_text(person, k, v)
if len(all_ansettelser.keys()) > 0:
ansettelser = ET.SubElement(person, 'ansettelser')
for ans_num in all_ansettelser.keys():
ansettelse = ET.SubElement(ansettelser, 'ansettelse')
ans_dict = all_ansettelser[ans_num]
set_text(ansettelse, 'institusjonsnr',
ans_dict['institusjonsnr'])
set_text(ansettelse, 'avdnr', ans_dict['avd'])
set_text(ansettelse, 'undavdnr', ans_dict['undavd'])
set_text(ansettelse, 'gruppenr', ans_dict['gruppe'])
# Use last 4 digits of stillingskode. API typically gives 20001234
# but we only want 1234
set_text(ansettelse, 'stillingskode',
ans_dict['stillingskode'])
set_text(ansettelse, 'datoFra',
ans_dict['datoFra'])
set_text(ansettelse, 'datoTil',
ans_dict['datoTil'])
if ans_dict['stillingsbetegnelse']:
set_text(ansettelse, 'stillingsbetegnelse',
ans_dict['stillingsbetegnelse'])
# set_text(ansettelse, 'stillingsandel', ???)
ansettelser = ET.SubElement(person, 'ansettelser')
for ans_dict in all_ansettelser:
ansettelse = ET.SubElement(ansettelser, 'ansettelse')
set_text(ansettelse, 'institusjonsnr',
ans_dict['institusjonsnr'])
set_text(ansettelse, 'avdnr', ans_dict['avd'])
set_text(ansettelse, 'undavdnr', ans_dict['undavd'])
set_text(ansettelse, 'gruppenr', ans_dict['gruppe'])
# Use last 4 digits of stillingskode. API typically gives 20001234
# but we only want 1234
set_text(ansettelse, 'stillingskode',
ans_dict['stillingskode'])
set_text(ansettelse, 'datoFra',
ans_dict['datoFra'])
set_text(ansettelse, 'datoTil',
ans_dict['datoTil'])
if ans_dict['stillingsbetegnelse']:
set_text(ansettelse, 'stillingsbetegnelse',
ans_dict['stillingsbetegnelse'])
# set_text(ansettelse, 'stillingsandel', ???)
def make_root_element() -> ET.Element:
Loading