Ejemplo n.º 1
0
 class Meta:
     model = Invoice
     fields = (
         "contact",
         "customer",
         "invoiced_on",
         "due_on",
         "title",
         "description",
         "service_period_from",
         "service_period_until",
         "owned_by",
         "status",
         "closed_on",
         "payment_notice",
         "postal_address",
         "type",
         "subtotal",
         "third_party_costs",
         "discount",
         "liable_to_vat",
         "show_service_details",
     )
     widgets = {
         "customer": Autocomplete(model=Organization),
         "contact": Autocomplete(model=Person,
                                 params={"only_employees": "on"}),
         "status": forms.RadioSelect,
         "description": Textarea,
         "payment_notice": Textarea({"rows": 2}),
         "postal_address": Textarea,
         "type": forms.RadioSelect,
     }
Ejemplo n.º 2
0
 class Meta:
     model = Organization
     fields = (
         "name",
         "is_private_person",
         "notes",
         "primary_contact",
         "default_billing_address",
         "groups",
         "is_archived",
     )
     widgets = {
         "name": Textarea(),
         "notes": Textarea(),
         "default_billing_address": Textarea(),
         "groups": forms.CheckboxSelectMultiple(),
     }
Ejemplo n.º 3
0
class LoggedHoursForm(ModelForm):
    user_fields = default_to_current_user = ("rendered_by", )

    service_title = forms.CharField(label=_("title"),
                                    required=False,
                                    max_length=200)
    service_description = forms.CharField(label=_("description"),
                                          required=False,
                                          widget=Textarea({"rows": 2}))
    service_role = forms.ModelChoiceField(queryset=Role.objects.all(),
                                          label=_("role"),
                                          required=False)
    service_type = forms.ModelChoiceField(ServiceType.objects.all(),
                                          label=ServiceType._meta.verbose_name,
                                          required=False)

    class Meta:
        model = LoggedHours
        fields = ("rendered_by", "rendered_on", "service", "hours",
                  "description")
        widgets = {"description": Textarea({"rows": 2})}

    def __init__(self, *args, **kwargs):
        self.project = kwargs.pop("project", None)
        if self.project:
            initial = kwargs.setdefault("initial", {})
            request = kwargs["request"]

            if pk := request.GET.get("copy"):
                try:
                    hours = LoggedHours.objects.get(pk=pk)
                except (LoggedHours.DoesNotExist, TypeError, ValueError):
                    pass
                else:
                    initial.update({
                        "service": hours.service_id,
                        "rendered_on": hours.rendered_on.isoformat(),
                        "hours": hours.hours,
                        "description": hours.description,
                    })

            for field in ["description", "hours", "rendered_on", "service"]:
                if value := request.GET.get(field):
                    initial[field] = value

            if not initial.get(
                    "hours") and request.user.hours_since_latest <= 12:
                initial.setdefault("hours", request.user.hours_since_latest)

            if not initial.get("service"):
                latest_on_project = (LoggedHours.objects.filter(
                    rendered_by=request.user,
                    service__project=self.project).order_by(
                        "-created_at").first())
                if latest_on_project:
                    initial.setdefault("service", latest_on_project.service_id)
Ejemplo n.º 4
0
 class Meta:
     model = LoggedCost
     fields = (
         "service",
         "rendered_by",
         "rendered_on",
         "expense_currency",
         "expense_cost",
         "third_party_costs",
         "are_expenses",
         "cost",
         "description",
     )
     widgets = {"description": Textarea({"rows": 2})}
Ejemplo n.º 5
0
 class Meta:
     model = Service
     fields = [
         "title",
         "description",
         "role",
         "allow_logging",
         "offer",
         "is_optional",
         "effort_type",
         "effort_hours",
         "effort_rate",
         "cost",
         "third_party_costs",
     ]
     widgets = {"description": Textarea()}
Ejemplo n.º 6
0
 class Meta:
     model = Person
     fields = (
         "address",
         "given_name",
         "family_name",
         "address_on_first_name_terms",
         "salutation",
         "date_of_birth",
         "notes",
         "organization",
         "primary_contact",
         "groups",
         "is_archived",
     )
     widgets = {
         "notes": Textarea(),
         "organization": Autocomplete(model=Organization),
         "groups": forms.CheckboxSelectMultiple(),
     }
Ejemplo n.º 7
0
 class Meta:
     model = PostalAddress
     fields = (
         "type",
         "street",
         "house_number",
         "address_suffix",
         "postal_code",
         "city",
         "country",
         "postal_address_override",
     )
     widgets = {
         "type":
         forms.TextInput(attrs={
             "class": "form-control short",
             "placeholder": _("type")
         }),
         "postal_address_override":
         Textarea(attrs={
             "class": "form-control",
             "rows": 3
         }),
     }
Ejemplo n.º 8
0
 class Meta:
     model = Absence
     fields = [
         "user", "starts_on", "ends_on", "days", "reason", "description"
     ]
     widgets = {"description": Textarea({"rows": 2})}
Ejemplo n.º 9
0
 class Meta:
     model = Break
     fields = ["description"]
     widgets = {"description": Textarea({"rows": 2})}
Ejemplo n.º 10
0
 class Meta:
     model = LoggedHours
     fields = ("rendered_by", "rendered_on", "service", "hours",
               "description")
     widgets = {"description": Textarea({"rows": 2})}
Ejemplo n.º 11
0
    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop("request")

        super().__init__(*args, **kwargs)

        self.entries = []
        for entry in CreditEntry.objects.reverse().filter(invoice__isnull=True,
                                                          notes="")[:20]:
            self.fields[f"entry_{entry.pk}_invoice"] = forms.TypedChoiceField(
                label=format_html(
                    '<a href="{}" target="_blank"'
                    ' rel="noopener noreferrer">{}, {}: {}</a>',
                    entry.get_absolute_url(),
                    entry.total,
                    local_date_format(entry.value_date),
                    entry.payment_notice,
                ),
                choices=[(None, "----------")] + [(
                    invoice.id,
                    mark_safe(" ".join((
                        format_html('<span title="{}">', invoice.description),
                        format_html(
                            "<strong>{}</strong>" if re.search(
                                r"\b" + invoice.code + r"\b",
                                entry.payment_notice,
                            ) else "{}",
                            invoice,
                        ),
                        invoice.status_badge,
                        "<br>",
                        format_html(
                            "{}",
                            invoice.contact.name_with_organization
                            if invoice.contact else invoice.customer,
                        ),
                        "<br>",
                        format_html(
                            "{} {}",
                            _("invoiced on"),
                            local_date_format(invoice.invoiced_on),
                        ) if invoice.invoiced_on else gettext("NO DATE YET"),
                        "<br>",
                        currency(invoice.total),
                        format_html(
                            "<br><span style='color:darkred'>{}: {}</span>",
                            _("third party costs"),
                            currency(invoice.third_party_costs),
                        ) if invoice.third_party_costs else "",
                        "</span>",
                    ))),
                ) for invoice in Invoice.objects.open().filter(
                    total=entry.total).select_related("contact__organization",
                                                      "customer", "owned_by",
                                                      "project")[:100]],
                coerce=int,
                required=False,
                widget=forms.RadioSelect,
            )

            self.fields[f"entry_{entry.pk}_notes"] = forms.CharField(
                widget=Textarea({"rows": 1}), label=_("notes"), required=False)

            self.entries.append((
                entry,
                f"entry_{entry.pk}_invoice",
                f"entry_{entry.pk}_notes",
            ))