Skip to content
Snippets Groups Projects

Cristin64

Merged Petr.Kalashnikov requested to merge cristin64 into master
2 unresolved threads
+ 33
36
@@ -128,8 +128,10 @@ def add_persons(root: ET.Element,
"""Add persons to the Element"""
personer = ET.SubElement(root, 'personer')
for person_data in persons:
all_ansettelser = []
if '_stillinger' in person_data and len(person_data['_stillinger']) > 0:
for stilling in person_data['_stillinger']:
# Verify employment info good enough for export
stil_model = Stilling(**stilling)
if not stilling_validate_fields(stil_model):
logger.warning(
@@ -137,6 +139,7 @@ def add_persons(root: ET.Element,
" Skipping employment info.",
person_data["id"])
continue
org_enhet_nr = int(stil_model.organisasjon_id)
if org_enhet_nr not in organizations:
logger.warning("No orgenhet found for stilling %r",
@@ -144,9 +147,26 @@ def add_persons(root: ET.Element,
continue
org = organizations[org_enhet_nr]
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
all_ansettelser.append({'institusjonsnr': str(
context.config.source_info.institusjonsnr),
'avd': avd,
'undavd': undavd,
'gruppe': gruppe,
'stillingskode': str(
stil_model.stillingskode)[-4:],
'datoFra': stil_model.innehaver[
0].innehaver_startdato,
'datoTil': stil_model.innehaver[
0].innehaver_sluttdato,
'stillingsbetegnelse': stil_model.stillingsnavn
})
# Validate and adjust values if possible, otherwise skip person
values = {
@@ -181,50 +201,27 @@ def add_persons(root: ET.Element,
if v is not None:
set_text(person, k, v)
if '_stillinger' in person_data and len(person_data['_stillinger']) > 0:
ansettelser_made = False
for stilling in person_data['_stillinger']:
# Verify employment info good enough for export
stil_model = Stilling(**stilling)
if not stilling_validate_fields(stil_model):
logger.warning(
"Employee %s has insufficient employment info in db."
" Skipping employment info.",
person_data["id"])
continue
org_enhet_nr = int(stil_model.organisasjon_id)
if org_enhet_nr not in organizations:
logger.warning("No orgenhet found for stilling %r",
stilling)
continue
org = organizations[org_enhet_nr]
avd, undavd, gruppe = get_stedkode(context, org.id)
if not avd or not undavd or not gruppe:
continue
# Don't create the ansettelser element until we know we can add at least
# one element to it
if not ansettelser_made:
ansettelser = ET.SubElement(person, 'ansettelser')
ansettelser_made = True
# Create the entry
if len(all_ansettelser) > 0:
ansettelser = ET.SubElement(person, 'ansettelser')
for ans_num in range(len(all_ansettelser)):
ansettelse = ET.SubElement(ansettelser, 'ansettelse')
ans_dict = all_ansettelser[ans_num]
set_text(ansettelse, 'institusjonsnr',
str(context.config.source_info.institusjonsnr))
set_text(ansettelse, 'avdnr', avd)
set_text(ansettelse, 'undavdnr', undavd)
set_text(ansettelse, 'gruppenr', gruppe)
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',
str(stil_model.stillingskode)[-4:])
ans_dict['stillingskode'])
set_text(ansettelse, 'datoFra',
stil_model.innehaver[0].innehaver_startdato)
ans_dict['datoFra'])
set_text(ansettelse, 'datoTil',
stil_model.innehaver[0].innehaver_sluttdato)
if stil_model.stillingsnavn is not None:
ans_dict['datoTil'])
if ans_dict['stillingsbetegnelse']:
set_text(ansettelse, 'stillingsbetegnelse',
stil_model.stillingsnavn)
ans_dict['stillingsbetegnelse'])
# set_text(ansettelse, 'stillingsandel', ???)
Loading