Exemplo n.º 1
0
 def clean_date(self):
     """The date must be in the Current :class:`FiscalYear`."""
     input_date = self.cleaned_data.get('date')
     fiscal_year_start = get_start_of_current_fiscal_year()
     if fiscal_year_start is not None and input_date < fiscal_year_start:
         raise forms.ValidationError("The date must be in the current "
                                     "Fiscal Year.")
     return input_date
Exemplo n.º 2
0
def _set_start_date_to_first_of_year(form, start_date):
    """Set start_date to the start of the fiscal year if form is unbound."""
    if not form.is_bound:
        fiscal_start = get_start_of_current_fiscal_year()
        start_date = (fiscal_start if fiscal_start is not None else
                      datetime.date(datetime.date.today().year, 1, 1))
        form.initial['start_date'] = _american_format(start_date)
    return form, start_date
Exemplo n.º 3
0
def _set_start_date_to_first_of_year(form, start_date):
    """Set start_date to the start of the fiscal year if form is unbound."""
    if not form.is_bound:
        fiscal_start = get_start_of_current_fiscal_year()
        start_date = (fiscal_start if fiscal_start is not None else
                      datetime.date(datetime.date.today().year, 1, 1))
        form.initial['start_date'] = _american_format(start_date)
    return form, start_date
Exemplo n.º 4
0
    def in_fiscal_year(self):
        """
        Determines whether the :attr:`BaseJournalEntry.date` is in the
        current :class:`~fiscalyears.models.FiscalYear`.

        Returns True if there is no current
        :class:`~fiscalyears.models.FiscalYear`.

        :returns: Whether or not the :attr:`date` is in the current
                :class:`~fiscalyears.models.FiscalYear`.
        :rtype: bool

        """
        current_year_start = get_start_of_current_fiscal_year()
        if current_year_start is not None and current_year_start > self.date:
            return False
        return True
Exemplo n.º 5
0
    def in_fiscal_year(self):
        """
        Determines whether the :attr:`BaseJournalEntry.date` is in the
        current :class:`~fiscalyears.models.FiscalYear`.

        Returns True if there is no current
        :class:`~fiscalyears.models.FiscalYear`.

        :returns: Whether or not the :attr:`date` is in the current
                :class:`~fiscalyears.models.FiscalYear`.
        :rtype: bool

        """
        current_year_start = get_start_of_current_fiscal_year()
        if current_year_start is not None and current_year_start > self.date:
            return False
        return True
Exemplo n.º 6
0
def show_account_detail(request, account_slug,
                        template_name="accounts/account_detail.html"):
    """
    Displays a list of :class:`Transaction` instances for the :class:`Account`
    with a :attr:`~Account.slug` equal to the ``account_slug`` parameter.

    The following ``GET`` parameters are accessible:
        * ``start_date`` - The starting date to filter the returned
          :class:`Transactions<Transaction>` by.
        * ``stop_date`` - The ending date to filter the returned
          :class:`Transactions<Transaction>` by.

    The ``start_date`` and ``stop_date`` variables default to the first day of
    the month and the current date.

    The view will provide ``start_balance``, ``end_balance``, ``transactions``,
    ``debit_total``, ``credit_total`` and ``net_change`` context variables. The
    :class:`Transactions<Transaction>` in the context variable ``transactions``
    will have the running balance added to the instance through the
    ``final_balance`` attribute.

    If the provided ``start_date`` is before the start of the current
    :class:`~fiscalyears.models.FiscalYear`, the running balance and
    :class:`Transaction's<entries.models.Transaction>` ``final_balance`` will
    not be calculated.

    If there are no :class:`Transactions<entries.models.Transaction>` the
    ``start_balance`` and ``end_balance`` will both be set to the balance on
    the ``start_date``

    :param account_slug: The :attr:`~accounts.models.Account.slug` of top   \
            :class:`Account` to retrieve.
    :type account_slug: str
    :param template_name: The template file to use to render the response.
    :type template_name: str
    :returns: HTTP Response with :class:`Transactions<Transaction>` and     \
            balance counters.
    :rtype: HttpResponse
    """
    form, start_date, stop_date = process_year_start_date_range_form(request)
    account = get_object_or_404(Account, slug=account_slug)
    date_range_query = (Q(date__lte=stop_date) & Q(date__gte=start_date))
    debit_total, credit_total, net_change = account.transaction_set.filter(
        date_range_query).get_totals(net_change=True)
    transactions = account.transaction_set.filter(
        date_range_query).select_related('journal_entry', 'bankspendingentry',
                                         'bankspend_entry',
                                         'bankreceivingentry',
                                         'bankreceive_entry')
    current_fiscal_start_date = get_start_of_current_fiscal_year()
    show_balance = (current_fiscal_start_date is None or
                    current_fiscal_start_date <= start_date)
    if not show_balance:
        messages.info(request, "The Balance counters are only available when "
                      "the Start Date is in the current Fiscal Year (after "
                      "{0})".format(current_fiscal_start_date.strftime(
                          "%m/%d/%Y")))
    if transactions.exists() and show_balance:
        start_balance = transactions[0].get_initial_account_balance()
        end_balance = start_balance
        # TODO: Use .get_totals() instead of looping through each
        for transaction in transactions:
            if account.flip_balance():
                end_balance -= transaction.balance_delta
            else:
                end_balance += transaction.balance_delta
            transaction.final_balance = end_balance
    else:
        start_balance = end_balance = account.get_balance_by_date(start_date)
    return render(request, template_name, locals())
Exemplo n.º 7
0
def show_account_detail(request,
                        account_slug,
                        template_name="accounts/account_detail.html"):
    """
    Displays a list of :class:`Transaction` instances for the :class:`Account`
    with a :attr:`~Account.slug` equal to the ``account_slug`` parameter.

    The following ``GET`` parameters are accessible:
        * ``start_date`` - The starting date to filter the returned
          :class:`Transactions<Transaction>` by.
        * ``stop_date`` - The ending date to filter the returned
          :class:`Transactions<Transaction>` by.

    The ``start_date`` and ``stop_date`` variables default to the first day of
    the month and the current date.

    The view will provide ``start_balance``, ``end_balance``, ``transactions``,
    ``debit_total``, ``credit_total`` and ``net_change`` context variables. The
    :class:`Transactions<Transaction>` in the context variable ``transactions``
    will have the running balance added to the instance through the
    ``final_balance`` attribute.

    If the provided ``start_date`` is before the start of the current
    :class:`~fiscalyears.models.FiscalYear`, the running balance and
    :class:`Transaction's<entries.models.Transaction>` ``final_balance`` will
    not be calculated.

    If there are no :class:`Transactions<entries.models.Transaction>` the
    ``start_balance`` and ``end_balance`` will both be set to the balance on
    the ``start_date``

    :param account_slug: The :attr:`~accounts.models.Account.slug` of top   \
            :class:`Account` to retrieve.
    :type account_slug: str
    :param template_name: The template file to use to render the response.
    :type template_name: str
    :returns: HTTP Response with :class:`Transactions<Transaction>` and     \
            balance counters.
    :rtype: HttpResponse
    """
    form, start_date, stop_date = process_year_start_date_range_form(request)
    account = get_object_or_404(Account, slug=account_slug)
    date_range_query = (Q(date__lte=stop_date) & Q(date__gte=start_date))
    debit_total, credit_total, net_change = account.transaction_set.filter(
        date_range_query).get_totals(net_change=True)
    transactions = account.transaction_set.filter(
        date_range_query).select_related('journal_entry', 'bankspendingentry',
                                         'bankspend_entry',
                                         'bankreceivingentry',
                                         'bankreceive_entry')
    current_fiscal_start_date = get_start_of_current_fiscal_year()
    show_balance = (current_fiscal_start_date is None
                    or current_fiscal_start_date <= start_date)
    if not show_balance:
        messages.info(
            request, "The Balance counters are only available when "
            "the Start Date is in the current Fiscal Year (after "
            "{0})".format(current_fiscal_start_date.strftime("%m/%d/%Y")))
    if transactions.exists() and show_balance:
        start_balance = transactions[0].get_initial_account_balance()
        end_balance = start_balance
        # TODO: Use .get_totals() instead of looping through each
        for transaction in transactions:
            if account.flip_balance():
                end_balance -= transaction.balance_delta
            else:
                end_balance += transaction.balance_delta
            transaction.final_balance = end_balance
    else:
        start_balance = end_balance = account.get_balance_by_date(start_date)
    return render(request, template_name, locals())