Exemplo n.º 1
0
    def add_task(task):
        items.row(p(task["code"], font), p(task["name"], font))
        items.row_style("SPAN", 1, -2)

        if task["qty"] is not None:
            items.row(
                "",
                "",
                ubrdecimal(task["complete"]),
                p(task["unit"], font),
                money(task["price"]),
                money(task["progress"]),
            )
            items.row_style("ALIGNMENT", 1, -1, "RIGHT")
            items.keep_previous_n_rows_together(2)
        else:
            items.row("", p(task["description"], font))
            items.row_style("SPAN", 1, -1)
            for li in task["lineitems"]:
                items.row(
                    "",
                    p(li["name"], font),
                    ubrdecimal(li["qty"]),
                    p(li["unit"], font),
                    money(li["price"]),
                    money(li["estimate"]),
                )
                items.row_style("ALIGNMENT", 2, -1, "RIGHT")
Exemplo n.º 2
0
 def get_lineitem_context(self, lineitem, **kwargs):
     # lineitem.get("new_key", lineitem["old_key"]) is a workaround to support old JSON and fixed JSON
     return super().get_lineitem_context(
         lineitem,
         qty=ubrdecimal(lineitem.get("expended", lineitem["qty"])),
         total=money(lineitem.get("progress", lineitem["estimate"])),
         **kwargs)
Exemplo n.º 3
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["jobs"] = self.object.jobs.with_totals().all()
        context["proposals"] = self.object.proposals.prefetch_related(
            "jobs__project"
        ).all()
        context["project_contacts"] = self.object.project_contacts.prefetch_related(
            "contact"
        ).all()

        context["jobsites"], context["activity_first_day"], context[
            "activity_last_day"
        ] = self.get_jobsites_and_activity()

        context["jobsites_count"] = len(context["jobsites"])
        context["project_has_billable_contact"] = self.object.has_billable_contact
        context["payments"] = self.object.payments.all()
        context["adjustments"] = self.object.adjustments.all()
        context["refunds"] = self.object.refunds.all()
        context["parent_invoices"] = (
            self.object.invoices.filter(parent=None).prefetch_related("invoices").all()
        )
        context["TAX_RATE_DISPLAY"] = "{}%".format(ubrdecimal(TAX_RATE * 100, 2))

        context["note"] = NoteForm()

        return context
Exemplo n.º 4
0
 def get_lineitem_context(self, lineitem, **kwargs):
     return super().get_lineitem_context(
         lineitem,
         qty=ubrdecimal(lineitem["qty"]),
         total=money(lineitem["estimate"]),
         **kwargs
     )
Exemplo n.º 5
0
 def get_task_context(self, task, **kwargs):
     total = money(task["estimate"])
     if task["is_provisional"]:
         total = _("Optional")
     elif task.get("variant_group") and task["variant_serial"] != 0:
         total = _("Alternative")
     return super().get_task_context(
         task,
         qty=ubrdecimal(task["qty"]),
         total=total,
         show_description=not self.render.only_task_names,
         **kwargs)
Exemplo n.º 6
0
 def get_task_context(self, task, **kwargs):
     if task["qty"] is None:
         return super().get_task_context(task,
                                         qty=None,
                                         total=money(task["progress"]),
                                         show_description=True,
                                         **kwargs)
     else:
         return super().get_task_context(task,
                                         qty=ubrdecimal(task["complete"]),
                                         total=money(task["progress"]),
                                         show_description=False,
                                         **kwargs)
Exemplo n.º 7
0
 def get(self, request, *args, **kwargs):
     model_type = kwargs["model_type"]
     model_pk = int(kwargs["pk"])
     if model_type == "group":
         group = Group.objects.get(pk=model_pk)
         return response.Response({
             "name": group.name,
             "description": group.description,
             "total": ubrdecimal(group.estimate),
         })
     elif model_type == "task":
         task = Task.objects.get(pk=model_pk)
         return response.Response({
             "name":
             task.name,
             "description":
             task.description,
             "project_string":
             _("Project"),
             "project_id":
             task.group.job.project.id,
             "qty":
             ubrdecimal(task.qty, min_significant=0),
             "unit":
             task.unit,
             "price":
             ubrdecimal(task.price),
             "total":
             ubrdecimal(task.total),
             "lineitems": [{
                 "name": li["name"],
                 "qty": ubrdecimal(li["qty"], min_significant=0),
                 "unit": li["unit"],
                 "price": ubrdecimal(li["price"]),
                 "total": ubrdecimal(li["total"]),
             }
                           for li in task.lineitems.values(
                               "name", "qty", "unit", "price", "total")],
         })