cr-reunion: load exisiting benficiaires from carddata to support mulitple run (#84828)
gitea/misc-cazino/pipeline/head This commit looks good
Details
gitea/misc-cazino/pipeline/head This commit looks good
Details
This commit is contained in:
parent
91ec320b59
commit
5e1dcda13e
|
@ -46,8 +46,14 @@ def build_cache(slug, cache):
|
|||
for card in cardef.data_class().select():
|
||||
cache[card.data[libelle_field.id].upper()] = str(card.id)
|
||||
|
||||
def get_beneficiaire_hash(row):
|
||||
return '%s##%s##%s' % (row['prenom'].strip().upper(), row['nom'].strip().upper(), row['numero fiscal'])
|
||||
|
||||
def get_beneficiaire_hash(prenom, nom, numero_fiscal):
|
||||
return '%s##%s##%s' % (prenom.strip().upper(), nom.strip().upper(), numero_fiscal)
|
||||
|
||||
|
||||
def get_beneficiaire_hash_from_row(row):
|
||||
return get_beneficiaire_hash(row['prenom'], row['nom'], row['numero fiscal'])
|
||||
|
||||
|
||||
def get_field_by_varname(cardef, varname):
|
||||
for field in cardef.fields:
|
||||
|
@ -398,6 +404,14 @@ def import_data(args):
|
|||
return extra_data
|
||||
return None
|
||||
|
||||
# Initialize BENEFICIAIRES with carddata
|
||||
beneficiaire_carddef = CardDef.get_by_urlname(CARD_BENEFICIAIRE_SLUG)
|
||||
prenom_field = get_field_by_varname(beneficiaire_carddef, 'prenom')
|
||||
nom_field = get_field_by_varname(beneficiaire_carddef, 'nom_usage')
|
||||
numero_fiscal_field = get_field_by_varname(beneficiaire_carddef, 'numero_fiscal')
|
||||
|
||||
for beneficiaire in beneficiaire_carddef.data_class().select():
|
||||
BENEFICIAIRES[get_beneficiaire_hash(beneficiaire.data[prenom_field.id], beneficiaire.data[nom_field.id], beneficiaire.data[numero_fiscal_field.id])] = str(beneficiaire.id)
|
||||
|
||||
for i, row in get_rows(args):
|
||||
|
||||
|
@ -417,12 +431,13 @@ def import_data(args):
|
|||
derogation = derogation_mapping[row['derogation']]
|
||||
|
||||
|
||||
beneficiaire_hash = get_beneficiaire_hash(row)
|
||||
beneficiaire_hash = get_beneficiaire_hash_from_row(row)
|
||||
|
||||
if beneficiaire_hash not in BENEFICIAIRES:
|
||||
email = ''
|
||||
if row['email'] != 'NULL':
|
||||
email = row['email'].lower()
|
||||
|
||||
beneficiaire_data = {
|
||||
'courriel_demandeur': email,
|
||||
'date_import': datetime.datetime.now().date().strftime('%Y-%m-%d'),
|
||||
|
@ -437,7 +452,9 @@ def import_data(args):
|
|||
BENEFICIAIRES[beneficiaire_hash] = beneficiaire_id
|
||||
|
||||
beneficiaire_id = BENEFICIAIRES[beneficiaire_hash]
|
||||
|
||||
email = ''
|
||||
if row['email'] != 'NULL':
|
||||
email = row['email'].lower()
|
||||
data = {
|
||||
'annee_demande': row['campagne'],
|
||||
'beneficiaire': beneficiaire_id,
|
||||
|
|
Loading…
Reference in New Issue