Пример #1
0
class Entry(models.Model):
    project = models.ForeignKey('Project', related_name='entries',
                                on_delete=models.CASCADE)
    task = models.ForeignKey('core.Task', related_name='entries',
                             blank=True, null=True, on_delete=models.SET_NULL)
    user = models.ForeignKey('auth.User', related_name='entries',
                             on_delete=models.CASCADE)
    date = models.DateField(blank=True)
    duration = models.DurationField(blank=True)
    datetime_start = models.DateTimeField(blank=True, null=True)
    datetime_end = models.DateTimeField(blank=True, null=True)
    note = models.TextField(blank=True, null=True)
    site = models.ForeignKey(Site, default=current_site_id(),
                             on_delete=models.CASCADE)

    objects = models.Manager()
    on_site = CurrentSiteManager()

    class Meta:
        default_permissions = ('view', 'add', 'change', 'delete')
        ordering = ['-date', '-id']
        verbose_name_plural = 'Entries'

    def save(self, *args, **kwargs):
        if not self.date:
            self.date = date.today()
        if not self.site:
            self.site = Site.objects.get(id=current_site_id())
        super().save(*args, **kwargs)

    def __str__(self):
        return 'Entry for ' + self.project.name + ' by ' + self.user.username
Пример #2
0
class Invoice(models.Model):
    client = models.ForeignKey('Client')  # Redundant with entries?
    note = models.CharField(max_length=255, blank=True, null=True)
    entries = models.ManyToManyField('Entry', related_name='invoices')
    created = models.DateTimeField(auto_now_add=True)
    paid = models.DateTimeField(blank=True, null=True)
    transaction_id = models.CharField(max_length=255, blank=True, null=True)
    site = models.ForeignKey(Site,
                             default=current_site_id(),
                             on_delete=models.CASCADE)

    objects = models.Manager()
    on_site = CurrentSiteManager()

    class Meta:
        default_permissions = ('view', 'add', 'change', 'delete')

    def save(self, *args, **kwargs):
        self.site = Site.objects.get(id=current_site_id())
        super(Invoice, self).save(*args, **kwargs)

    def __str__(self):
        return 'Invoice: ' + self.client.name

    def total_duration(self):
        total = 0
        for entry in self.entries:
            total += entry.duration

    def total_billed(self):
        total = 0
        for entry in self.entries:
            if entry.task.hourly_rate:
                total += entry.duration * entry.hourly_rate
        return total
Пример #3
0
class Task(models.Model):
    name = models.CharField(max_length=255)
    hourly_rate = models.DecimalField(max_digits=10, decimal_places=2,
                                      blank=True, null=True)
    sites = models.ManyToManyField(Site)

    objects = models.Manager()
    on_site = CurrentSiteManager()

    class Meta:
        default_permissions = ('view', 'add', 'change', 'delete')

    def __str__(self):
        return 'Task: ' + self.name
Пример #4
0
class Task(models.Model):
    project = models.ForeignKey('Project',
                                related_name='task',
                                on_delete=models.CASCADE)
    name = models.CharField(max_length=255)
    hourly_rate = models.DecimalField(max_digits=10,
                                      decimal_places=2,
                                      blank=True,
                                      null=True)
    sites = models.ManyToManyField(Site)

    objects = models.Manager()
    on_site = CurrentSiteManager()

    class Meta:
        default_permissions = ('view', 'add', 'change', 'delete')
        ordering = ['-id']

    def __str__(self):
        return 'Task: ' + self.name
Пример #5
0
class Entry(models.Model):
    project = models.ForeignKey(
        "Project", related_name="entries", on_delete=models.CASCADE
    )
    task = models.ForeignKey(
        "core.Task",
        related_name="entries",
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
    )
    user = models.ForeignKey(
        "auth.User", related_name="entries", on_delete=models.CASCADE
    )
    date = models.DateField(blank=True)
    duration = models.DurationField(blank=True)
    datetime_start = models.DateTimeField(blank=True, null=True)
    datetime_end = models.DateTimeField(blank=True, null=True)
    note = models.TextField(blank=True, null=True)
    site = models.ForeignKey(Site, default=current_site_id(), on_delete=models.CASCADE)

    objects = models.Manager()
    on_site = CurrentSiteManager()

    class Meta:
        default_permissions = ("view", "add", "change", "delete")
        ordering = ["-date", "-id"]
        verbose_name_plural = "Entries"

    def save(self, *args, **kwargs):
        if not self.date:
            self.date = date.today()
        if not self.site:
            self.site = Site.objects.get(id=current_site_id())
        super().save(*args, **kwargs)

    def __str__(self):
        return "Entry for " + self.project.name + " by " + self.user.username
Пример #6
0
class Client(models.Model):
    name = models.CharField(max_length=255)
    archive = models.BooleanField(default=False)
    payment_id = models.CharField(max_length=255, blank=True, null=True)
    sites = models.ManyToManyField(Site)

    objects = models.Manager()
    on_site = CurrentSiteManager()

    class Meta:
        default_permissions = ('view', 'add', 'change', 'delete')
        ordering = ['-id']

    def __str__(self):
        return 'Client: ' + self.name

    def get_total_projects(self):
        return self.projects.count()

    def get_total_duration(self):
        return duration_string(
            self.projects.aggregate(
                Sum('entries__duration'))['entries__duration__sum'])
Пример #7
0
class Client(models.Model):
    name = models.CharField(max_length=255)
    archive = models.BooleanField(default=False)
    payment_id = models.CharField(max_length=255, blank=True, null=True)
    sites = models.ManyToManyField(Site)

    objects = models.Manager()
    on_site = CurrentSiteManager()

    class Meta:
        default_permissions = ("view", "add", "change", "delete")
        ordering = ["-id"]

    def __str__(self):
        return "Client: " + self.name

    def get_total_projects(self):
        return self.projects.count()

    def get_total_duration(self):
        return duration_string(
            self.projects.aggregate(Sum("entries__duration"))["entries__duration__sum"]
        )