예제 #1
0
 def ready(self):
     from .management import create_initial_superuser
     from .models import Account
     services.register(Account, menu=False, dashboard=False)
     accounts.register(Account, icon='Face-monkey.png')
     post_migrate.connect(create_initial_superuser,
         dispatch_uid="orchestra.contrib.accounts.management.createsuperuser")
예제 #2
0
 def ready(self):
     from .management import create_initial_superuser
     from .models import Account
     services.register(Account, menu=False, dashboard=False)
     accounts.register(Account, icon='Face-monkey.png')
     post_migrate.connect(
         create_initial_superuser,
         dispatch_uid="orchestra.contrib.accounts.management.createsuperuser"
     )
예제 #3
0
 def ready(self):
     from .models import PaymentSource, Transaction, TransactionProcess
     accounts.register(PaymentSource, dashboard=False)
     accounts.register(Transaction, icon='transaction.png', search=False)
     accounts.register(TransactionProcess,
                       icon='transactionprocess.png',
                       dashboard=False,
                       search=False)
예제 #4
0
 def ready(self):
     from .models import Contact
     accounts.register(Contact, icon='contact_book.png')
예제 #5
0
        """
        Returns True if the user has any permissions in the given app label.
        Uses pretty much the same logic as has_perm, above.
        """
        # Active superusers have all permissions.
        if self.is_active and self.is_superuser:
            return True
        return auth._user_has_module_perms(self, app_label)
    
    def get_related_passwords(self):
        related = [
            self.main_systemuser,
        ]
        for model, key, related_kwargs, __ in settings.ACCOUNTS_CREATE_RELATED:
            if 'password' not in related_kwargs:
                continue
            model = apps.get_model(model)
            kwargs = {
                key: eval(related_kwargs[key], {'account': self})
            }
            try:
                rel = model.objects.get(account=self, **kwargs)
            except model.DoesNotExist:
                continue
            related.append(rel)
        return related


services.register(Account, menu=False)
accounts.register(Account)
예제 #6
0
 def ready(self):
     from .models import PaymentSource, Transaction, TransactionProcess
     accounts.register(PaymentSource, dashboard=False)
     accounts.register(Transaction, icon='transaction.png', search=False)
     accounts.register(TransactionProcess, icon='transactionprocess.png', dashboard=False, search=False)
예제 #7
0
 def ready(self):
     from .models import Order
     accounts.register(Order, icon='basket.png', search=False)
     from . import signals
예제 #8
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',))
예제 #9
0
 def ready(self):
     from .models import Contact
     accounts.register(Contact, icon='contact_book.png')
예제 #10
0
 def ready(self):
     from .models import Bill
     accounts.register(Bill, icon='invoice.png')
예제 #11
0
    email_usage = MultiSelectField(_("email usage"), max_length=256, blank=True,
            choices=EMAIL_USAGES,
            default=settings.CONTACTS_DEFAULT_EMAIL_USAGES)
    phone = models.CharField(_("phone"), max_length=32, blank=True)
    phone2 = models.CharField(_("alternative phone"), max_length=32, blank=True)
    address = models.TextField(_("address"), blank=True)
    city = models.CharField(_("city"), max_length=128, blank=True,
            default=settings.CONTACTS_DEFAULT_CITY)
    zipcode = models.PositiveIntegerField(_("zip code"), null=True, blank=True)
    country = models.CharField(_("country"), max_length=20, blank=True,
            default=settings.CONTACTS_DEFAULT_COUNTRY)
    
    def __unicode__(self):
        return self.short_name


class InvoiceContact(models.Model):
    account = models.OneToOneField('accounts.Account', verbose_name=_("account"),
            related_name='invoicecontact')
    name = models.CharField(_("name"), max_length=256)
    address = models.TextField(_("address"))
    city = models.CharField(_("city"), max_length=128,
            default=settings.CONTACTS_DEFAULT_CITY)
    zipcode = models.PositiveIntegerField(_("zip code"))
    country = models.CharField(_("country"), max_length=20,
            default=settings.CONTACTS_DEFAULT_COUNTRY)
    vat = models.CharField(_("VAT number"), max_length=64)


accounts.register(Contact)
예제 #12
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', ))
예제 #13
0
        return '#%i' % self.id
    
    def check_state(self, *args):
        if self.state not in args:
            raise TypeError("Transaction process not in %s" % ' or '.join(args))
    
    def mark_as_executed(self):
        self.check_state(self.CREATED)
        self.state = self.EXECUTED
        for transaction in self.transactions.all():
            transaction.mark_as_executed()
        self.save(update_fields=['state'])
    
    def abort(self):
        self.check_state(self.CREATED, self.EXCECUTED)
        self.state = self.ABORTED
        for transaction in self.transaction.all():
            transaction.mark_as_aborted()
        self.save(update_fields=['state'])
    
    def commit(self):
        self.check_state(self.CREATED, self.EXECUTED)
        self.state = self.COMMITED
        for transaction in self.transactions.processing():
            transaction.mark_as_secured()
        self.save(update_fields=['state'])


accounts.register(PaymentSource)
accounts.register(Transaction)
예제 #14
0
 def ready(self):
     from .models import Bill
     accounts.register(Bill, icon='invoice.png')
예제 #15
0
#            self.bill.save(update_fields=['total'])


class BillSubline(models.Model):
    """ Subline used for describing an item discount """
    VOLUME = 'VOLUME'
    COMPENSATION = 'COMPENSATION'
    OTHER = 'OTHER'
    TYPES = (
        (VOLUME, _("Volume")),
        (COMPENSATION, _("Compensation")),
        (OTHER, _("Other")),
    )
    
    # TODO: order info for undoing
    line = models.ForeignKey(BillLine, verbose_name=_("bill line"), related_name='sublines')
    description = models.CharField(_("description"), max_length=256)
    # TODO rename to subtotal
    total = models.DecimalField(max_digits=12, decimal_places=2)
    type = models.CharField(_("type"), max_length=16, choices=TYPES, default=OTHER)
    
#    def save(self, *args, **kwargs):
#        # TODO cost of this shit
#        super(BillSubline, self).save(*args, **kwargs)
#        if self.line.bill.is_open:
#            self.line.bill.total = self.line.bill.get_total()
#            self.line.bill.save(update_fields=['total'])


accounts.register(Bill)
예제 #16
0
    def store(cls, order, value):
        now = timezone.now()
        try:
            last = cls.objects.filter(order=order).latest()
        except cls.DoesNotExist:
            cls.objects.create(order=order, value=value, updated_on=now)
        else:
            error = decimal.Decimal(str(settings.ORDERS_METRIC_ERROR))
            if value > last.value+error or value < last.value-error:
                cls.objects.create(order=order, value=value, updated_on=now)
            else:
                last.updated_on = now
                last.save(update_fields=['updated_on'])


accounts.register(Order)


# TODO perhas use cache = caches.get_request_cache() to cache an account delete and don't processes get_related_objects() if the case
# FIXME https://code.djangoproject.com/ticket/24576
# TODO build a cache hash table {model: related, model: None}
@receiver(post_delete, dispatch_uid="orders.cancel_orders")
def cancel_orders(sender, **kwargs):
    if sender._meta.app_label not in settings.ORDERS_EXCLUDED_APPS:
        instance = kwargs['instance']
        # Account delete will delete all related orders, no need to maintain order consistency
        if isinstance(instance, Order.account.field.rel.to):
            return
        if type(instance) in services:
            for order in Order.objects.by_object(instance).active():
                order.cancel()
예제 #17
0
 def ready(self):
     from .models import Order
     accounts.register(Order, icon='basket.png', search=False)
     from . import signals
예제 #18
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', ))
예제 #19
0
    def ready(self):
        from .models import Order

        accounts.register(Order, icon="basket.png")
        from . import signals
예제 #20
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',))
예제 #21
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',))