@@ -20,11 +20,20 @@ async def user_kpi_cb(
2020 callback : CallbackQuery , user : Employee , kpi_repo : KPIRequestsRepo
2121):
2222 premium = await kpi_repo .spec_premium .get_premium (fullname = user .fullname )
23- if premium is None :
23+ if (
24+ premium is None
25+ or not premium .csi_premium
26+ or not premium .flr_premium
27+ or not premium .gok_premium
28+ or not premium .tests_premium
29+ or not premium .total_premium
30+ ):
2431 await callback .message .edit_text (
2532 """🌟 <b>Показатели</b>
2633
27- Не смог найти твои показатели в премиуме :(""" ,
34+ Не смог найти твои показатели в премиуме :(
35+
36+ <i>Вернись позже, когда показатели загрузятся</i>""" ,
2837 reply_markup = kpi_kb (),
2938 )
3039 return
@@ -77,66 +86,75 @@ async def user_kpi_cb(
7786async def user_kpi_calculator_cb (
7887 callback : CallbackQuery , user : Employee , kpi_repo : KPIRequestsRepo
7988):
80- user_premium = await kpi_repo .spec_premium .get_premium (fullname = user .fullname )
89+ premium = await kpi_repo .spec_premium .get_premium (fullname = user .fullname )
8190
82- if user_premium is None :
91+ if (
92+ premium is None
93+ or not premium .csi_premium
94+ or not premium .flr_premium
95+ or not premium .gok_premium
96+ or not premium .tests_premium
97+ or not premium .total_premium
98+ ):
8399 await callback .message .edit_text (
84100 """🧮 <b>Калькулятор KPI</b>
85101
86- Не смог найти твои показатели в премиуме :(""" ,
102+ Не смог найти твои показатели в премиуме :(
103+
104+ <i>Вернись позже, когда показатели загрузятся</i>""" ,
87105 reply_markup = kpi_calculator_kb (),
88106 )
89107 return
90108
91109 csi_calculation = KPICalculator .calculate_csi_needed (
92- user .division , user_premium .csi , user_premium .csi_normative
110+ user .division , premium .csi , premium .csi_normative
93111 )
94112 flr_calculation = KPICalculator .calculate_flr_needed (
95- user .division , user_premium .flr , user_premium .flr_normative
113+ user .division , premium .flr , premium .flr_normative
96114 )
97115 gok_calculation = KPICalculator .calculate_gok_needed (
98- user .division , user_premium .gok , user_premium .gok_normative
116+ user .division , premium .gok , premium .gok_normative
99117 )
100118 target_calculation = KPICalculator .calculate_target_needed (
101- user_premium .target ,
102- user_premium .target_goal_first ,
103- user_premium .target_goal_second ,
104- user_premium .target_type ,
119+ premium .target ,
120+ premium .target_goal_first ,
121+ premium .target_goal_second ,
122+ premium .target_type ,
105123 )
106124
107125 message_text = f"""🧮 <b>Калькулятор KPI</b>
108126
109127📊 <b>Оценка клиента</b>
110- <blockquote>Текущий: { SalaryFormatter .format_value (user_premium .csi )} ({ SalaryFormatter .format_percentage (user_premium .csi_normative_rate )} )
111- План: { SalaryFormatter .format_value (user_premium .csi_normative )}
128+ <blockquote>Текущий: { SalaryFormatter .format_value (premium .csi )} ({ SalaryFormatter .format_percentage (premium .csi_normative_rate )} )
129+ План: { SalaryFormatter .format_value (premium .csi_normative )}
112130
113131<b>Для премии:</b>
114132{ csi_calculation } </blockquote>
115133
116134🔧 <b>FLR</b>
117- <blockquote>Текущий: { SalaryFormatter .format_value (user_premium .flr )} ({ SalaryFormatter .format_percentage (user_premium .flr_normative_rate )} )
118- План: { SalaryFormatter .format_value (user_premium .flr_normative )}
135+ <blockquote>Текущий: { SalaryFormatter .format_value (premium .flr )} ({ SalaryFormatter .format_percentage (premium .flr_normative_rate )} )
136+ План: { SalaryFormatter .format_value (premium .flr_normative )}
119137
120138<b>Для премии:</b>
121139{ flr_calculation } </blockquote>
122140
123141⚖️ <b>ГОК</b>
124- <blockquote>Текущий: { SalaryFormatter .format_value (round (user_premium .gok ))} ({ SalaryFormatter .format_percentage (user_premium .gok_normative_rate )} )
125- План: { SalaryFormatter .format_value (round (user_premium .gok_normative ))}
142+ <blockquote>Текущий: { SalaryFormatter .format_value (round (premium .gok ))} ({ SalaryFormatter .format_percentage (premium .gok_normative_rate )} )
143+ План: { SalaryFormatter .format_value (round (premium .gok_normative ))}
126144
127145<b>Для премии:</b>
128146{ gok_calculation } </blockquote>
129147
130148🎯 <b>Цель</b>
131- <blockquote>Факт: { SalaryFormatter .format_value (user_premium .target )} ({ SalaryFormatter .format_percentage (round ((user_premium .target_goal_first / user_premium .target * 100 ) if user_premium .target_type and "AHT" in user_premium .target_type and user_premium .target and user_premium .target > 0 and user_premium .target_goal_first else (user_premium .target / user_premium .target_goal_first * 100 ) if user_premium .target_goal_first and user_premium .target_goal_first > 0 else 0 ))} / { SalaryFormatter .format_percentage (round ((user_premium .target_goal_second / user_premium .target * 100 ) if user_premium .target_type and "AHT" in user_premium .target_type and user_premium .target and user_premium .target > 0 and user_premium .target_goal_second else (user_premium .target / user_premium .target_goal_second * 100 ) if user_premium .target_goal_second and user_premium .target_goal_second > 0 else 0 ))} )
132- План: { SalaryFormatter .format_value (round (user_premium .target_goal_first ))} / { SalaryFormatter .format_value (round (user_premium .target_goal_second ))}
149+ <blockquote>Факт: { SalaryFormatter .format_value (premium .target )} ({ SalaryFormatter .format_percentage (round ((premium .target_goal_first / premium .target * 100 ) if premium .target_type and "AHT" in premium .target_type and premium .target and premium .target > 0 and premium .target_goal_first else (premium .target / premium .target_goal_first * 100 ) if premium .target_goal_first and premium .target_goal_first > 0 else 0 ))} / { SalaryFormatter .format_percentage (round ((premium .target_goal_second / premium .target * 100 ) if premium .target_type and "AHT" in premium .target_type and premium .target and premium .target > 0 and premium .target_goal_second else (premium .target / premium .target_goal_second * 100 ) if premium .target_goal_second and premium .target_goal_second > 0 else 0 ))} )
150+ План: { SalaryFormatter .format_value (round (premium .target_goal_first ))} / { SalaryFormatter .format_value (round (premium .target_goal_second ))}
133151
134152Требуется минимум 100 { "чатов" if user .division == "НЦК" else "звонков" } для получения премии за цель
135153
136154<b>Для премии:</b>
137155{ target_calculation } </blockquote>
138156
139- <i>Данные от: { user_premium .updated_at .replace (tzinfo = datetime .timezone .utc ).astimezone (datetime .timezone (datetime .timedelta (hours = 5 ))).strftime ("%d.%m.%y %H:%M" ) if user_premium .updated_at else "—" } </i>"""
157+ <i>Данные от: { premium .updated_at .replace (tzinfo = datetime .timezone .utc ).astimezone (datetime .timezone (datetime .timedelta (hours = 5 ))).strftime ("%d.%m.%y %H:%M" ) if premium .updated_at else "—" } </i>"""
140158
141159 try :
142160 await callback .message .edit_text (message_text , reply_markup = kpi_calculator_kb ())
@@ -148,26 +166,33 @@ async def user_kpi_calculator_cb(
148166async def user_kpi_salary_cb (
149167 callback : CallbackQuery , user : Employee , kpi_repo : KPIRequestsRepo
150168):
151- user_premium = await kpi_repo .spec_premium .get_premium (fullname = user .fullname )
169+ premium = await kpi_repo .spec_premium .get_premium (fullname = user .fullname )
152170
153- if user_premium is None :
171+ if (
172+ premium is None
173+ or not premium .csi_premium
174+ or not premium .flr_premium
175+ or not premium .gok_premium
176+ or not premium .tests_premium
177+ or not premium .total_premium
178+ ):
154179 await callback .message .edit_text (
155180 """💰 <b>Расчет зарплаты</b>
156181
157- Не смог найти твои показатели в премиуме :(""" ,
182+ Не смог найти твои показатели в премиуме :(
183+
184+ <i>Вернись позже, когда показатели загрузятся</i>""" ,
158185 reply_markup = kpi_salary_kb (),
159186 )
160187 return
161188
162189 try :
163190 salary_result = await SalaryCalculator .calculate_salary (
164- user = user , premium_data = user_premium
191+ user = user , premium_data = premium
165192 )
166193
167194 # Format the result using centralized formatter
168- message_text = SalaryFormatter .format_salary_message (
169- salary_result , user_premium
170- )
195+ message_text = SalaryFormatter .format_salary_message (salary_result , premium )
171196 except Exception as e :
172197 await callback .message .edit_text (
173198 f"""💰 <b>Расчет зарплаты</b>
0 commit comments