Exemple #1
0
    def statistics(self):
        from workbench.reporting.project_budget_statistics import (
            project_budget_statistics, )

        pbs = project_budget_statistics(self.projects.all())
        overall = pbs["overall"]
        overall["gross_margin_per_hour"] = (
            (overall["invoiced"] - overall["third_party_costs"]) /
            overall["hours"] if overall["hours"] else None)
        pbs["statistics"] = sorted(pbs["statistics"],
                                   key=lambda s: s["project"])
        return pbs
Exemple #2
0
    def statistics(self):
        from workbench.reporting.project_budget_statistics import (
            project_budget_statistics, )

        pbs = project_budget_statistics(self.project_set.all())["overall"]

        invoices = (self.invoice_set.invoiced().filter(
            project__isnull=True).order_by().aggregate(
                Sum("total_excl_tax"), Sum("third_party_costs")))

        pbs["invoiced"] += invoices["total_excl_tax__sum"] or Z2
        pbs["third_party_costs"] += invoices["third_party_costs__sum"] or Z2

        pbs["gross_margin_per_hour"] = (
            (pbs["invoiced"] - pbs["third_party_costs"]) /
            pbs["hours"] if pbs["hours"] else None)
        return pbs
Exemple #3
0
def project_budget_statistics_view(request, form):
    statistics = project_budget_statistics.project_budget_statistics(
        form.queryset(), cutoff_date=form.cleaned_data.get("cutoff_date")
    )

    if form.cleaned_data.get("closed_during_the_last_year"):
        statistics["statistics"] = sorted(
            statistics["statistics"], key=lambda s: s["project"].closed_on, reverse=True
        )

    if request.GET.get("export") == "xlsx" and statistics["statistics"]:
        xlsx = WorkbenchXLSXDocument()
        xlsx.project_budget_statistics(statistics)
        return xlsx.to_response("project-budget-statistics.xlsx")

    return render(
        request,
        "reporting/project_budget_statistics.html",
        {"form": form, "statistics": statistics},
    )
Exemple #4
0
 def accruals(self, cutoff_date):
     projects = Project.objects.open(on=cutoff_date)
     statistics = project_budget_statistics(projects,
                                            cutoff_date=cutoff_date)
     return statistics["overall"]["delta_negative"]
    def test_not_archived_hours_grouped_services_green_hours_hpc(self):
        """Test a scenario"""
        service1 = factories.ServiceFactory.create(effort_rate=180,
                                                   effort_type="Any")
        service2 = factories.ServiceFactory.create(project=service1.project)

        project = Project.objects.get()
        self.assertEqual(project.not_archived_total, {
            "total": Z2,
            "hours_rate_undefined": Z1
        })

        factories.LoggedHoursFactory.create(service=service1, hours=10)
        factories.LoggedHoursFactory.create(service=service2, hours=20)
        factories.LoggedCostFactory.create(service=service1,
                                           cost=0,
                                           third_party_costs=0)

        project = Project.objects.get()
        self.assertEqual(
            project.not_archived_total,
            {
                "total": Decimal("1800.00"),
                "hours_rate_undefined": Decimal("20.00")
            },
        )

        invoice = factories.InvoiceFactory.create(
            project=project,
            customer=project.customer,
            contact=project.contact,
            type=factories.Invoice.SERVICES,
            invoiced_on=in_days(0),
            status=Invoice.SENT,
        )
        invoice.create_services_from_logbook(project.services.all())

        project = Project.objects.get()
        self.assertEqual(project.not_archived_total, {
            "total": Z2,
            "hours_rate_undefined": Z1
        })

        hours = factories.LoggedHoursFactory.create(service=service1, hours=10)
        project = Project.objects.get()
        self.assertEqual(
            project.not_archived_total,
            {
                "total": Decimal("1800.00"),
                "hours_rate_undefined": Z1
            },
        )

        self.assertEqual(project.project_invoices_total_excl_tax,
                         Decimal("1800.00"))

        grouped = project.grouped_services
        self.assertEqual(len(grouped["offers"]), 1)
        self.assertIs(grouped["offers"][0][0], None)  # Offer is None
        self.assertEqual(grouped["logged_hours"], Decimal(40))
        self.assertEqual(grouped["service_hours"], 0)
        self.assertEqual(grouped["total_logged_cost"], Decimal(3600))
        self.assertEqual(grouped["total_service_cost"], 0)
        self.assertEqual(grouped["total_logged_hours_rate_undefined"],
                         Decimal(20))
        self.assertEqual(grouped["total_service_hours_rate_undefined"], 0)

        today = dt.date.today()
        date_range = [dt.date(today.year, 1, 1), dt.date(today.year, 12, 31)]

        hpc = hours_per_customer(date_range)
        self.assertEqual(hpc["organizations"][0]["total_hours"], Decimal(40))
        self.assertEqual(len(hpc["organizations"]), 1)
        self.assertEqual(len(hpc["users"]), 3)

        hpc = hours_per_customer(date_range, users=[hours.rendered_by])
        self.assertEqual(hpc["organizations"][0]["total_hours"], Decimal(10))
        self.assertEqual(len(hpc["organizations"]), 1)
        self.assertEqual(len(hpc["users"]), 1)

        stats = project_budget_statistics.project_budget_statistics(
            Project.objects.all())
        self.assertEqual(
            stats["statistics"],
            [{
                "cost": Decimal("0.00"),
                "delta": Decimal("1800.000"),
                "effort_cost": Decimal("3600.000"),
                "effort_hours_with_rate_undefined": Decimal("20.00"),
                "hours": Decimal("40.00"),
                "invoiced": Decimal("1800.00"),
                "logbook": Decimal("3600.000"),
                "not_archived": Decimal("10.0"),
                "offered": Decimal("0.00"),
                "project": project,
                "third_party_costs": Decimal("0.00"),
            }],
        )
        self.assertEqual(stats["overall"]["delta_positive"],
                         Decimal("1800.00"))
        self.assertEqual(stats["overall"]["delta_negative"], Decimal("0.00"))