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,11 +81,19 @@ def feed_from_irap(csv_file_name):
81 db.session.add(n_s) 81 db.session.add(n_s)
82 db.session.commit() 82 db.session.commit()
83 83
  84 + # Feed periods names
  85 + # Todo: should come from year column name
  86 + #
84 for p in range(2011, 2030): 87 for p in range(2011, 2030):
85 n_p = Period(name=f"{p}") 88 n_p = Period(name=f"{p}")
86 db.session.add(n_p) 89 db.session.add(n_p)
87 db.session.commit() 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 for r in rows: 97 for r in rows:
90 p = Project.query.filter(Project.name == r[project_key]).one() 98 p = Project.query.filter(Project.name == r[project_key]).one()
91 a = Agent.query.filter(Agent.firstname == r[firstname_key], Agent.secondname == r[secondname_key]).one() 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,8 +104,9 @@ def feed_from_irap(csv_file_name):
96 try: 104 try:
97 charge = int(100 * float(charge)) 105 charge = int(100 * float(charge))
98 except ValueError: 106 except ValueError:
99 - # print(f"Wrong charge {charge}")  
100 charge = 0 107 charge = 0
  108 + if charge == 0:
  109 + continue
101 n_c = Charge(agent_id=a.id, 110 n_c = Charge(agent_id=a.id,
102 project_id=p.id, 111 project_id=p.id,
103 service_id=s.id, 112 service_id=s.id,