Commit 61e60a1fbb9c3ede574524dd45c4f536102f0066

Authored by hitier
1 parent 770d2129

Now add default capacity

Showing 1 changed file with 10 additions and 4 deletions   Show diff stats
app/commands/commands.py
@@ -43,8 +43,8 @@ def feed_from_irap(csv_file_name): @@ -43,8 +43,8 @@ def feed_from_irap(csv_file_name):
43 secondname_key = 'prénom' 43 secondname_key = 'prénom'
44 project_key = 'PROJETS' 44 project_key = 'PROJETS'
45 service_key = 'Groupe métier' 45 service_key = 'Groupe métier'
46 - typology_title = 'TYPOLOGIE'  
47 - thematic_title = 'thématique' 46 + # typology_title = 'TYPOLOGIE'
  47 + # thematic_title = 'thématique'
48 48
49 # Get the columns values 49 # Get the columns values
50 # 50 #
@@ -82,13 +82,18 @@ def feed_from_irap(csv_file_name): @@ -82,13 +82,18 @@ def feed_from_irap(csv_file_name):
82 db.session.commit() 82 db.session.commit()
83 83
84 # Feed periods names 84 # Feed periods names
85 - # Todo: should come from year column name 85 + # Todo: are statically built,
  86 + # should come from year column name.
86 # 87 #
87 for p in range(2011, 2030): 88 for p in range(2011, 2030):
88 n_p = Period(name=f"{p}") 89 n_p = Period(name=f"{p}")
89 db.session.add(n_p) 90 db.session.add(n_p)
90 db.session.commit() 91 db.session.commit()
91 92
  93 + # Add one default capacity
  94 + db.session.add(Capacity(name="Travailleur"))
  95 + db.session.commit()
  96 +
92 # Now feed the charges. 97 # Now feed the charges.
93 # 98 #
94 # At least one for each csv row 99 # At least one for each csv row
@@ -98,6 +103,7 @@ def feed_from_irap(csv_file_name): @@ -98,6 +103,7 @@ def feed_from_irap(csv_file_name):
98 p = Project.query.filter(Project.name == r[project_key]).one() 103 p = Project.query.filter(Project.name == r[project_key]).one()
99 a = Agent.query.filter(Agent.firstname == r[firstname_key], Agent.secondname == r[secondname_key]).one() 104 a = Agent.query.filter(Agent.firstname == r[firstname_key], Agent.secondname == r[secondname_key]).one()
100 s = Service.query.filter(Service.name == r[service_key]).one() 105 s = Service.query.filter(Service.name == r[service_key]).one()
  106 + c = Capacity.query.first()
101 for period_name in range(2011, 2030): 107 for period_name in range(2011, 2030):
102 t = Period.query.filter(Period.name == period_name).one() 108 t = Period.query.filter(Period.name == period_name).one()
103 charge = r[f"{period_name}"] 109 charge = r[f"{period_name}"]
@@ -110,7 +116,7 @@ def feed_from_irap(csv_file_name): @@ -110,7 +116,7 @@ def feed_from_irap(csv_file_name):
110 n_c = Charge(agent_id=a.id, 116 n_c = Charge(agent_id=a.id,
111 project_id=p.id, 117 project_id=p.id,
112 service_id=s.id, 118 service_id=s.id,
113 - # capacity_id=0, 119 + capacity_id=c.id,
114 period_id=t.id, 120 period_id=t.id,
115 charge_rate=charge) 121 charge_rate=charge)
116 db.session.add(n_c) 122 db.session.add(n_c)