def planned_costs(self, reporting_period=None): """The function returns the planned costs of resources which have been estimated for this task at a specific reporting period plus the costs of the effective effort before the provided reporting_period When no reporting_period is provided, the last reporting period is selected. Args: no arguments Returns: planned costs (Decimal), 0 if when no estimation or no reporting period is present Raises: No exceptions planned""" try: if not reporting_period: reporting_period_internal = ReportingPeriod.get_latest_reporting_period(self.project) else: reporting_period_internal = ReportingPeriod.objects.get(id=reporting_period.id) predecessor_reporting_periods = ReportingPeriod.get_all_predecessors(reporting_period_internal, self.project) estimations_to_this_task = Estimation.objects.filter(task=self.id, reporting_period=reporting_period_internal) sum_costs = 0 if len(estimations_to_this_task) != 0: for estimation_to_this_task in estimations_to_this_task: sum_costs += estimation_to_this_task.calculated_costs() if len(predecessor_reporting_periods) != 0: for predecessor_reporting_period in predecessor_reporting_periods: sum_costs += self.effective_costs(reporting_period=predecessor_reporting_period) except ReportingPeriodNotFound: sum_costs = 0 return sum_costs
def update_work(self, request): from koalixcrm.crm.reporting.work import Work if self.has_changed(): if self.cleaned_data['work_id']: work = Work.objects.get(id=self.cleaned_data['work_id']) else: work = Work() if self.cleaned_data['DELETE']: work.delete() else: work.task = self.cleaned_data['task'] work.reporting_period = ReportingPeriod.get_reporting_period(project=self.cleaned_data['task'].project, search_date=self.cleaned_data['date']) work.employee = UserExtension.get_user_extension(request.user) work.date = self.cleaned_data['date'] if bool(self.cleaned_data['start_time']) & bool(self.cleaned_data['stop_time']): work.start_time = datetime.datetime.combine(self.cleaned_data['date'], self.cleaned_data['start_time']) work.stop_time = datetime.datetime.combine(self.cleaned_data['date'], self.cleaned_data['stop_time']) else: work.worked_hours = self.cleaned_data['worked_hours'] work.description = self.cleaned_data['description'] work.short_description = limit_string_length(work.description, 100) work.save()
def update_work(self, request): from koalixcrm.crm.reporting.work import Work if self.has_changed(): if self.cleaned_data['work_id']: work = Work.objects.get(id=self.cleaned_data['work_id']) else: work = Work() if self.cleaned_data['DELETE']: work.delete() else: work.task = self.cleaned_data['task'] work.reporting_period = ReportingPeriod.get_reporting_period(project=self.cleaned_data['task'].project, search_date=self.cleaned_data['date']) work.human_resource = HumanResource.objects.get(user=UserExtension.get_user_extension(request.user)) work.date = self.cleaned_data['date'] if bool(self.cleaned_data['start_time']) & bool(self.cleaned_data['stop_time']): work.start_time = datetime.datetime.combine(self.cleaned_data['date'], self.cleaned_data['start_time']) work.stop_time = datetime.datetime.combine(self.cleaned_data['date'], self.cleaned_data['stop_time']) else: work.worked_hours = self.cleaned_data['worked_hours'] work.description = self.cleaned_data['description'] work.short_description = limit_string_length(work.description, 100) work.save()
def planned_effort(self, reporting_period=None): """The function return the planned effort of resources which have been estimated for this task at a specific reporting period. When no reporting_period is provided, the last reporting period is selected Args: no arguments Returns: planned effort (Decimal) [hrs], 0 if when no estimation are present Raises: no exceptions expected""" try: if not reporting_period: reporting_period_internal = ReportingPeriod.get_latest_reporting_period( self.project) else: reporting_period_internal = reporting_period estimations_to_this_task = Estimation.objects.filter(task=self.id, reporting_period=reporting_period_internal) effort = 0 for estimation_to_this_task in estimations_to_this_task: effort += estimation_to_this_task.amount except ReportingPeriodNotFound: effort = 0 return effort
def planned_effort(self, reporting_period=None): """The function return the planned effort of resources which have been estimated for this task at a specific reporting period. When no reporting_period is provided, the last reporting period is selected Args: no arguments Returns: planned effort (Decimal) [hrs], 0 if when no estimation are present Raises: no exceptions expected""" try: if not reporting_period: reporting_period_internal = ReportingPeriod.get_latest_reporting_period( self.project) else: reporting_period_internal = reporting_period estimations_to_this_task = Estimation.objects.filter( task=self.id, reporting_period=reporting_period_internal) effort = 0 for estimation_to_this_task in estimations_to_this_task: effort += estimation_to_this_task.amount except ReportingPeriodNotFound: effort = 0 return effort
def effective_accumulated_costs(self, reporting_period=None): if reporting_period: reporting_periods = ReportingPeriod.get_all_predecessors(target_reporting_period=reporting_period, project=self) else: reporting_periods = ReportingPeriod.objects.filter(project=self.id) effective_accumulated_costs = 0 for single_reporting_period in reporting_periods: all_project_tasks = Task.objects.filter(project=self.id) for task in all_project_tasks: effective_accumulated_costs += float(task.effective_costs(reporting_period=single_reporting_period)) return effective_accumulated_costs
def planned_costs(self, reporting_period=None): """The function returns the planned costs of resources which have been estimated for this task at a specific reporting period plus the costs of the effective effort before the provided reporting_period When no reporting_period is provided, the last reporting period is selected. Args: no arguments Returns: planned costs (Decimal), 0 if when no estimation or no reporting period is present Raises: No exceptions planned""" try: if not reporting_period: reporting_period_internal = ReportingPeriod.get_latest_reporting_period( self.project) else: reporting_period_internal = ReportingPeriod.objects.get( id=reporting_period.id) predecessor_reporting_periods = ReportingPeriod.get_all_predecessors( reporting_period_internal, self.project) estimations_to_this_task = Estimation.objects.filter( task=self.id, reporting_period=reporting_period_internal) sum_costs = 0 if len(estimations_to_this_task) != 0: for estimation_to_this_task in estimations_to_this_task: sum_costs += estimation_to_this_task.calculated_costs() if len(predecessor_reporting_periods) != 0: for predecessor_reporting_period in predecessor_reporting_periods: sum_costs += self.effective_costs( reporting_period=predecessor_reporting_period) except ReportingPeriodNotFound: sum_costs = 0 return sum_costs
def get_reporting_period(self, search_date): from koalixcrm.crm.reporting.reporting_period import ReportingPeriod """Returns the reporting period that is valid. Valid is a reporting period when the provided date lies between begin and end of the reporting period Args: no arguments Returns: accounting_period (ReportPeriod) Raises: ReportPeriodNotFound when there is no valid reporting Period""" return ReportingPeriod.get_reporting_period(self, search_date)
def effective_accumulated_costs(self, reporting_period=None): if reporting_period: reporting_periods = ReportingPeriod.get_all_predecessors(target_reporting_period=reporting_period, project=self) else: reporting_periods = ReportingPeriod.objects.filter(project=self.id) effective_accumulated_costs = 0 for single_reporting_period in reporting_periods: all_project_tasks = Task.objects.filter(project=self.id) for task in all_project_tasks: effective_accumulated_costs += float(task.effective_costs(reporting_period=single_reporting_period)) getcontext().prec = 5 effective_accumulated_costs = Decimal(effective_accumulated_costs) self.default_currency.round(effective_accumulated_costs) return effective_accumulated_costs