# Path: konfera/models/abstract.py
# class KonferaModel(models.Model):
# 
#     class Meta:
#         abstract = True
# 
#     uuid = models.UUIDField(default=uuid.uuid4, editable=False)
#     date_created = models.DateTimeField(verbose_name=_('Created'), auto_now_add=True)
#     date_modified = models.DateTimeField(verbose_name=_('Last modified'), auto_now=True)
# 
# Path: konfera/models/receipt.py
# class Receipt(AddressModel):
#     order = models.OneToOneField('Order', on_delete=models.CASCADE, related_name='receipt_of')
#     title = models.CharField(max_length=128, verbose_name=_('Name'), blank=True)
#     companyid = models.CharField(max_length=32, blank=True, verbose_name=_('Company ID'))
#     taxid = models.CharField(max_length=32, blank=True, verbose_name=_('TAX ID'))
#     vatid = models.CharField(max_length=32, blank=True, verbose_name=_('VAT ID'))
#     amount = models.DecimalField(decimal_places=2, max_digits=12, validators=[MinValueValidator(0)])
# 
#     def __str__(self):
#         return self.title
# 
# Path: konfera/settings.py
# UNPAID_ORDER_NOTIFICATION_REPEAT = getattr(settings, 'UNPAID_ORDER_NOTIFICATION_REPEAT', 3)
# 
# UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY = getattr(settings, 'UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY', 5)


from datetime import timedelta
from decimal import Decimal
from django.core.validators import MinValueValidator
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.db.models import Q
from konfera.models.abstract import KonferaModel
from konfera.models.receipt import Receipt
from konfera.settings import UNPAID_ORDER_NOTIFICATION_REPEAT, UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY
        return self.price - self.discount + self.processing_fee

    @property
    def variable_symbol(self):
        return str(int(self.uuid))[:10]

    @property
    def event(self):
        if self.ticket_set.exists():
            return self.ticket_set.first().type.event

    def recalculate_ticket_price(self):
        self.price = 0
        self.discount = 0

        for ticket in self.ticket_set.all():
            if ticket.status != ticket.CANCELLED:
                self.price += ticket.type.price
                self.discount += ticket.discount_calculator()

        self.save()

    @staticmethod
    def get_unpaid_orders(overdue=False):
        deadline = timezone.now() - timedelta(days=UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY)
        orders = Order.objects.filter(Q(status=Order.AWAITING) | Q(status=Order.PARTLY_PAID))
        orders = orders.filter((Q(unpaid_notification_sent_amount=0) & Q(date_created__lt=deadline)) |
                               Q(unpaid_notification_sent_at__lt=deadline))
        if overdue:
            return orders.filter(unpaid_notification_sent_amount=UNPAID_ORDER_NOTIFICATION_REPEAT)

# Path: konfera/models/abstract.py
# class KonferaModel(models.Model):
# 
#     class Meta:
#         abstract = True
# 
#     uuid = models.UUIDField(default=uuid.uuid4, editable=False)
#     date_created = models.DateTimeField(verbose_name=_('Created'), auto_now_add=True)
#     date_modified = models.DateTimeField(verbose_name=_('Last modified'), auto_now=True)
# 
# Path: konfera/models/receipt.py
# class Receipt(AddressModel):
#     order = models.OneToOneField('Order', on_delete=models.CASCADE, related_name='receipt_of')
#     title = models.CharField(max_length=128, verbose_name=_('Name'), blank=True)
#     companyid = models.CharField(max_length=32, blank=True, verbose_name=_('Company ID'))
#     taxid = models.CharField(max_length=32, blank=True, verbose_name=_('TAX ID'))
#     vatid = models.CharField(max_length=32, blank=True, verbose_name=_('VAT ID'))
#     amount = models.DecimalField(decimal_places=2, max_digits=12, validators=[MinValueValidator(0)])
# 
#     def __str__(self):
#         return self.title
# 
# Path: konfera/settings.py
# UNPAID_ORDER_NOTIFICATION_REPEAT = getattr(settings, 'UNPAID_ORDER_NOTIFICATION_REPEAT', 3)
# 
# UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY = getattr(settings, 'UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY', 5)


# Path: konfera/models/order.py
from datetime import timedelta
from decimal import Decimal
from django.core.validators import MinValueValidator
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.db.models import Q
from konfera.models.abstract import KonferaModel
from konfera.models.receipt import Receipt
from konfera.settings import UNPAID_ORDER_NOTIFICATION_REPEAT, UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY

        return self.price - self.discount + self.processing_fee

    @property
    def variable_symbol(self):
        return str(int(self.uuid))[:10]

    @property
    def event(self):
        if self.ticket_set.exists():
            return self.ticket_set.first().type.event

    def recalculate_ticket_price(self):
        self.price = 0
        self.discount = 0

        for ticket in self.ticket_set.all():
            if ticket.status != ticket.CANCELLED:
                self.price += ticket.type.price
                self.discount += ticket.discount_calculator()

        self.save()

    @staticmethod
    def get_unpaid_orders(overdue=False):
        deadline = timezone.now() - timedelta(days=UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY)
        orders = Order.objects.filter(Q(status=Order.AWAITING) | Q(status=Order.PARTLY_PAID))
        orders = orders.filter((Q(unpaid_notification_sent_amount=0) & Q(date_created__lt=deadline)) |
                               Q(unpaid_notification_sent_at__lt=deadline))
        if overdue:
            return orders.filter(unpaid_notification_sent_amount=UNPAID_ORDER_NOTIFICATION_REPEAT)

        return orders.filter(unpaid_notification_sent_amount__lt=UNPAID_ORDER_NOTIFICATION_REPEAT)