prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  bug: remaining effort on initial report creation is buggy
  ## Scenario
  Create a report and add an estimated remaining effort to it.
  
  ## Expected behavior
  It updates the remaining effort of the certain task in the statistics view.
  
  ## Actual behavior
  After submitting the report the remaining effort does **not** update in stats view. But after editing the rem. effort and saving the report again in the timesheet, it will update the values in the stats view.
  
  The attributes are fine in both requests to the backend. I suspect that a the `POST` and `PATCH` requests have different handling of the remaining effort attribute. Maybe the `POST` does not properly trigger the update?
  ![image](https://user-images.githubusercontent.com/10029904/219358043-268b4856-1b2e-430a-b4f0-e9891d1f799e.png)
  
  
  </issue>
  <code>
  [start of timed/tracking/signals.py]
  1 from django.db.models import Sum
  2 from django.db.models.signals import pre_save
  3 from django.dispatch import receiver
  4 
  5 from timed.tracking.models import Report
  6 
  7 
  8 @receiver(pre_save, sender=Report)
  9 def update_rejected_on_reports(sender, instance, **kwargs):
  10     """Unreject report when the task changes."""
  11     # Check if the report is being created or updated
  12     if instance.pk and instance.rejected:
  13         report = Report.objects.get(id=instance.id)
  14         if report.task_id != instance.task_id:
  15             instance.rejected = False
  16 
  17 
  18 @receiver(pre_save, sender=Report)
  19 def update_most_recent_remaining_effort(sender, instance, **kwargs):
  20     """Update remaining effort on task, if remaining effort tracking is active.
  21 
  22     Update most_recent_remaining_effort on task and total_remaining_effort on project
  23     only if remaining effort on report has changed.
  24     Any other change on report should not trigger this signal.
  25     """
  26     if kwargs.get("raw", False):  # pragma: no cover
  27         return
  28 
  29     if not instance.pk:
  30         return
  31     if instance.task.project.remaining_effort_tracking is not True:
  32         return
  33 
  34     if instance.remaining_effort != Report.objects.get(id=instance.id).remaining_effort:
  35         task = instance.task
  36         task.most_recent_remaining_effort = instance.remaining_effort
  37         task.save()
  38 
  39         project = task.project
  40         total_remaining_effort = (
  41             project.tasks.all()
  42             .aggregate(sum_remaining=Sum("most_recent_remaining_effort"))
  43             .get("sum_remaining")
  44         )
  45         project.total_remaining_effort = total_remaining_effort
  46         project.save()
  47
  [end of timed/tracking/signals.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/timed/tracking/signals.py b/timed/tracking/signals.py
  --- a/timed/tracking/signals.py
  +++ b/timed/tracking/signals.py
  @@ -26,21 +26,30 @@
       if kwargs.get("raw", False):  # pragma: no cover
           return
   
  -    if not instance.pk:
  -        return
       if instance.task.project.remaining_effort_tracking is not True:
           return
   
  +    # update most_recent_remaining_effort and total_remaining_effort on report creation
  +    if not instance.pk:
  +        update_remaining_effort(instance)
  +        return
  +
  +    # check if remaining effort has changed on report update
       if instance.remaining_effort != Report.objects.get(id=instance.id).remaining_effort:
  -        task = instance.task
  -        task.most_recent_remaining_effort = instance.remaining_effort
  -        task.save()
  -
  -        project = task.project
  -        total_remaining_effort = (
  -            project.tasks.all()
  -            .aggregate(sum_remaining=Sum("most_recent_remaining_effort"))
  -            .get("sum_remaining")
  -        )
  -        project.total_remaining_effort = total_remaining_effort
  -        project.save()
  +        update_remaining_effort(instance)
  +
  +
  +def update_remaining_effort(report):
  +    task = report.task
  +    project = task.project
  +
  +    task.most_recent_remaining_effort = report.remaining_effort
  +    task.save()
  +
  +    total_remaining_effort = (
  +        task.project.tasks.all()
  +        .aggregate(sum_remaining=Sum("most_recent_remaining_effort"))
  +        .get("sum_remaining")
  +    )
  +    project.total_remaining_effort = total_remaining_effort
  +    project.save()
  
verification_info: {"golden_diff": "diff --git a/timed/tracking/signals.py b/timed/tracking/signals.py\n--- a/timed/tracking/signals.py\n+++ b/timed/tracking/signals.py\n@@ -26,21 +26,30 @@\n     if kwargs.get(\"raw\", False):  # pragma: no cover\n         return\n \n-    if not instance.pk:\n-        return\n     if instance.task.project.remaining_effort_tracking is not True:\n         return\n \n+    # update most_recent_remaining_effort and total_remaining_effort on report creation\n+    if not instance.pk:\n+        update_remaining_effort(instance)\n+        return\n+\n+    # check if remaining effort has changed on report update\n     if instance.remaining_effort != Report.objects.get(id=instance.id).remaining_effort:\n-        task = instance.task\n-        task.most_recent_remaining_effort = instance.remaining_effort\n-        task.save()\n-\n-        project = task.project\n-        total_remaining_effort = (\n-            project.tasks.all()\n-            .aggregate(sum_remaining=Sum(\"most_recent_remaining_effort\"))\n-            .get(\"sum_remaining\")\n-        )\n-        project.total_remaining_effort = total_remaining_effort\n-        project.save()\n+        update_remaining_effort(instance)\n+\n+\n+def update_remaining_effort(report):\n+    task = report.task\n+    project = task.project\n+\n+    task.most_recent_remaining_effort = report.remaining_effort\n+    task.save()\n+\n+    total_remaining_effort = (\n+        task.project.tasks.all()\n+        .aggregate(sum_remaining=Sum(\"most_recent_remaining_effort\"))\n+        .get(\"sum_remaining\")\n+    )\n+    project.total_remaining_effort = total_remaining_effort\n+    project.save()\n", "issue": "bug: remaining effort on initial report creation is buggy\n## Scenario\r\nCreate a report and add an estimated remaining effort to it.\r\n\r\n## Expected behavior\r\nIt updates the remaining effort of the certain task in the statistics view.\r\n\r\n## Actual behavior\r\nAfter submitting the report the remaining effort does **not** update in stats view. But after editing the rem. effort and saving the report again in the timesheet, it will update the values in the stats view.\r\n\r\nThe attributes are fine in both requests to the backend. I suspect that a the `POST` and `PATCH` requests have different handling of the remaining effort attribute. Maybe the `POST` does not properly trigger the update?\r\n![image](https://user-images.githubusercontent.com/10029904/219358043-268b4856-1b2e-430a-b4f0-e9891d1f799e.png)\r\n\n", "before_files": [{"content": "from django.db.models import Sum\nfrom django.db.models.signals import pre_save\nfrom django.dispatch import receiver\n\nfrom timed.tracking.models import Report\n\n\n@receiver(pre_save, sender=Report)\ndef update_rejected_on_reports(sender, instance, **kwargs):\n    \"\"\"Unreject report when the task changes.\"\"\"\n    # Check if the report is being created or updated\n    if instance.pk and instance.rejected:\n        report = Report.objects.get(id=instance.id)\n        if report.task_id != instance.task_id:\n            instance.rejected = False\n\n\n@receiver(pre_save, sender=Report)\ndef update_most_recent_remaining_effort(sender, instance, **kwargs):\n    \"\"\"Update remaining effort on task, if remaining effort tracking is active.\n\n    Update most_recent_remaining_effort on task and total_remaining_effort on project\n    only if remaining effort on report has changed.\n    Any other change on report should not trigger this signal.\n    \"\"\"\n    if kwargs.get(\"raw\", False):  # pragma: no cover\n        return\n\n    if not instance.pk:\n        return\n    if instance.task.project.remaining_effort_tracking is not True:\n        return\n\n    if instance.remaining_effort != Report.objects.get(id=instance.id).remaining_effort:\n        task = instance.task\n        task.most_recent_remaining_effort = instance.remaining_effort\n        task.save()\n\n        project = task.project\n        total_remaining_effort = (\n            project.tasks.all()\n            .aggregate(sum_remaining=Sum(\"most_recent_remaining_effort\"))\n            .get(\"sum_remaining\")\n        )\n        project.total_remaining_effort = total_remaining_effort\n        project.save()\n", "path": "timed/tracking/signals.py"}]}