Commit 770d21295753c57d200eb79dd67b5191d849a5d8

Authored by hitier
1 parent 28a7e0a2

Now add only non-zero charge

Showing 1 changed file with 10 additions and 1 deletions   Show diff stats
app/commands/commands.py
... ... @@ -81,11 +81,19 @@ def feed_from_irap(csv_file_name):
81 81 db.session.add(n_s)
82 82 db.session.commit()
83 83  
  84 + # Feed periods names
  85 + # Todo: should come from year column name
  86 + #
84 87 for p in range(2011, 2030):
85 88 n_p = Period(name=f"{p}")
86 89 db.session.add(n_p)
87 90 db.session.commit()
88 91  
  92 + # Now feed the charges.
  93 + #
  94 + # At least one for each csv row
  95 + # At most one for each year
  96 + #
89 97 for r in rows:
90 98 p = Project.query.filter(Project.name == r[project_key]).one()
91 99 a = Agent.query.filter(Agent.firstname == r[firstname_key], Agent.secondname == r[secondname_key]).one()
... ... @@ -96,8 +104,9 @@ def feed_from_irap(csv_file_name):
96 104 try:
97 105 charge = int(100 * float(charge))
98 106 except ValueError:
99   - # print(f"Wrong charge {charge}")
100 107 charge = 0
  108 + if charge == 0:
  109 + continue
101 110 n_c = Charge(agent_id=a.id,
102 111 project_id=p.id,
103 112 service_id=s.id,
... ...