Esempio n. 1
0
 def ready(self):
     from .models import Queue, Ticket
     accounts.register(Ticket, icon='Ticket_star.png')
     administration.register(Queue, dashboard=False)
     ModelTranslation.register(Queue, ('verbose_name',))
Esempio n. 2
0
    service = models.ForeignKey('services.Service', verbose_name=_("service"),
        related_name='rates')
    plan = models.ForeignKey(Plan, verbose_name=_("plan"), related_name='rates')
    quantity = models.PositiveIntegerField(_("quantity"), null=True, blank=True)
    price = models.DecimalField(_("price"), max_digits=12, decimal_places=2)
    
    objects = RateQuerySet.as_manager()
    
    class Meta:
        unique_together = ('service', 'plan', 'quantity')
    
    def __str__(self):
        return "{}-{}".format(str(self.price), self.quantity)
    
    @classmethod
    def get_methods(cls):
        return cls.RATE_METHODS
    
    @classmethod
    def get_choices(cls):
        choices = []
        for name, method in cls.RATE_METHODS.items():
            choices.append((name, method.verbose_name))
        return choices


accounts.register(ContractedPlan)
services.register(ContractedPlan, menu=False)

ModelTranslation.register(Plan, ('verbose_name',))
Esempio n. 3
0
 def ready(self):
     from .models import Plan, ContractedPlan
     accounts.register(ContractedPlan, icon='ContractedPack.png')
     services.register(ContractedPlan, menu=False, dashboard=False)
     administration.register(Plan, icon='Pack.png')
     ModelTranslation.register(Plan, ('verbose_name', ))
Esempio n. 4
0
                counter += rate['quantity']
                if counter >= position:
                    return decimal.Decimal(str(rate['price']))

    def get_rates(self, account, cache=True):
        # rates are cached per account
        if not cache:
            return self.rates.by_account(account)
        if not hasattr(self, '__cached_rates'):
            self.__cached_rates = {}
        rates = self.__cached_rates.get(account.id, self.rates.by_account(account))
        return rates
    
    @property
    def rate_method(self):
        return rate_class.get_methods()[self.rate_algorithm]
    
    def update_orders(self, commit=True):
        order_model = apps.get_model(settings.SERVICES_ORDER_MODEL)
        related_model = self.content_type.model_class()
        updates = []
        queryset = related_model.objects.all()
        if related_model._meta.model_name != 'account':
            queryset = queryset.select_related('account').all()
        for instance in queryset:
            updates += order_model.update_orders(instance, service=self, commit=commit)
        return updates


ModelTranslation.register(Service, ('description',))
Esempio n. 5
0
 def ready(self):
     from .models import MiscService, Miscellaneous
     services.register(Miscellaneous, icon='applications-other.png')
     administration.register(MiscService, icon='Misc-Misc-Box-icon.png')
     ModelTranslation.register(MiscService, ('verbose_name',))
Esempio n. 6
0
 def ready(self):
     from .models import Queue, Ticket
     accounts.register(Ticket, icon='Ticket_star.png')
     administration.register(Queue, dashboard=False)
     ModelTranslation.register(Queue, ('verbose_name', ))
Esempio n. 7
0
    is_active = models.BooleanField(_("active"), default=True,
        help_text=_("Designates whether this service should be treated as "
                    "active. Unselect this instead of deleting services."))
    
    class Meta:
        verbose_name_plural = _("miscellaneous")
    
    def __str__(self):
        return self.identifier or self.description[:32] or str(self.service)
    
    @cached_property
    def active(self):
        return self.is_active and self.service.is_active and self.account.is_active
    
    def get_description(self):
        return ' '.join((str(self.amount), self.service.description or self.service.verbose_name))
    
    @cached_property
    def service_class(self):
        return self.service
    
    def clean(self):
        if self.identifier:
            self.identifier = self.identifier.strip()
        self.description = self.description.strip()


services.register(Miscellaneous)

ModelTranslation.register(MiscService, ('verbose_name',))
Esempio n. 8
0
 def ready(self):
     from .models import Service
     administration.register(Service, icon='price.png')
     ModelTranslation.register(Service, ('description',))
Esempio n. 9
0
    def __str__(self):
        return "#%i" % self.id
    
    def save(self, *args, **kwargs):
        """ notify stakeholders of ticket update """
        if not self.pk:
            self.ticket.mark_as_unread()
            self.ticket.mark_as_read_by(self.author)
            self.ticket.notify(message=self)
            self.author_name = self.author.get_full_name()
        super(Message, self).save(*args, **kwargs)
    
    @property
    def number(self):
        return self.ticket.messages.filter(id__lte=self.id).count()


class TicketTracker(models.Model):
    """ Keeps track of user read tickets """
    ticket = models.ForeignKey(Ticket, verbose_name=_("ticket"), related_name='trackers')
    user = models.ForeignKey(djsettings.AUTH_USER_MODEL, verbose_name=_("user"),
        related_name='ticket_trackers')
    
    class Meta:
        unique_together = (
            ('ticket', 'user'),
        )


ModelTranslation.register(Queue, ('verbose_name',))
Esempio n. 10
0
 def ready(self):
     from .models import Plan, ContractedPlan
     accounts.register(ContractedPlan, icon='ContractedPack.png')
     services.register(ContractedPlan, menu=False, dashboard=False)
     administration.register(Plan, icon='Pack.png')
     ModelTranslation.register(Plan, ('verbose_name',))