Exemple #1
0
def create_default_accounts():
    """Create the default structure"""
    from oscar_accounts import names
    AccountType = get_model('oscar_accounts', 'AccountType')

    assets = AccountType.add_root(name=names.ASSETS)
    sales = assets.add_child(name=names.SALES)

    sales.accounts.create(name=names.REDEMPTIONS)
    sales.accounts.create(name=names.LAPSED)

    cash = assets.add_child(name=names.CASH)
    cash.accounts.create(name=names.BANK, credit_limit=None)

    unpaid = assets.add_child(name=names.UNPAID_ACCOUNT_TYPE)
    for name in names.UNPAID_ACCOUNTS:
        unpaid.accounts.create(name=name, credit_limit=None)

    # Create liability accounts
    liabilities = AccountType.add_root(name=names.LIABILITIES)
    income = liabilities.add_child(name=names.DEFERRED_INCOME)
    for i, name in enumerate(names.DEFERRED_INCOME_ACCOUNT_TYPES):
        income.add_child(name=name)
Exemple #2
0
from decimal import Decimal as D

from django import forms
from django.utils.translation import ugettext_lazy as _
from oscar_accounts.loading import get_model
from oscar_accounts.templatetags.currency_filters import currency

Account = get_model('oscar_accounts', 'Account')


class ValidAccountForm(forms.Form):
    code = forms.CharField(label=_("Account code"))

    def __init__(self, user, *args, **kwargs):
        self.user = user
        super().__init__(*args, **kwargs)

    def clean_code(self):
        code = self.cleaned_data['code'].strip().upper()
        code = code.replace('-', '')
        try:
            self.account = Account.objects.get(code=code)
        except Account.DoesNotExist:
            raise forms.ValidationError(_("No account found with this code"))
        if not self.account.is_active():
            raise forms.ValidationError(_("This account is no longer active"))
        if not self.account.is_open():
            raise forms.ValidationError(_("This account is no longer open"))
        if self.account.balance == D('0.00'):
            raise forms.ValidationError(_("This account is empty"))
        if not self.account.can_be_authorised_by(self.user):
Exemple #3
0
from django import http
from django.conf import settings
from django.contrib import messages
from django.db.models import Sum
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.views import generic
from oscar_accounts.loading import get_model
from oscar.templatetags.currency_filters import currency

from oscar_accounts import exceptions, facade, names
from oscar_accounts.dashboard import forms, reports

AccountType = get_model('oscar_accounts', 'AccountType')
Account = get_model('oscar_accounts', 'Account')
Transfer = get_model('oscar_accounts', 'Transfer')
Transaction = get_model('oscar_accounts', 'Transaction')


class AccountListView(generic.ListView):
    model = Account
    context_object_name = 'accounts'
    template_name = 'accounts/dashboard/account_list.html'
    form_class = forms.SearchForm
    description = _("All %s") % names.UNIT_NAME_PLURAL.lower()
    paginate_by = getattr(settings, 'OSCAR_ACCOUNTS_DASHBOARD_ITEMS_PER_PAGE',
                          20)

    def get_context_data(self, **kwargs):
Exemple #4
0
import logging

from oscar_accounts.loading import get_model

from oscar_accounts import core, exceptions

Account = get_model('oscar_accounts', 'Account')
Transfer = get_model('oscar_accounts', 'Transfer')

logger = logging.getLogger('oscar_accounts')


def close_expired_accounts():
    """
    Close expired, open accounts and transfer any remaining balance to an
    expiration account.
    """
    accounts = Account.expired.filter(status=Account.OPEN)
    logger.info("Found %d open accounts to close", accounts.count())
    destination = core.lapsed_account()
    for account in accounts:
        balance = account.balance
        try:
            transfer(account,
                     destination,
                     balance,
                     description="Closing account")
        except exceptions.AccountException as e:
            logger.error("Unable to close account #%d - %s", account.id, e)
        else:
            logger.info(("Account #%d successfully expired - %d transferred "
Exemple #5
0
from decimal import Decimal as D

from django import forms
from django.conf import settings
from django.core import exceptions
from django.utils.translation import ugettext_lazy as _
from oscar_accounts.loading import get_model
from oscar.forms.widgets import DatePickerInput
from oscar.templatetags.currency_filters import currency

from oscar_accounts import codes, names

Account = get_model('oscar_accounts', 'Account')
AccountType = get_model('oscar_accounts', 'AccountType')


class SearchForm(forms.Form):
    name = forms.CharField(required=False)
    code = forms.CharField(required=False)
    STATUS_CHOICES = (('', "------"), (Account.OPEN, _("Open")),
                      (Account.FROZEN, _("Frozen")), (Account.CLOSED,
                                                      _("Closed")))
    status = forms.ChoiceField(choices=STATUS_CHOICES, required=False)


class TransferSearchForm(forms.Form):
    reference = forms.CharField(required=False)
    start_date = forms.DateField(required=False, widget=DatePickerInput)
    end_date = forms.DateField(required=False, widget=DatePickerInput)

Exemple #6
0
from oscar_accounts.loading import get_model

IPAddressRecord = get_model('oscar_accounts', 'IPAddressRecord')


def record_failed_request(request):
    record, __ = IPAddressRecord.objects.get_or_create(
        ip_address=request.META['REMOTE_ADDR'])
    record.increment_failures()


def record_successful_request(request):
    try:
        record, __ = IPAddressRecord.objects.get_or_create(
            ip_address=request.META['REMOTE_ADDR'])
    except IPAddressRecord.DoesNotExist:
        return
    record.reset()


def record_blocked_request(request):
    try:
        record, __ = IPAddressRecord.objects.get_or_create(
            ip_address=request.META['REMOTE_ADDR'])
    except IPAddressRecord.DoesNotExist:
        return
    record.increment_blocks()


def is_blocked(request):
    try:
Exemple #7
0
 class Meta:
     model = get_model('oscar_accounts', 'Transaction')
Exemple #8
0
 class Meta:
     model = get_model('oscar_accounts', 'Transfer')
Exemple #9
0
 class Meta:
     model = get_model('oscar_accounts', 'Account')