open-synergy/opnsynid-hr

View on GitHub
hr_attendance_computation/models/hr_attendance.py

Summary

Maintainability
F
4 days
Test Coverage

Function _compute_attendance_duration has a Cognitive Complexity of 82 (exceeds 5 allowed). Consider refactoring.
Open

    def _compute_attendance_duration(self):  # noqa C901
        precision = (
            self.env["res.users"]
            .browse(self.env.user.id)
            .company_id.working_time_precision
Severity: Minor
Found in hr_attendance_computation/models/hr_attendance.py - About 1 day to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

File hr_attendance.py has 343 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
# Copyright 2011 Domsense srl (<http://www.domsense.com>)
# Copyright 2011-15 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright 2017 OpenSynergy Indonesia (<https://opensynergy-indonesia.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
Severity: Minor
Found in hr_attendance_computation/models/hr_attendance.py - About 4 hrs to fix

    Avoid deeply nested control flow statements.
    Open

                            if abs(1 - rounded_start_hour) < 0.01:
                                attendance_start = datetime(
                                    attendance_start.year,
                                    attendance_start.month,
                                    attendance_start.day,
    Severity: Major
    Found in hr_attendance_computation/models/hr_attendance.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if matched_schedules:
                                  intervals_within += 1
                                  # sign in tolerance
                                  if intervals_within == 1:
                                      att = matched_schedules[0]
      Severity: Major
      Found in hr_attendance_computation/models/hr_attendance.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if len(matched_schedules) > 1:
                                    raise UserError(
                                        _("Wrongly configured working schedule with " "id %s")
                                        % unicode(calendar_id)  # noqa: F821
                                    )
        Severity: Major
        Found in hr_attendance_computation/models/hr_attendance.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if attendance.outside_calendar_duration:
                                      overtime = attendance.outside_calendar_duration
                                      cal = reference_calendar
                                      if cal.overtime_rounding_tolerance:
                                          overtime = self.time_sum(
          Severity: Major
          Found in hr_attendance_computation/models/hr_attendance.py - About 45 mins to fix

            Function _compute_triggering_attendance_id has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def _compute_triggering_attendance_id(self):
                    for attendance in self:
                        attendance.triggering_attendance_id = False
                        if attendance.action == "sign_in":
                            attendance.triggering_attendance_id = attendance.id
            Severity: Minor
            Found in hr_attendance_computation/models/hr_attendance.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    first_timedelta = timedelta(
                        0,
                        int(str_first_time.split(":")[0]) * 3600.0
                        + int(str_first_time.split(":")[1]) * 60.0,
            Severity: Major
            Found in hr_attendance_computation/models/hr_attendance.py and 1 other location - About 2 hrs to fix
            hr_attendance_computation/models/hr_attendance.py on lines 98..101

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 60.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    second_timedelta = timedelta(
                        0,
                        int(str_second_time.split(":")[0]) * 3600.0
                        + int(str_second_time.split(":")[1]) * 60.0,
            Severity: Major
            Found in hr_attendance_computation/models/hr_attendance.py and 1 other location - About 2 hrs to fix
            hr_attendance_computation/models/hr_attendance.py on lines 92..95

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 60.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                def _ceil_rounding(self, rounding, datetime_):
                    minutes = datetime_.minute / 60.0 + datetime_.second / 3600.0
                    return math.ceil(minutes * rounding) / rounding
            Severity: Major
            Found in hr_attendance_computation/models/hr_attendance.py and 1 other location - About 2 hrs to fix
            hr_attendance_computation/models/hr_attendance.py on lines 193..195

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 56.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                def _floor_rounding(self, rounding, datetime_):
                    minutes = datetime_.minute / 60.0 + datetime_.second / 3600.0
                    return math.floor(minutes * rounding) / rounding
            Severity: Major
            Found in hr_attendance_computation/models/hr_attendance.py and 1 other location - About 2 hrs to fix
            hr_attendance_computation/models/hr_attendance.py on lines 189..191

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 56.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                                    if abs(1 - rounded_start_hour) < 0.01:
                                        attendance_start = datetime(
                                            attendance_start.year,
                                            attendance_start.month,
                                            attendance_start.day,
            Severity: Minor
            Found in hr_attendance_computation/models/hr_attendance.py and 1 other location - About 45 mins to fix
            hr_attendance_computation/models/hr_attendance.py on lines 313..318

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 35.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                                    attendance_stop = datetime(
                                        attendance_stop.year,
                                        attendance_stop.month,
                                        attendance_stop.day,
                                        attendance_stop.hour,
            Severity: Minor
            Found in hr_attendance_computation/models/hr_attendance.py and 1 other location - About 45 mins to fix
            hr_attendance_computation/models/hr_attendance.py on lines 298..311

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 35.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status