# Path: payway/accounts/conf/settings.py
# INVOICES_PER_PAGE = getattr(settings, 'INVOICES_PER_PAGE', 5)
# 
# Path: payway/accounts/models.py
# class Account(RandomUIDAbstractModel):
#     user = models.ForeignKey(User, related_name='accounts', verbose_name=_('user'))
#     currency_code = models.CharField(_('currency code'), max_length=3, choices=CURRENCY_CHOICES, default=moneyed.RUB)
# 
#     class Meta:
#         verbose_name = _('account')
#         verbose_name_plural = _('accounts')
#         permissions = (('can_view_account_report', 'Can view account report'),)
#         db_table = 'payway_accounts'
# 
#     @property
#     def currency(self):
#         currency = None
#         if self.currency_code:
#             currency = get_currency(self.currency_code)
#         return currency
# 
#     def __unicode__(self):
#         return u"{0} {1}".format(self.uid, self.currency)
# 
#     def get_balance(self):
#         sum = Transaction.objects.filter(account=self, money_amount_currency=self.currency).sum_values()
#         return round_down(Money(sum, self.currency))
# 
#     def withdraw(self, money, allow_overdraft=False):
#         self.assert_correct_currency(money)
# 
#         if money < Money(0, self.currency):
#             raise ValueError("You can't withdraw a negative amount")
# 
#         if not allow_overdraft and (self.get_balance() - money) < Money(0, self.currency):
#             raise Overdraft
# 
#         return Transaction.objects.create(
#             account=self,
#             money_amount=money * '-1.0',
#         )
# 
#     def add(self, money):
#         self.assert_correct_currency(money)
# 
#         if money < Money(0, self.currency):
#             raise ValueError("You can't add a negative money amount")
# 
#         return Transaction.objects.create(
#             account=self,
#             money_amount=money,
#         )
# 
#     def transfer(self, money, to_account):
#         self.assert_correct_currency(money)
# 
#         if money < Money(0, self.currency):
#             raise ValueError("You can't transfer a negative money amount")
# 
#         self.withdraw(money)
# 
#         return Transaction.objects.create(
#             account=to_account,
#             money_amount=money,
#         )
# 
#     def assert_correct_currency(self, money):
#         if money.currency != self.currency:
#             raise ValueError("You can't add money with %s currency. Current currency %s" % (money.currency, self.currency))


from django.shortcuts import get_object_or_404
from django.views.generic.base import TemplateView
from django_simptools.shortcuts import create_paginated_page
from payway.accounts.conf.settings import INVOICES_PER_PAGE
from payway.accounts.models import Account
# -*- coding: UTF-8 -*-

__author__ = 'Razzhivin Alexander'
__email__ = 'admin@httpbots.com'


class InvoicesListListView(TemplateView):
    template_name = 'accounts/invoices_list.html'


    def get(self, request, *args, **kwargs):
        account_uid = int(kwargs.get('account_uid', -1))
        account = get_object_or_404(Account, uid=account_uid)

        invoices_page = create_paginated_page(
            query_set=account.invoices.all().order_by('-created'),
            page_number=request.GET.get('page') or 1,

# Path: payway/accounts/conf/settings.py
# INVOICES_PER_PAGE = getattr(settings, 'INVOICES_PER_PAGE', 5)
# 
# Path: payway/accounts/models.py
# class Account(RandomUIDAbstractModel):
#     user = models.ForeignKey(User, related_name='accounts', verbose_name=_('user'))
#     currency_code = models.CharField(_('currency code'), max_length=3, choices=CURRENCY_CHOICES, default=moneyed.RUB)
# 
#     class Meta:
#         verbose_name = _('account')
#         verbose_name_plural = _('accounts')
#         permissions = (('can_view_account_report', 'Can view account report'),)
#         db_table = 'payway_accounts'
# 
#     @property
#     def currency(self):
#         currency = None
#         if self.currency_code:
#             currency = get_currency(self.currency_code)
#         return currency
# 
#     def __unicode__(self):
#         return u"{0} {1}".format(self.uid, self.currency)
# 
#     def get_balance(self):
#         sum = Transaction.objects.filter(account=self, money_amount_currency=self.currency).sum_values()
#         return round_down(Money(sum, self.currency))
# 
#     def withdraw(self, money, allow_overdraft=False):
#         self.assert_correct_currency(money)
# 
#         if money < Money(0, self.currency):
#             raise ValueError("You can't withdraw a negative amount")
# 
#         if not allow_overdraft and (self.get_balance() - money) < Money(0, self.currency):
#             raise Overdraft
# 
#         return Transaction.objects.create(
#             account=self,
#             money_amount=money * '-1.0',
#         )
# 
#     def add(self, money):
#         self.assert_correct_currency(money)
# 
#         if money < Money(0, self.currency):
#             raise ValueError("You can't add a negative money amount")
# 
#         return Transaction.objects.create(
#             account=self,
#             money_amount=money,
#         )
# 
#     def transfer(self, money, to_account):
#         self.assert_correct_currency(money)
# 
#         if money < Money(0, self.currency):
#             raise ValueError("You can't transfer a negative money amount")
# 
#         self.withdraw(money)
# 
#         return Transaction.objects.create(
#             account=to_account,
#             money_amount=money,
#         )
# 
#     def assert_correct_currency(self, money):
#         if money.currency != self.currency:
#             raise ValueError("You can't add money with %s currency. Current currency %s" % (money.currency, self.currency))


# Path: payway/accounts/views/invoices_list.py
from django.shortcuts import get_object_or_404
from django.views.generic.base import TemplateView
from django_simptools.shortcuts import create_paginated_page
from payway.accounts.conf.settings import INVOICES_PER_PAGE
from payway.accounts.models import Account

# -*- coding: UTF-8 -*-

__author__ = 'Razzhivin Alexander'
__email__ = 'admin@httpbots.com'


class InvoicesListListView(TemplateView):
    template_name = 'accounts/invoices_list.html'


    def get(self, request, *args, **kwargs):
        account_uid = int(kwargs.get('account_uid', -1))
        account = get_object_or_404(Account, uid=account_uid)

        invoices_page = create_paginated_page(
            query_set=account.invoices.all().order_by('-created'),
            page_number=request.GET.get('page') or 1,

            objects_per_page=INVOICES_PER_PAGE