def _split_latest_activity(): IncubusFactory.get_instance().user_event() last_activity = Activity(Activity.get_last_activity()) as_window = activity_split.ActivitySplit() as_window.fill_with_activity(last_activity) as_window.mainloop()
def all_activities(self) -> dict: """ Returns all activities """ if not self._all_activities_read: self._all_activities = Activity.get_activities() for act in self._all_activities["activities"]: activity = Activity(act) act["date"] = date_time.get_formatted_date(activity.date) self._all_activities_read = True return self._all_activities
def _delete_click(self): deletable_activities = self._selected_activities if len(deletable_activities) == 0: return deletable_guids = [] for act in deletable_activities: deletable_guids.append(act.guid) backup.execute() Activity.delete_activities(deletable_guids) self._fill_tree_with_activities() PrimeSingleton.get().refresh()
def _fill_tree_with_activities(self): self._activities = Activity.get_activities() self._activities["activities"] = sorted( self._activities["activities"], key=lambda x: x["date"], reverse=True) self._tree_content = {} self._tree.delete(*self._tree.get_children()) for activity_line in self._activities["activities"]: activity_obj = activity.Activity(activity_line) project_obj = activity_obj.project tree_val = ( project_obj.client.name, project_obj.name, activity_obj.location, activity_obj.guid ) id_in_tree = self._tree.insert( '', 'end', text=date_time.get_formatted_date(activity_obj.date), value=tree_val ) self._tree_content[id_in_tree] = activity_obj self.update()
def result(self) -> dict: """ Returns net worth """ self._result = {"NetWorth": []} self._sum_val = 0 # Bank account balance bank_account_balance = bank_account.get_current_account_balance_sum() self._append_result("Bank account balance", bank_account_balance) # Reserved balance reserved_balance = bank_account.get_reserved_balance() * -1 self._append_result("Reserved balance", reserved_balance) # Credit card debt credit_card_debt = credit_card.get_current_credit_card_debt_sum() * -1 self._append_result("Credit card debt", credit_card_debt) # SUM: Liquid cash self._append_sum("Cash") # Activity earnings activity_earning = Activity.get_total_activity_earnings() self._append_result("Activity earning", activity_earning) # Activity income tax inc_tax_rate = IncomeTaxCalculatorFactory.get_instance( ).default_tax_rate activity_tax = activity_earning * inc_tax_rate / 100 * -1 self._append_result("Activity tax", activity_tax) # Payment balance payment_balance = payment.get_payment_balance() self._append_result("Payment balance", payment_balance) # SUM: Short term money self._append_sum("Short term money") # Reserved balance again reserved_balance *= -1 self._append_result("Reserved balance", reserved_balance) # SUM: Total money self._append_sum("Total money") # Asset resale asset_resales = asset.get_asset_type_resale_value_sum( deduct_income_tax=True, own_percentage_only=True) for asset_resale in asset_resales: self._append_result(asset_resale["type"] + " resale", asset_resale["sales_value"]) # SUM: Net worth self._append_sum("Net worth") # Return return self._result
def fill_with_last_activity(self): """ Fills window with last activity """ last_activity = Activity.get_last_activity() if last_activity == {}: return act_obj = model.timesheet.activity.Activity(last_activity) act_obj.guid = "" act_obj.date = datetime.datetime.today() self.fill_with_activity(act_obj) self._set_status("(filled with last activity)")
def todays_activities(self) -> dict: """ Returns todays activities """ if not self._todays_activities_read: self._todays_activities = {"activities": []} all_activities = self.all_activities for act in all_activities["activities"]: activity = Activity(act) if date_time.is_today(activity.date): self._todays_activities["activities"].append(act) self._todays_activities_read = True return self._todays_activities
def forecast_tax_rate(self) -> float: """ Returns forecast tax rate """ if not self._forecast_tax_rate_calculated: # Last year (with inflation) last_year = date.today().year - 1 last_year_invoices = get_invoices_of_fiscal_year(last_year) invoice_sum = 0 for invoice in last_year_invoices: home_amount = self._converter.convert_to_local_currency( invoice["amount"], invoice["currency"]) home_amount *= 1 + (config.CONSTANTS["TUFE_RATE"] / 100) invoice_sum += home_amount if invoice_sum == 0: last_year_rate = 0 else: last_year_annual_tax = self._calc_annual_tax(invoice_sum) last_year_rate = last_year_annual_tax / invoice_sum # This year (projection) this_year_invoices = get_invoices_of_fiscal_year(date.today().year) invoice_sum = 0 for invoice in this_year_invoices: home_amount = self._converter.convert_to_local_currency( invoice["amount"], invoice["currency"]) home_amount *= 1 + (config.CONSTANTS["TUFE_RATE"] / 100) invoice_sum += home_amount invoice_sum += Activity.get_total_activity_earnings() invoice_sum = invoice_sum * (12 - (date.today().month) + 1) if invoice_sum == 0: this_year_rate = 0 else: this_year_annual_tax = self._calc_annual_tax(invoice_sum) this_year_rate = this_year_annual_tax / invoice_sum # Average if this_year_rate == 0: self._forecast_tax_rate = last_year_rate elif last_year_rate == 0: self._forecast_tax_rate = this_year_rate else: if this_year_rate > last_year_rate: self._forecast_tax_rate = this_year_rate else: self._forecast_tax_rate = (this_year_rate + last_year_rate) / 2 self._forecast_tax_rate *= 100 self._forecast_tax_rate_calculated = True return self._forecast_tax_rate
def entire_dataset(self) -> dict: """ Returns entire dataset """ hour_sum = 0 for act in self.all_activities["activities"]: activity = Activity(act) hour_sum += activity.hours result = { "today": self.todays_activities["activities"], "all": self.all_activities["activities"], "hour_sum": hour_sum, "day_sum": len(self.all_activities["activities"]) } return result
def get_notifications() -> List: """ Builds and returns a notification list """ output = [] if not Activity.has_activity_for_today(): output.append(ICON_YELLOW + "No activity entered for today") # Completed payments for pay in payment.get_completed_payments(): line = ICON_GREEN + "Completed Payment" line += _get_payment_suffix(pay) output.append(line) # pylint: disable=C0301 # Approaching or late payments for pay in get_raw_recurrence_list(): output.append(pay[1]) # Flush return output
def startup(): """ Main startup function """ config.read_constants() backup.clear_old_backups() if "-test" in sys.argv: config.test_mode() else: payment.generate_high_time_recurrences() if config.CONSTANTS["UPDATE_ON_STARTUP"]: UpdateFacadeFactory.get_instance().execute() add_activity = all([ date_time.is_working_day(datetime.datetime.now()), not Activity.has_activity_for_today() ]) prime = Prime(add_activity=add_activity) PrimeSingleton.set(prime) prime.start()
def _append_month(self, year: int, month: int, elem: str): sap_year = str(year) sap_month = date_time.get_two_digit_month(month) ecz_activities = ecz_daha.get_monthly_activity(p_sap_year=sap_year, p_sap_month=sap_month) for ecz_activity in ecz_activities: date_of_activity = date_time.parse_sap_date(ecz_activity["date"]) kifu_hour_sum = Activity.get_time_sum(client_name=self._ecz, date=date_of_activity) date = date_time.get_formatted_date( date_time.parse_sap_date(ecz_activity["date"])) entry = { "date": date, "comment": ecz_activity["comment"], "ecz_hours": ecz_activity["hours"], "kifu_hours": kifu_hour_sum, "different": kifu_hour_sum != ecz_activity["hours"] } self._result[elem].append(entry)
def generate(self): """ Generate report with all activities """ self._generate_with_dict(Activity.get_activities())
def _read_activities(self): self._activities = [] for activity_dict in Activity.get_activities()["activities"]: self._activities.append(Activity(activity_dict)) sorted(self._activities, key=lambda activity: activity.date)
def fill_with_last_activity(self): """ Fills window with latest activity """ last_activity = Activity.get_last_activity() if last_activity == {}: return self.fill_with_activity(last_activity)