We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `timed/tracking/signals.py`
Content:
```
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 FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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()

{"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"}], "after_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 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        update_remaining_effort(instance)\n\n\ndef 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", "path": "timed/tracking/signals.py"}]}