Renamed "subject" to "account" in the accounting application.

This commit is contained in:
依瑪貓 2020-07-21 10:38:47 +08:00
parent 28e84702e7
commit 076a68c028
16 changed files with 288 additions and 290 deletions

View File

@ -1,8 +1,8 @@
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Subject, Transaction, Record from .models import Account, Transaction, Record
admin.site.register(Subject) admin.site.register(Account)
admin.site.register(Transaction) admin.site.register(Transaction)
admin.site.register(Record) admin.site.register(Record)

View File

@ -26,8 +26,8 @@ from mia_core.templatetags.mia_core import smart_month
from mia_core.utils import get_multi_lingual_attr from mia_core.utils import get_multi_lingual_attr
class Subject(models.Model): class Account(models.Model):
"""An accounting subject.""" """An account."""
sn = models.PositiveIntegerField(primary_key=True) sn = models.PositiveIntegerField(primary_key=True)
parent = models.ForeignKey( parent = models.ForeignKey(
"self", on_delete=models.PROTECT, null=True, blank=True, "self", on_delete=models.PROTECT, null=True, blank=True,
@ -43,17 +43,16 @@ class Subject(models.Model):
created_by = models.ForeignKey( created_by = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.PROTECT, settings.AUTH_USER_MODEL, on_delete=models.PROTECT,
db_column="createdby", db_column="createdby",
related_name="created_accounting_subjects") related_name="created_accounting_accounts")
updated_at = models.DateTimeField( updated_at = models.DateTimeField(
auto_now_add=True, db_column="updated") auto_now_add=True, db_column="updated")
updated_by = models.ForeignKey( updated_by = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.PROTECT, settings.AUTH_USER_MODEL, on_delete=models.PROTECT,
db_column="updatedby", db_column="updatedby",
related_name="updated_accounting_subjects") related_name="updated_accounting_accounts")
def __str__(self): def __str__(self):
"""Returns the string representation of this accounting """Returns the string representation of this account."""
subject."""
return self.code.__str__() + " " + self.title return self.code.__str__() + " " + self.title
_title = None _title = None
@ -155,7 +154,7 @@ class Transaction(models.Model):
"""Whether this transaction is a cash income transaction.""" """Whether this transaction is a cash income transaction."""
debit_records = self.debit_records debit_records = self.debit_records
return (len(debit_records) == 1 return (len(debit_records) == 1
and debit_records[0].subject.code == "1111" and debit_records[0].account.code == "1111"
and debit_records[0].summary is None) and debit_records[0].summary is None)
@property @property
@ -163,7 +162,7 @@ class Transaction(models.Model):
"""Whether this transaction is a cash expense transaction.""" """Whether this transaction is a cash expense transaction."""
credit_records = self.credit_records credit_records = self.credit_records
return (len(credit_records) == 1 return (len(credit_records) == 1
and credit_records[0].subject.code == "1111" and credit_records[0].account.code == "1111"
and credit_records[0].summary is None) and credit_records[0].summary is None)
def get_absolute_url(self): def get_absolute_url(self):
@ -199,8 +198,8 @@ class Record(models.Model):
db_column="transaction_sn") db_column="transaction_sn")
is_credit = models.BooleanField() is_credit = models.BooleanField()
ord = models.PositiveSmallIntegerField(default=1) ord = models.PositiveSmallIntegerField(default=1)
subject = models.ForeignKey( account = models.ForeignKey(
Subject, on_delete=models.PROTECT, db_column="subject_sn") Account, on_delete=models.PROTECT, db_column="subject_sn")
summary = models.CharField(max_length=128, blank=True, null=True) summary = models.CharField(max_length=128, blank=True, null=True)
amount = models.PositiveIntegerField() amount = models.PositiveIntegerField()
created_at = models.DateTimeField( created_at = models.DateTimeField(
@ -310,7 +309,7 @@ class Record(models.Model):
record.""" record."""
return "%s %s %s %s" % ( return "%s %s %s %s" % (
self.transaction.date, self.transaction.date,
self.subject.title, self.account.title,
self.summary, self.summary,
self.amount) self.amount)

View File

@ -22,12 +22,12 @@
*/ */
.subject-picker { .account-picker {
height: auto; height: auto;
max-height: 400px; max-height: 400px;
overflow-x: hidden; overflow-x: hidden;
} }
.date-subject-line { .date-account-line {
font-size: 0.833em; font-size: 0.833em;
} }
.negative { .negative {
@ -100,7 +100,7 @@
.income-statement-table tr { .income-statement-table tr {
height: 50px; height: 50px;
} }
.income-statement-table td .subject { .income-statement-table td .account {
text-indent: 2em; text-indent: 2em;
} }
.income-statement-table tr.section-title { .income-statement-table tr.section-title {
@ -156,7 +156,7 @@
font-size: 1.1em; font-size: 1.1em;
font-weight: bolder; font-weight: bolder;
} }
.balance-sheet-table td .subject { .balance-sheet-table td .account {
text-indent: 1em; text-indent: 1em;
} }
.balance-sheet-table .total { .balance-sheet-table .total {

View File

@ -97,7 +97,7 @@ First written: 2020/7/20
</tr> </tr>
{% for item in group.details %} {% for item in group.details %}
<tr> <tr>
<td><div class="subject">{{ item.title|title }}</div></td> <td><div class="account">{{ item.title|title }}</div></td>
<td class="amount {% if item.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td> <td class="amount {% if item.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td>
<td class="actions"> <td class="actions">
<a href="{% url "accounting:ledger" item.code period.spec %}" class="btn btn-info" role="button"> <a href="{% url "accounting:ledger" item.code period.spec %}" class="btn btn-info" role="button">
@ -128,7 +128,7 @@ First written: 2020/7/20
</tr> </tr>
{% for item in group.details %} {% for item in group.details %}
<tr> <tr>
<td><div class="subject">{{ item.title|title }}</div></td> <td><div class="account">{{ item.title|title }}</div></td>
<td class="amount {% if item.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td> <td class="amount {% if item.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td>
<td class="actions"> <td class="actions">
<a href="{% url "accounting:ledger" item.code period.spec %}" class="btn btn-info" role="button"> <a href="{% url "accounting:ledger" item.code period.spec %}" class="btn btn-info" role="button">
@ -165,7 +165,7 @@ First written: 2020/7/20
</tr> </tr>
{% for item in group.details %} {% for item in group.details %}
<tr> <tr>
<td><div class="subject">{{ item.title|title }}</div></td> <td><div class="account">{{ item.title|title }}</div></td>
<td class="amount {% if item.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td> <td class="amount {% if item.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td>
<td class="actions"> <td class="actions">
<a href="{% url "accounting:ledger" item.code period.spec %}" class="btn btn-info" role="button"> <a href="{% url "accounting:ledger" item.code period.spec %}" class="btn btn-info" role="button">
@ -235,7 +235,7 @@ First written: 2020/7/20
{{ group.title|title }} {{ group.title|title }}
</li> </li>
{% for item in group.details %} {% for item in group.details %}
<li class="list-group-item d-flex justify-content-between align-items-center subject"> <li class="list-group-item d-flex justify-content-between align-items-center account">
<a class="list-group-item-action" href="{% url "accounting:ledger" item.code period.spec %}"> <a class="list-group-item-action" href="{% url "accounting:ledger" item.code period.spec %}">
{{ item.title|title }} {{ item.title|title }}
<div class="float-right"> <div class="float-right">
@ -266,7 +266,7 @@ First written: 2020/7/20
{{ group.title|title }} {{ group.title|title }}
</li> </li>
{% for item in group.details %} {% for item in group.details %}
<li class="list-group-item d-flex justify-content-between align-items-center subject"> <li class="list-group-item d-flex justify-content-between align-items-center account">
<a class="list-group-item-action" href="{% url "accounting:ledger" item.code period.spec %}"> <a class="list-group-item-action" href="{% url "accounting:ledger" item.code period.spec %}">
{{ item.title|title }} {{ item.title|title }}
<div class="float-right"> <div class="float-right">
@ -295,8 +295,8 @@ First written: 2020/7/20
{{ group.title|title }} {{ group.title|title }}
</li> </li>
{% for item in group.details %} {% for item in group.details %}
<li class="list-group-item d-flex justify-content-between align-items-center subject"> <li class="list-group-item d-flex justify-content-between align-items-center account">
{# TODO: Link to the income statement for subject #3353 #} {# TODO: Link to the income statement for account #3353 #}
<a class="list-group-item-action" href="{% url "accounting:ledger" item.code period.spec %}"> <a class="list-group-item-action" href="{% url "accounting:ledger" item.code period.spec %}">
{{ item.title|title }} {{ item.title|title }}
<div class="float-right"> <div class="float-right">

View File

@ -27,7 +27,7 @@ First written: 2020/7/15
{% load accounting %} {% load accounting %}
{% block settings %} {% block settings %}
{% blocktrans asvar title with subject=current_subject.title|title context "Accounting|" %}Cash Summary for {{ subject }}{% endblocktrans %} {% blocktrans asvar title with account=current_account.title|title context "Accounting|" %}Cash Summary for {{ account }}{% endblocktrans %}
{% setvar "title" title %} {% setvar "title" title %}
{% static "accounting/css/report.css" as css %} {% static "accounting/css/report.css" as css %}
{% setvar "css" css %} {% setvar "css" css %}
@ -66,20 +66,20 @@ First written: 2020/7/15
{% endwith %} {% endwith %}
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown"> <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span class="d-none d-md-inline">{{ current_subject.title|title }}</span> <span class="d-none d-md-inline">{{ current_account.title|title }}</span>
<span class="d-md-none">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</span> <span class="d-md-none">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</span>
</button> </button>
<div class="dropdown-menu subject-picker"> <div class="dropdown-menu account-picker">
<div class="dropdown-header">{% trans "Shortcuts" context "Accounting|Subject|" as text %}{{ text|force_escape }}</div> <div class="dropdown-header">{% trans "Shortcuts" context "Accounting|Account|" as text %}{{ text|force_escape }}</div>
{% for subject in shortcut_subjects %} {% for account in shortcut_accounts %}
<a class="dropdown-item {% if subject.code == current_subject.code %} active {% endif %}>" href="{% url "accounting:cash-summary" subject.code %}"> <a class="dropdown-item {% if account.code == current_account.code %} active {% endif %}>" href="{% url "accounting:cash-summary" account.code %}">
{{ subject.title|title }} {{ account.title|title }}
</a> </a>
{% endfor %} {% endfor %}
<div class="dropdown-header">{% trans "All" context "Accounting|Subject|" as text %}{{ text|force_escape }}</div> <div class="dropdown-header">{% trans "All" context "Accounting|Account|" as text %}{{ text|force_escape }}</div>
{% for subject in all_sibjects %} {% for account in all_accounts %}
<a class="dropdown-item {% if subject.code == current_subject.code %} active {% endif %}>" href="{% url "accounting:cash-summary" subject.code %}"> <a class="dropdown-item {% if account.code == current_account.code %} active {% endif %}>" href="{% url "accounting:cash-summary" account.code %}">
{{ subject.code }} {{ subject.title|title }} {{ account.code }} {{ account.title|title }}
</a> </a>
{% endfor %} {% endfor %}
</div> </div>
@ -111,7 +111,7 @@ First written: 2020/7/15
<td class="amount {% if item.cumulative_balance < 0 %} text-danger {% endif %}">{{ item.cumulative_balance|accounting_amount }}</td> <td class="amount {% if item.cumulative_balance < 0 %} text-danger {% endif %}">{{ item.cumulative_balance|accounting_amount }}</td>
<td class="actions"> <td class="actions">
{% if item.month is not None %} {% if item.month is not None %}
<a class="btn btn-info" role="button" href="{% url "accounting:cash" current_subject.code item.month|date:"Y-m" %}"> <a class="btn btn-info" role="button" href="{% url "accounting:cash" current_account.code item.month|date:"Y-m" %}">
<i class="fas fa-eye"></i> <i class="fas fa-eye"></i>
<span class="d-none d-lg-inline">{% trans "View" context "Accounting|" as text %}{{ text|force_escape }}</span> <span class="d-none d-lg-inline">{% trans "View" context "Accounting|" as text %}{{ text|force_escape }}</span>
</a> </a>
@ -127,7 +127,7 @@ First written: 2020/7/15
{% for item in item_list %} {% for item in item_list %}
<li class="list-group-item {% if item.balance < 0 %} list-group-item-danger {% endif %}"> <li class="list-group-item {% if item.balance < 0 %} list-group-item-danger {% endif %}">
{% if item.month is not None %} {% if item.month is not None %}
<a class="list-group-item-action d-flex justify-content-between align-items-center" href="{% url "accounting:cash" current_subject.code item.month|date:"Y-m" %}"> <a class="list-group-item-action d-flex justify-content-between align-items-center" href="{% url "accounting:cash" current_account.code item.month|date:"Y-m" %}">
{{ item.label }} {{ item.label }}
<div> <div>
<span class="badge badge-success badge-pill"> <span class="badge badge-success badge-pill">

View File

@ -27,7 +27,7 @@ First written: 2020/7/1
{% load accounting %} {% load accounting %}
{% block settings %} {% block settings %}
{% blocktrans asvar title with subject=current_subject.title|title period=period.description context "Accounting|" %}Cash Account for {{ subject }} in {{ period }}{% endblocktrans %} {% blocktrans asvar title with account=current_account.title|title period=period.description context "Accounting|" %}Cash Account for {{ account }} in {{ period }}{% endblocktrans %}
{% setvar "title" title %} {% setvar "title" title %}
{% setvar "use_period_chooser" True %} {% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as css %} {% static "accounting/css/report.css" as css %}
@ -67,20 +67,20 @@ First written: 2020/7/1
{% endwith %} {% endwith %}
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown"> <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span class="d-none d-md-inline">{{ current_subject.title|title }}</span> <span class="d-none d-md-inline">{{ current_account.title|title }}</span>
<span class="d-md-none">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</span> <span class="d-md-none">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</span>
</button> </button>
<div class="dropdown-menu subject-picker"> <div class="dropdown-menu account-picker">
<div class="dropdown-header">{% trans "Shortcuts" context "Accounting|Subject|" as text %}{{ text|force_escape }}</div> <div class="dropdown-header">{% trans "Shortcuts" context "Accounting|Account|" as text %}{{ text|force_escape }}</div>
{% for subject in shortcut_subjects %} {% for account in shortcut_accounts %}
<a class="dropdown-item {% if subject.code == current_subject.code %} active {% endif %}>" href="{% url "accounting:cash" subject.code period.spec %}"> <a class="dropdown-item {% if account.code == current_account.code %} active {% endif %}>" href="{% url "accounting:cash" account.code period.spec %}">
{{ subject.title|title }} {{ account.title|title }}
</a> </a>
{% endfor %} {% endfor %}
<div class="dropdown-header">{% trans "All" context "Accounting|Subject|" as text %}{{ text|force_escape }}</div> <div class="dropdown-header">{% trans "All" context "Accounting|Account|" as text %}{{ text|force_escape }}</div>
{% for subject in all_sibjects %} {% for account in all_accounts %}
<a class="dropdown-item {% if subject.code == current_subject.code %} active {% endif %}>" href="{% url "accounting:cash" subject.code period.spec %}"> <a class="dropdown-item {% if account.code == current_account.code %} active {% endif %}>" href="{% url "accounting:cash" account.code period.spec %}">
{{ subject.code }} {{ subject.title|title }} {{ account.code }} {{ account.title|title }}
</a> </a>
{% endfor %} {% endfor %}
</div> </div>
@ -102,7 +102,7 @@ First written: 2020/7/1
<thead> <thead>
<tr> <tr>
<th scope="col">{% trans "Date" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Date" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th scope="col">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th scope="col">{% trans "Summary" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Summary" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th class="amount" scope="col">{% trans "Income" context "Accounting|" as text %}{{ text|force_escape }}</th> <th class="amount" scope="col">{% trans "Income" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th class="amount" scope="col">{% trans "Expense" context "Accounting|" as text %}{{ text|force_escape }}</th> <th class="amount" scope="col">{% trans "Expense" context "Accounting|" as text %}{{ text|force_escape }}</th>
@ -114,7 +114,7 @@ First written: 2020/7/1
{% for item in item_list %} {% for item in item_list %}
<tr class="{% if not item.is_balanced or item.has_order_hole %} table-danger {% endif %}"> <tr class="{% if not item.is_balanced or item.has_order_hole %} table-danger {% endif %}">
<td>{{ item.transaction.date|smart_date }}</td> <td>{{ item.transaction.date|smart_date }}</td>
<td>{{ item.subject.title|title }}</td> <td>{{ item.account.title|title }}</td>
<td>{{ item.summary|default:"" }}{% if not item.is_balanced %} <td>{{ item.summary|default:"" }}{% if not item.is_balanced %}
<span class="badge badge-danger badge-pill"> <span class="badge badge-danger badge-pill">
{% trans "Unbalanced" context "Accounting|" as text %} {% trans "Unbalanced" context "Accounting|" as text %}
@ -148,8 +148,8 @@ First written: 2020/7/1
<li class="list-group-item {% if not item.is_balanced or item.has_order_hole %} list-group-item-danger {% endif %}"> <li class="list-group-item {% if not item.is_balanced or item.has_order_hole %} list-group-item-danger {% endif %}">
{% if item.sn is not None %} {% if item.sn is not None %}
<a class="list-group-item-action" href="{{ item.transaction.get_absolute_url }}"> <a class="list-group-item-action" href="{{ item.transaction.get_absolute_url }}">
<div class="date-subject-line d-flex justify-content-between align-items-center"> <div class="date-account-line d-flex justify-content-between align-items-center">
{{ item.transaction.date|smart_date }} {{ item.subject.title|title }} {{ item.transaction.date|smart_date }} {{ item.account.title|title }}
</div> </div>
<div class="d-flex justify-content-between align-items-center"> <div class="d-flex justify-content-between align-items-center">
<div> <div>
@ -185,8 +185,8 @@ First written: 2020/7/1
</div> </div>
</a> </a>
{% else %} {% else %}
<div class="date-subject-line d-flex justify-content-between align-items-center"> <div class="date-account-line d-flex justify-content-between align-items-center">
{{ item.transaction.date|smart_date }} {{ item.subject.title }} {{ item.transaction.date|smart_date }} {{ item.account.title }}
</div> </div>
<div class="d-flex justify-content-between align-items-center"> <div class="d-flex justify-content-between align-items-center">
<div>{{ item.summary|default:"" }}</div> <div>{{ item.summary|default:"" }}</div>

View File

@ -62,7 +62,7 @@ First written: 2020/7/9
</span> </span>
<span class="d-md-none">{% trans "Book" context "Accounting|" as text %}{{ text|force_escape }}</span> <span class="d-md-none">{% trans "Book" context "Accounting|" as text %}{{ text|force_escape }}</span>
</button> </button>
<div class="dropdown-menu subject-picker"> <div class="dropdown-menu account-picker">
<a class="dropdown-item {% if request.resolver_match.url_name == "cash" %} active {% endif %}" href="{{ reports.cash }}"> <a class="dropdown-item {% if request.resolver_match.url_name == "cash" %} active {% endif %}" href="{{ reports.cash }}">
<i class="fas fa-money-bill-wave"></i> <i class="fas fa-money-bill-wave"></i>
{% trans "Cash Account" context "Accounting|" as text %} {% trans "Cash Account" context "Accounting|" as text %}
@ -108,9 +108,9 @@ First written: 2020/7/9
{% trans "Search" context "Accounting|" as text %} {% trans "Search" context "Accounting|" as text %}
{{ text|force_escape }} {{ text|force_escape }}
</span> </span>
<a class="dropdown-item {% if request.resolver_match.url_name == "subjects" %} active {% endif %}" href="{% url "accounting:subjects" %}"> <a class="dropdown-item {% if request.resolver_match.url_name == "accounts" %} active {% endif %}" href="{% url "accounting:accounts" %}">
<i class="fas fa-list-ol"></i> <i class="fas fa-list-ol"></i>
{% trans "Subjects" context "Accounting|" as text %} {% trans "Accounts" context "Accounting|" as text %}
{{ text|force_escape }} {{ text|force_escape }}
</a> </a>
</div> </div>

View File

@ -108,7 +108,7 @@ First written: 2020/7/19
</tr> </tr>
{% for item in group.details %} {% for item in group.details %}
<tr> <tr>
<td><div class="subject">{{ item.title|title }}</div></td> <td><div class="account">{{ item.title|title }}</div></td>
<td class="amount {% if item.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td> <td class="amount {% if item.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td>
<td class="amount"></td> <td class="amount"></td>
<td class="actions"> <td class="actions">
@ -171,7 +171,7 @@ First written: 2020/7/19
{{ group.title|title }} {{ group.title|title }}
</li> </li>
{% for item in group.details %} {% for item in group.details %}
<li class="list-group-item d-flex justify-content-between align-items-center subject"> <li class="list-group-item d-flex justify-content-between align-items-center account">
<a class="list-group-item-action" href="{% url "accounting:ledger" item.code period.spec %}"> <a class="list-group-item-action" href="{% url "accounting:ledger" item.code period.spec %}">
{{ item.title|title }} {{ item.title|title }}
<div class="float-right"> <div class="float-right">

View File

@ -82,7 +82,7 @@ First written: 2020/7/17
<thead> <thead>
<tr> <tr>
<th scope="col">{% trans "Date" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Date" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th scope="col">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th scope="col">{% trans "Summary" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Summary" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th class="amount" scope="col">{% trans "Debit" context "Accounting|" as text %}{{ text|force_escape }}</th> <th class="amount" scope="col">{% trans "Debit" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th class="amount" scope="col">{% trans "Credit" context "Accounting|" as text %}{{ text|force_escape }}</th> <th class="amount" scope="col">{% trans "Credit" context "Accounting|" as text %}{{ text|force_escape }}</th>
@ -94,7 +94,7 @@ First written: 2020/7/17
{% for item in item_list %} {% for item in item_list %}
<tr class="{% if not item.is_balanced or item.has_order_hole %} table-danger {% endif %}"> <tr class="{% if not item.is_balanced or item.has_order_hole %} table-danger {% endif %}">
<td>{{ item.transaction.date|smart_date }}</td> <td>{{ item.transaction.date|smart_date }}</td>
<td>{{ item.subject.title|title }}</td> <td>{{ item.account.title|title }}</td>
<td><div class="{% if item.is_credit %} journal-credit {% else %} journal-debit {% endif %}">{{ item.summary|default:"" }}{% if not item.is_balanced %} <td><div class="{% if item.is_credit %} journal-credit {% else %} journal-debit {% endif %}">{{ item.summary|default:"" }}{% if not item.is_balanced %}
<span class="badge badge-danger badge-pill"> <span class="badge badge-danger badge-pill">
{% trans "Unbalanced" context "Accounting|" as text %} {% trans "Unbalanced" context "Accounting|" as text %}
@ -129,8 +129,8 @@ First written: 2020/7/17
{% if item.sn is not None %} {% if item.sn is not None %}
<a class="list-group-item-action" href="{{ item.transaction.get_absolute_url }}"> <a class="list-group-item-action" href="{{ item.transaction.get_absolute_url }}">
<div class="{% if item.is_credit %} journal-credit {% else %} journal-debit {% endif %}"> <div class="{% if item.is_credit %} journal-credit {% else %} journal-debit {% endif %}">
<div class="date-subject-line"> <div class="date-account-line">
{{ item.transaction.date|smart_date }} {{ item.subject.title|title }} {{ item.transaction.date|smart_date }} {{ item.account.title|title }}
</div> </div>
<div class="d-flex justify-content-between align-items-center"> <div class="d-flex justify-content-between align-items-center">
<div> <div>
@ -166,8 +166,8 @@ First written: 2020/7/17
</a> </a>
{% else %} {% else %}
<div class="{% if item.is_credit %} journal-credit {% else %} journal-debit {% endif %}"> <div class="{% if item.is_credit %} journal-credit {% else %} journal-debit {% endif %}">
<div class="date-subject-line"> <div class="date-account-line">
{{ item.transaction.date|smart_date }} {{ item.subject.title|title }} {{ item.transaction.date|smart_date }} {{ item.account.title|title }}
</div> </div>
<div class="d-flex justify-content-between align-items-center"> <div class="d-flex justify-content-between align-items-center">
<div> <div>

View File

@ -27,7 +27,7 @@ First written: 2020/7/16
{% load accounting %} {% load accounting %}
{% block settings %} {% block settings %}
{% blocktrans asvar title with subject=current_subject.title|title context "Accounting|" %}Ledger Summary for {{ subject }}{% endblocktrans %} {% blocktrans asvar title with account=current_account.title|title context "Accounting|" %}Ledger Summary for {{ account }}{% endblocktrans %}
{% setvar "title" title %} {% setvar "title" title %}
{% static "accounting/css/report.css" as css %} {% static "accounting/css/report.css" as css %}
{% setvar "css" css %} {% setvar "css" css %}
@ -66,13 +66,13 @@ First written: 2020/7/16
{% endwith %} {% endwith %}
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown"> <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span class="d-none d-md-inline">{{ current_subject.title|title }}</span> <span class="d-none d-md-inline">{{ current_account.title|title }}</span>
<span class="d-md-none">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</span> <span class="d-md-none">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</span>
</button> </button>
<div class="dropdown-menu subject-picker"> <div class="dropdown-menu account-picker">
{% for subject in subjects %} {% for account in accounts %}
<a class="dropdown-item {% if subject.code == current_subject.code %} active {% endif %}>" href="{% url "accounting:ledger-summary" subject.code %}"> <a class="dropdown-item {% if account.code == current_account.code %} active {% endif %}>" href="{% url "accounting:ledger-summary" account.code %}">
{{ subject.title|title }} {{ account.title|title }}
</a> </a>
{% endfor %} {% endfor %}
</div> </div>
@ -96,7 +96,7 @@ First written: 2020/7/16
</thead> </thead>
<tbody> <tbody>
{% for item in item_list %} {% for item in item_list %}
<tr class="{% if current_subject.code|first in "12" and item.balance < 0 %} table-danger {% endif %}"> <tr class="{% if current_account.code|first in "12" and item.balance < 0 %} table-danger {% endif %}">
<td>{{ item.label }}</td> <td>{{ item.label }}</td>
<td class="amount">{{ item.debit|accounting_amount }}</td> <td class="amount">{{ item.debit|accounting_amount }}</td>
<td class="amount">{{ item.credit|accounting_amount }}</td> <td class="amount">{{ item.credit|accounting_amount }}</td>
@ -104,7 +104,7 @@ First written: 2020/7/16
<td class="amount {% if item.cumulative_balance < 0 %} text-danger {% endif %}">{{ item.cumulative_balance|accounting_amount }}</td> <td class="amount {% if item.cumulative_balance < 0 %} text-danger {% endif %}">{{ item.cumulative_balance|accounting_amount }}</td>
<td class="actions"> <td class="actions">
{% if item.month is not None %} {% if item.month is not None %}
<a class="btn btn-info" role="button" href="{% url "accounting:ledger" current_subject.code item.month|date:"Y-m" %}"> <a class="btn btn-info" role="button" href="{% url "accounting:ledger" current_account.code item.month|date:"Y-m" %}">
<i class="fas fa-eye"></i> <i class="fas fa-eye"></i>
<span class="d-none d-lg-inline">{% trans "View" context "Accounting|" as text %}{{ text|force_escape }}</span> <span class="d-none d-lg-inline">{% trans "View" context "Accounting|" as text %}{{ text|force_escape }}</span>
</a> </a>
@ -118,9 +118,9 @@ First written: 2020/7/16
{# The list for small screens #} {# The list for small screens #}
<ul class="list-group d-sm-none"> <ul class="list-group d-sm-none">
{% for item in item_list %} {% for item in item_list %}
<li class="list-group-item {% if current_subject.code|first in "12" and item.balance < 0 %} list-group-item-danger {% endif %}"> <li class="list-group-item {% if current_account.code|first in "12" and item.balance < 0 %} list-group-item-danger {% endif %}">
{% if item.month is not None %} {% if item.month is not None %}
<a class="list-group-item-action d-flex justify-content-between align-items-center" href="{% url "accounting:ledger" current_subject.code item.month|date:"Y-m" %}"> <a class="list-group-item-action d-flex justify-content-between align-items-center" href="{% url "accounting:ledger" current_account.code item.month|date:"Y-m" %}">
{{ item.label }} {{ item.label }}
<div> <div>
<span class="badge badge-success badge-pill"> <span class="badge badge-success badge-pill">

View File

@ -27,7 +27,7 @@ First written: 2020/7/16
{% load accounting %} {% load accounting %}
{% block settings %} {% block settings %}
{% blocktrans asvar title with subject=current_subject.title|title period=period.description context "Accounting|" %}Ledger for {{ subject }} in {{ period }}{% endblocktrans %} {% blocktrans asvar title with account=current_account.title|title period=period.description context "Accounting|" %}Ledger for {{ account }} in {{ period }}{% endblocktrans %}
{% setvar "title" title %} {% setvar "title" title %}
{% setvar "use_period_chooser" True %} {% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as css %} {% static "accounting/css/report.css" as css %}
@ -67,13 +67,13 @@ First written: 2020/7/16
{% endwith %} {% endwith %}
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown"> <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span class="d-none d-md-inline">{{ current_subject.title|title }}</span> <span class="d-none d-md-inline">{{ current_account.title|title }}</span>
<span class="d-md-none">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</span> <span class="d-md-none">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</span>
</button> </button>
<div class="dropdown-menu subject-picker"> <div class="dropdown-menu account-picker">
{% for subject in subjects %} {% for account in accounts %}
<a class="dropdown-item {% if subject.code == current_subject.code %} active {% endif %}" href="{% url "accounting:ledger" subject.code period.spec %}"> <a class="dropdown-item {% if account.code == current_account.code %} active {% endif %}" href="{% url "accounting:ledger" account.code period.spec %}">
{{ subject.code }} {{ subject.title|title }} {{ account.code }} {{ account.title|title }}
</a> </a>
{% endfor %} {% endfor %}
</div> </div>
@ -95,7 +95,7 @@ First written: 2020/7/16
<thead> <thead>
<tr> <tr>
<th scope="col">{% trans "Date" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Date" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th scope="col">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th scope="col">{% trans "Summary" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Summary" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th class="amount" scope="col">{% trans "Debit" context "Accounting|" as text %}{{ text|force_escape }}</th> <th class="amount" scope="col">{% trans "Debit" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th class="amount" scope="col">{% trans "Credit" context "Accounting|" as text %}{{ text|force_escape }}</th> <th class="amount" scope="col">{% trans "Credit" context "Accounting|" as text %}{{ text|force_escape }}</th>
@ -107,7 +107,7 @@ First written: 2020/7/16
{% for item in item_list %} {% for item in item_list %}
<tr class="{% if not item.is_balanced or item.has_order_hole or not item.is_credit_card_paid %} table-danger {% endif %}{% if item.is_existing_equipment %} table-info {% endif %}"> <tr class="{% if not item.is_balanced or item.has_order_hole or not item.is_credit_card_paid %} table-danger {% endif %}{% if item.is_existing_equipment %} table-info {% endif %}">
<td>{{ item.transaction.date|smart_date }}</td> <td>{{ item.transaction.date|smart_date }}</td>
<td>{{ item.subject.title|title }}</td> <td>{{ item.account.title|title }}</td>
<td>{{ item.summary|default:"" }}{% if not item.is_balanced %} <td>{{ item.summary|default:"" }}{% if not item.is_balanced %}
<span class="badge badge-danger badge-pill"> <span class="badge badge-danger badge-pill">
{% trans "Unbalanced" context "Accounting|" as text %} {% trans "Unbalanced" context "Accounting|" as text %}
@ -151,8 +151,8 @@ First written: 2020/7/16
<li class="list-group-item {% if not item.is_balanced or item.has_order_hole or not item.is_credit_card_paid %} list-group-item-danger {% endif %}{% if item.is_existing_equipment %} list-group-item-info {% endif %}"> <li class="list-group-item {% if not item.is_balanced or item.has_order_hole or not item.is_credit_card_paid %} list-group-item-danger {% endif %}{% if item.is_existing_equipment %} list-group-item-info {% endif %}">
{% if item.sn is not None %} {% if item.sn is not None %}
<a class="list-group-item-action" href="{{ item.transaction.get_absolute_url }}"> <a class="list-group-item-action" href="{{ item.transaction.get_absolute_url }}">
<div class="date-subject-line"> <div class="date-account-line">
{{ item.transaction.date|smart_date }} {{ item.subject.title|title }} {{ item.transaction.date|smart_date }} {{ item.account.title|title }}
</div> </div>
<div class="d-flex justify-content-between align-items-center"> <div class="d-flex justify-content-between align-items-center">
<div> <div>
@ -200,8 +200,8 @@ First written: 2020/7/16
</div> </div>
</a> </a>
{% else %} {% else %}
<div class="date-subject-line"> <div class="date-account-line">
{{ item.transaction.date|smart_date }} {{ item.subject.title|title }} {{ item.transaction.date|smart_date }} {{ item.account.title|title }}
</div> </div>
<div class="d-flex justify-content-between align-items-center"> <div class="d-flex justify-content-between align-items-center">
<div> <div>

View File

@ -85,7 +85,7 @@ First written: 2020/7/21
<thead> <thead>
<tr> <tr>
<th scope="col">{% trans "Date" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Date" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th scope="col">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th scope="col">{% trans "Summary" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Summary" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th class="amount" scope="col">{% trans "Debit" context "Accounting|" as text %}{{ text|force_escape }}</th> <th class="amount" scope="col">{% trans "Debit" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th class="amount" scope="col">{% trans "Credit" context "Accounting|" as text %}{{ text|force_escape }}</th> <th class="amount" scope="col">{% trans "Credit" context "Accounting|" as text %}{{ text|force_escape }}</th>
@ -97,7 +97,7 @@ First written: 2020/7/21
{% for item in item_list %} {% for item in item_list %}
<tr class="{% if not item.is_balanced or item.has_order_hole %} table-danger {% endif %}"> <tr class="{% if not item.is_balanced or item.has_order_hole %} table-danger {% endif %}">
<td>{{ item.transaction.date|smart_date }}</td> <td>{{ item.transaction.date|smart_date }}</td>
<td>{{ item.subject.title|title }}</td> <td>{{ item.account.title|title }}</td>
<td><div class="{% if item.is_credit %} journal-credit {% else %} journal-debit {% endif %}">{{ item.summary|default:"" }}{% if not item.is_balanced %} <td><div class="{% if item.is_credit %} journal-credit {% else %} journal-debit {% endif %}">{{ item.summary|default:"" }}{% if not item.is_balanced %}
<span class="badge badge-danger badge-pill"> <span class="badge badge-danger badge-pill">
{% trans "Unbalanced" context "Accounting|" as text %} {% trans "Unbalanced" context "Accounting|" as text %}
@ -129,8 +129,8 @@ First written: 2020/7/21
<li class="list-group-item {% if not item.is_balanced or item.has_order_hole %} list-group-item-danger {% endif %}"> <li class="list-group-item {% if not item.is_balanced or item.has_order_hole %} list-group-item-danger {% endif %}">
<a class="list-group-item-action" href="{{ item.transaction.get_absolute_url }}"> <a class="list-group-item-action" href="{{ item.transaction.get_absolute_url }}">
<div class="{% if item.is_credit %} journal-credit {% else %} journal-debit {% endif %}"> <div class="{% if item.is_credit %} journal-credit {% else %} journal-debit {% endif %}">
<div class="date-subject-line"> <div class="date-account-line">
{{ item.transaction.date|smart_date }} {{ item.subject.title|title }} {{ item.transaction.date|smart_date }} {{ item.account.title|title }}
</div> </div>
<div class="d-flex justify-content-between align-items-center"> <div class="d-flex justify-content-between align-items-center">
<div> <div>

View File

@ -88,7 +88,7 @@ First written: 2020/7/19
<table class="table table-borderless table-hover trial-balance-table"> <table class="table table-borderless table-hover trial-balance-table">
<thead> <thead>
<tr> <tr>
<th scope="col">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</th> <th scope="col">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th class="amount" scope="col">{% trans "Debit" context "Accounting|" as text %}{{ text|force_escape }}</th> <th class="amount" scope="col">{% trans "Debit" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th class="amount" scope="col">{% trans "Credit" context "Accounting|" as text %}{{ text|force_escape }}</th> <th class="amount" scope="col">{% trans "Credit" context "Accounting|" as text %}{{ text|force_escape }}</th>
<th class="actions" scope="col">{% trans "View" context "Accounting|" as text %}{{ text|force_escape }}</th> <th class="actions" scope="col">{% trans "View" context "Accounting|" as text %}{{ text|force_escape }}</th>

View File

@ -43,19 +43,19 @@ app_name = "accounting"
urlpatterns = [ urlpatterns = [
path("", views.home, name="home"), path("", views.home, name="home"),
path("cash", reports.cash_default, name="cash.home"), path("cash", reports.cash_default, name="cash.home"),
path("cash/<str:subject_code>/<str:period_spec>", path("cash/<str:account_code>/<str:period_spec>",
reports.cash, name="cash"), reports.cash, name="cash"),
path("cash-summary", path("cash-summary",
reports.cash_summary_default, name="cash-summary.home"), reports.cash_summary_default, name="cash-summary.home"),
path("cash-summary/<str:subject_code>", path("cash-summary/<str:account_code>",
reports.cash_summary, name="cash-summary"), reports.cash_summary, name="cash-summary"),
path("ledger", path("ledger",
reports.ledger_default, name="ledger.home"), reports.ledger_default, name="ledger.home"),
path("ledger/<str:subject_code>/<str:period_spec>", path("ledger/<str:account_code>/<str:period_spec>",
reports.ledger, name="ledger"), reports.ledger, name="ledger"),
path("ledger-summary", path("ledger-summary",
reports.ledger_summary_default, name="ledger-summary.home"), reports.ledger_summary_default, name="ledger-summary.home"),
path("ledger-summary/<str:subject_code>", path("ledger-summary/<str:account_code>",
reports.ledger_summary, name="ledger-summary"), reports.ledger_summary, name="ledger-summary"),
path("journal", path("journal",
reports.journal_default, name="journal.home"), reports.journal_default, name="journal.home"),
@ -87,18 +87,18 @@ urlpatterns = [
mia_core_views.todo, name="transactions.update"), mia_core_views.todo, name="transactions.update"),
path("transactions/<int:pk>/delete", path("transactions/<int:pk>/delete",
mia_core_views.todo, name="transactions.delete"), mia_core_views.todo, name="transactions.delete"),
path("subjects", path("accounts",
mia_core_views.todo, name="subjects"), mia_core_views.todo, name="accounts"),
path("subjects/create", path("accounts/create",
mia_core_views.todo, name="subjects.create"), mia_core_views.todo, name="accounts.create"),
path("subjects/store", path("accounts/store",
mia_core_views.todo, name="subjects.store"), mia_core_views.todo, name="accounts.store"),
path("subjects/<str:subject_code>", path("accounts/<str:account_code>",
mia_core_views.todo, name="subjects.view"), mia_core_views.todo, name="accounts.view"),
path("subjects/<str:subject_code>/edit", path("accounts/<str:account_code>/edit",
mia_core_views.todo, name="subjects.edit"), mia_core_views.todo, name="accounts.edit"),
path("subjects/<str:subject_code>/update", path("accounts/<str:account_code>/update",
mia_core_views.todo, name="subjects.update"), mia_core_views.todo, name="accounts.update"),
path("subjects/<str:subject_code>/delete", path("accounts/<str:account_code>/delete",
mia_core_views.todo, name="subjects.delete"), mia_core_views.todo, name="accounts.delete"),
] ]

View File

@ -22,7 +22,7 @@
from django.conf import settings from django.conf import settings
from django.urls import reverse from django.urls import reverse
from accounting.models import Subject from accounting.models import Account
from mia_core.period import Period from mia_core.period import Period
@ -32,9 +32,9 @@ class ReportUrl:
Args: Args:
**kwargs: the keyword arguments: **kwargs: the keyword arguments:
period (Period): The currently-specified period. period (Period): The currently-specified period.
cash (Subject): The currently-specified subject of the cash (Account): The currently-specified account of the
cash account or cash summary. cash account or cash summary.
ledger (Subject): The currently-specified subject of the ledger (Account): The currently-specified account of the
ledger or leger summary. ledger or leger summary.
Attributes: Attributes:
@ -48,8 +48,8 @@ class ReportUrl:
balance_sheet (str): The URL of the balance sheet. balance_sheet (str): The URL of the balance sheet.
""" """
_period = None _period = None
_cash_subject = None _cash_account = None
_ledger_subject = None _ledger_account = None
def __init__(self, **kwargs): def __init__(self, **kwargs):
if "period" in kwargs: if "period" in kwargs:
@ -57,40 +57,38 @@ class ReportUrl:
else: else:
self._period = Period() self._period = Period()
if "cash" in kwargs: if "cash" in kwargs:
self._cash_subject = kwargs["cash"] self._cash_account = kwargs["cash"]
else: else:
self._cash_subject = Subject.objects.filter( self._cash_account = Account.objects.get(
code=settings.ACCOUNTING["DEFAULT_CASH_SUBJECT"] code=settings.ACCOUNTING["DEFAULT_CASH_ACCOUNT"])
).first()
if "ledger" in kwargs: if "ledger" in kwargs:
self._ledger_subject = kwargs["ledger"] self._ledger_account = kwargs["ledger"]
else: else:
self._ledger_subject = Subject.objects.filter( self._ledger_account = Account.objects.get(
code=settings.ACCOUNTING["DEFAULT_LEDGER_SUBJECT"] code=settings.ACCOUNTING["DEFAULT_LEDGER_ACCOUNT"])
).first()
@property @property
def cash(self): def cash(self):
return reverse( return reverse(
"accounting:cash", "accounting:cash",
args=[self._cash_subject.code, self._period.spec]) args=[self._cash_account.code, self._period.spec])
@property @property
def cash_summary(self): def cash_summary(self):
return reverse( return reverse(
"accounting:cash-summary", args=[self._cash_subject.code]) "accounting:cash-summary", args=[self._cash_account.code])
@property @property
def ledger(self): def ledger(self):
return reverse( return reverse(
"accounting:ledger", "accounting:ledger",
args=[self._ledger_subject.code, self._period.spec]) args=[self._ledger_account.code, self._period.spec])
@property @property
def ledger_summary(self): def ledger_summary(self):
return reverse( return reverse(
"accounting:ledger-summary", "accounting:ledger-summary",
args=[self._ledger_subject.code]) args=[self._ledger_account.code])
@property @property
def journal(self): def journal(self):

View File

@ -29,7 +29,7 @@ from django.utils import dateformat, timezone
from django.utils.translation import pgettext, get_language from django.utils.translation import pgettext, get_language
from django.views.decorators.http import require_GET from django.views.decorators.http import require_GET
from accounting.models import Record, Transaction, Subject, \ from accounting.models import Record, Transaction, Account, \
RecordSummary RecordSummary
from accounting.utils import ReportUrl from accounting.utils import ReportUrl
from mia import settings from mia import settings
@ -47,58 +47,58 @@ def cash_default(request):
request (HttpRequest) The request. request (HttpRequest) The request.
Returns: Returns:
HttpResponseRedirect: The redirection to the default subject HttpResponseRedirect: The redirection to the default account
and month. and month.
""" """
subject_code = settings.ACCOUNTING["DEFAULT_CASH_SUBJECT"] account_code = settings.ACCOUNTING["DEFAULT_CASH_ACCOUNT"]
period_spec = dateformat.format(timezone.localdate(), "Y-m") period_spec = dateformat.format(timezone.localdate(), "Y-m")
return HttpResponseRedirect( return HttpResponseRedirect(
reverse("accounting:cash", args=(subject_code, period_spec))) reverse("accounting:cash", args=(account_code, period_spec)))
@require_GET @require_GET
@digest_login_required @digest_login_required
def cash(request, subject_code, period_spec): def cash(request, account_code, period_spec):
"""The cash account. """The cash account.
Args: Args:
request (HttpRequest) The request. request (HttpRequest) The request.
subject_code (str): The code of the specified subject. account_code (str): The code of the specified account.
period_spec (str): The period specificaiton. period_spec (str): The period specification.
Returns: Returns:
HttpResponse: The response. HttpResponse: The response.
""" """
# The period # The period
period = _get_period(period_spec) period = _get_period(period_spec)
# The subject # The account
subjects = _cash_subjects() accounts = _cash_accounts()
current_subject = None current_account = None
for subject in subjects: for account in accounts:
if subject.code == subject_code: if account.code == account_code:
current_subject = subject current_account = account
if current_subject is None: if current_account is None:
raise Http404() raise Http404()
# The accounting records # The accounting records
if current_subject.code == "0": if current_account.code == "0":
records = list(Record.objects.filter( records = list(Record.objects.filter(
Q(transaction__in=Transaction.objects.filter( Q(transaction__in=Transaction.objects.filter(
Q(date__gte=period.start), Q(date__gte=period.start),
Q(date__lte=period.end), Q(date__lte=period.end),
(Q(record__subject__code__startswith="11") | (Q(record__account__code__startswith="11") |
Q(record__subject__code__startswith="12") | Q(record__account__code__startswith="12") |
Q(record__subject__code__startswith="21") | Q(record__account__code__startswith="21") |
Q(record__subject__code__startswith="22")))), Q(record__account__code__startswith="22")))),
~Q(subject__code__startswith="11"), ~Q(account__code__startswith="11"),
~Q(subject__code__startswith="12"), ~Q(account__code__startswith="12"),
~Q(subject__code__startswith="21"), ~Q(account__code__startswith="21"),
~Q(subject__code__startswith="22"))) ~Q(account__code__startswith="22")))
balance_before = Record.objects.filter( balance_before = Record.objects.filter(
Q(transaction__date__lt=period.start), Q(transaction__date__lt=period.start),
(Q(subject__code__startswith="11") | (Q(account__code__startswith="11") |
Q(subject__code__startswith="12") | Q(account__code__startswith="12") |
Q(subject__code__startswith="21") | Q(account__code__startswith="21") |
Q(subject__code__startswith="21")))\ Q(account__code__startswith="21")))\
.aggregate( .aggregate(
balance=Coalesce(Sum(Case( balance=Coalesce(Sum(Case(
When(is_credit=True, then=-1), When(is_credit=True, then=-1),
@ -108,12 +108,12 @@ def cash(request, subject_code, period_spec):
Q(transaction__in=Transaction.objects.filter( Q(transaction__in=Transaction.objects.filter(
Q(date__gte=period.start), Q(date__gte=period.start),
Q(date__lte=period.end), Q(date__lte=period.end),
Q(record__subject__code__startswith= Q(record__account__code__startswith=
current_subject.code))), current_account.code))),
~Q(subject__code__startswith=current_subject.code))) ~Q(account__code__startswith=current_account.code)))
balance_before = Record.objects.filter( balance_before = Record.objects.filter(
transaction__date__lt=period.start, transaction__date__lt=period.start,
subject__code__startswith=current_subject.code)\ account__code__startswith=current_account.code)\
.aggregate( .aggregate(
balance=Coalesce(Sum(Case(When( balance=Coalesce(Sum(Case(When(
is_credit=True, then=-1), is_credit=True, then=-1),
@ -125,7 +125,7 @@ def cash(request, subject_code, period_spec):
record.balance = balance record.balance = balance
record_sum = Record( record_sum = Record(
transaction=Transaction(date=records[-1].transaction.date), transaction=Transaction(date=records[-1].transaction.date),
subject=current_subject, account=current_account,
summary=pgettext("Accounting|", "Total"), summary=pgettext("Accounting|", "Total"),
balance=balance balance=balance
) )
@ -135,7 +135,7 @@ def cash(request, subject_code, period_spec):
x.amount for x in records if not x.is_credit]) x.amount for x in records if not x.is_credit])
records.insert(0, Record( records.insert(0, Record(
transaction=Transaction(date=period.start), transaction=Transaction(date=period.start),
subject=Subject.objects.filter(code="3351").first(), account=Account.objects.filter(code="3351").first(),
is_credit=balance_before >= 0, is_credit=balance_before >= 0,
amount=abs(balance_before), amount=abs(balance_before),
balance=balance_before)) balance=balance_before))
@ -144,17 +144,17 @@ def cash(request, subject_code, period_spec):
records = pagination.items records = pagination.items
_find_imbalanced(records) _find_imbalanced(records)
_find_order_holes(records) _find_order_holes(records)
shortcut_subjects = settings.ACCOUNTING["CASH_SHORTCUT_SUBJECTS"] shortcut_accounts = settings.ACCOUNTING["CASH_SHORTCUT_ACCOUNTS"]
return render(request, "accounting/cash.html", { return render(request, "accounting/cash.html", {
"item_list": records, "item_list": records,
"pagination": pagination, "pagination": pagination,
"current_subject": current_subject, "current_account": current_account,
"period": period, "period": period,
"reports": ReportUrl(cash=current_subject, period=period), "reports": ReportUrl(cash=current_account, period=period),
"shortcut_subjects": [x for x in subjects "shortcut_accounts": [x for x in accounts
if x.code in shortcut_subjects], if x.code in shortcut_accounts],
"all_subjects": [x for x in subjects "all_accounts": [x for x in accounts
if x.code not in shortcut_subjects], if x.code not in shortcut_accounts],
}) })
@ -167,45 +167,45 @@ def cash_summary_default(request):
request (HttpRequest) The request. request (HttpRequest) The request.
Returns: Returns:
HttpResponseRedirect: The redirection to the default subject. HttpResponseRedirect: The redirection to the default account.
""" """
subject_code = settings.ACCOUNTING["DEFAULT_CASH_SUBJECT"] account_code = settings.ACCOUNTING["DEFAULT_CASH_ACCOUNT"]
return HttpResponseRedirect( return HttpResponseRedirect(
reverse("accounting:cash-summary", args=(subject_code))) reverse("accounting:cash-summary", args=(account_code)))
@require_GET @require_GET
@digest_login_required @digest_login_required
def cash_summary(request, subject_code): def cash_summary(request, account_code):
"""The cash account summary. """The cash account summary.
Args: Args:
request (HttpRequest) The request. request (HttpRequest) The request.
subject_code (str): The code of the specified subject. account_code (str): The code of the specified account.
Returns: Returns:
HttpResponse: The response. HttpResponse: The response.
""" """
# The subject # The account
subjects = _cash_subjects() accounts = _cash_accounts()
current_subject = None current_account = None
for subject in subjects: for account in accounts:
if subject.code == subject_code: if account.code == account_code:
current_subject = subject current_account = account
if current_subject is None: if current_account is None:
raise Http404() raise Http404()
# The month summaries # The month summaries
if current_subject.code == "0": if current_account.code == "0":
months = [RecordSummary(**x) for x in Record.objects.filter( months = [RecordSummary(**x) for x in Record.objects.filter(
Q(transaction__in=Transaction.objects.filter( Q(transaction__in=Transaction.objects.filter(
Q(record__subject__code__startswith="11") | Q(record__account__code__startswith="11") |
Q(record__subject__code__startswith="12") | Q(record__account__code__startswith="12") |
Q(record__subject__code__startswith="21") | Q(record__account__code__startswith="21") |
Q(record__subject__code__startswith="22"))), Q(record__account__code__startswith="22"))),
~Q(subject__code__startswith="11"), ~Q(account__code__startswith="11"),
~Q(subject__code__startswith="12"), ~Q(account__code__startswith="12"),
~Q(subject__code__startswith="21"), ~Q(account__code__startswith="21"),
~Q(subject__code__startswith="22")) \ ~Q(account__code__startswith="22")) \
.annotate(month=TruncMonth("transaction__date")) \ .annotate(month=TruncMonth("transaction__date")) \
.values("month") \ .values("month") \
.order_by("month") \ .order_by("month") \
@ -222,8 +222,8 @@ def cash_summary(request, subject_code):
else: else:
months = [RecordSummary(**x) for x in Record.objects.filter( months = [RecordSummary(**x) for x in Record.objects.filter(
Q(transaction__in=Transaction.objects.filter( Q(transaction__in=Transaction.objects.filter(
record__subject__code__startswith=current_subject.code)), record__account__code__startswith=current_account.code)),
~Q(subject__code__startswith=current_subject.code)) \ ~Q(account__code__startswith=current_account.code)) \
.annotate(month=TruncMonth("transaction__date")) \ .annotate(month=TruncMonth("transaction__date")) \
.values("month") \ .values("month") \
.order_by("month") \ .order_by("month") \
@ -249,16 +249,16 @@ def cash_summary(request, subject_code):
cumulative_balance=cumulative_balance, cumulative_balance=cumulative_balance,
)) ))
pagination = Pagination(request, months, True) pagination = Pagination(request, months, True)
shortcut_subjects = settings.ACCOUNTING["CASH_SHORTCUT_SUBJECTS"] shortcut_accounts = settings.ACCOUNTING["CASH_SHORTCUT_ACCOUNTS"]
return render(request, "accounting/cash-summary.html", { return render(request, "accounting/cash-summary.html", {
"item_list": pagination.items, "item_list": pagination.items,
"pagination": pagination, "pagination": pagination,
"current_subject": current_subject, "current_account": current_account,
"reports": ReportUrl(cash=current_subject), "reports": ReportUrl(cash=current_account),
"shortcut_subjects": [x for x in subjects if "shortcut_accounts": [x for x in accounts if
x.code in shortcut_subjects], x.code in shortcut_accounts],
"all_subjects": [x for x in subjects if "all_accounts": [x for x in accounts if
x.code not in shortcut_subjects], x.code not in shortcut_accounts],
}) })
@ -271,54 +271,54 @@ def ledger_default(request):
request (HttpRequest) The request. request (HttpRequest) The request.
Returns: Returns:
HttpResponseRedirect: The redirection to the default subject HttpResponseRedirect: The redirection to the default account
and month. and month.
""" """
subject_code = settings.ACCOUNTING["DEFAULT_LEDGER_SUBJECT"] account_code = settings.ACCOUNTING["DEFAULT_LEDGER_ACCOUNT"]
period_spec = dateformat.format(timezone.localdate(), "Y-m") period_spec = dateformat.format(timezone.localdate(), "Y-m")
return HttpResponseRedirect( return HttpResponseRedirect(
reverse("accounting:ledger", args=(subject_code, period_spec))) reverse("accounting:ledger", args=(account_code, period_spec)))
@require_GET @require_GET
@digest_login_required @digest_login_required
def ledger(request, subject_code, period_spec): def ledger(request, account_code, period_spec):
"""The ledger. """The ledger.
Args: Args:
request (HttpRequest) The request. request (HttpRequest) The request.
subject_code (str): The code of the specified subject. account_code (str): The code of the specified account.
period_spec (str): The period specificaiton. period_spec (str): The period specification.
Returns: Returns:
HttpResponse: The response. HttpResponse: The response.
""" """
# The period # The period
period = _get_period(period_spec) period = _get_period(period_spec)
# The subject # The account
subjects = _ledger_subjects() accounts = _ledger_accounts()
current_subject = None current_account = None
for subject in subjects: for account in accounts:
if subject.code == subject_code: if account.code == account_code:
current_subject = subject current_account = account
if current_subject is None: if current_account is None:
raise Http404() raise Http404()
# The accounting records # The accounting records
records = list(Record.objects.filter( records = list(Record.objects.filter(
transaction__date__gte=period.start, transaction__date__gte=period.start,
transaction__date__lte=period.end, transaction__date__lte=period.end,
subject__code__startswith=current_subject.code)) account__code__startswith=current_account.code))
if re.match("^[1-3]", current_subject.code) is not None: if re.match("^[1-3]", current_account.code) is not None:
balance = Record.objects.filter( balance = Record.objects.filter(
transaction__date__lt=period.start, transaction__date__lt=period.start,
subject__code__startswith=current_subject.code)\ account__code__startswith=current_account.code)\
.aggregate( .aggregate(
balance=Coalesce(Sum(Case(When( balance=Coalesce(Sum(Case(When(
is_credit=True, then=-1), is_credit=True, then=-1),
default=1) * F("amount")), 0))["balance"] default=1) * F("amount")), 0))["balance"]
record_brought_forward = Record( record_brought_forward = Record(
transaction=Transaction(date=period.start), transaction=Transaction(date=period.start),
subject=current_subject, account=current_account,
summary=pgettext("Accounting|", "Brought Forward"), summary=pgettext("Accounting|", "Brought Forward"),
is_credit=balance < 0, is_credit=balance < 0,
amount=abs(balance), amount=abs(balance),
@ -340,10 +340,10 @@ def ledger(request, subject_code, period_spec):
return render(request, "accounting/ledger.html", { return render(request, "accounting/ledger.html", {
"item_list": records, "item_list": records,
"pagination": pagination, "pagination": pagination,
"current_subject": current_subject, "current_account": current_account,
"period": period, "period": period,
"reports": ReportUrl(ledger=current_subject, period=period), "reports": ReportUrl(ledger=current_account, period=period),
"subjects": subjects, "accounts": accounts,
}) })
@ -356,36 +356,36 @@ def ledger_summary_default(request):
request (HttpRequest) The request. request (HttpRequest) The request.
Returns: Returns:
HttpResponseRedirect: The redirection to the default subject. HttpResponseRedirect: The redirection to the default account.
""" """
subject_code = settings.ACCOUNTING["DEFAULT_LEDGER_SUBJECT"] account_code = settings.ACCOUNTING["DEFAULT_LEDGER_ACCOUNT"]
return HttpResponseRedirect( return HttpResponseRedirect(
reverse("accounting:ledger-summary", args=(subject_code))) reverse("accounting:ledger-summary", args=(account_code)))
@require_GET @require_GET
@digest_login_required @digest_login_required
def ledger_summary(request, subject_code): def ledger_summary(request, account_code):
"""The ledger summary report. """The ledger summary report.
Args: Args:
request (HttpRequest) The request. request (HttpRequest) The request.
subject_code (str): The code of the specified subject. account_code (str): The code of the specified account.
Returns: Returns:
HttpResponse: The response. HttpResponse: The response.
""" """
# The subject # The account
subjects = _ledger_subjects() accounts = _ledger_accounts()
current_subject = None current_account = None
for subject in subjects: for account in accounts:
if subject.code == subject_code: if account.code == account_code:
current_subject = subject current_account = account
if current_subject is None: if current_account is None:
raise Http404() raise Http404()
# The month summaries # The month summaries
months = [RecordSummary(**x) for x in Record.objects\ months = [RecordSummary(**x) for x in Record.objects\
.filter(subject__code__startswith=current_subject.code)\ .filter(account__code__startswith=current_account.code)\
.annotate(month=TruncMonth("transaction__date"))\ .annotate(month=TruncMonth("transaction__date"))\
.values("month")\ .values("month")\
.order_by("month")\ .order_by("month")\
@ -414,9 +414,9 @@ def ledger_summary(request, subject_code):
return render(request, "accounting/ledger-summary.html", { return render(request, "accounting/ledger-summary.html", {
"item_list": pagination.items, "item_list": pagination.items,
"pagination": pagination, "pagination": pagination,
"current_subject": current_subject, "current_account": current_account,
"reports": ReportUrl(ledger=current_subject), "reports": ReportUrl(ledger=current_account),
"subjects": subjects, "accounts": accounts,
}) })
@ -456,7 +456,7 @@ def journal(request, period_spec):
transaction__date__lte=period.end).order_by( transaction__date__lte=period.end).order_by(
"transaction__date", "is_credit", "ord") "transaction__date", "is_credit", "ord")
# The brought-forward records # The brought-forward records
brought_forward_subjects = Subject.objects.filter( brought_forward_accounts = Account.objects.filter(
Q(code__startswith="1") Q(code__startswith="1")
| Q(code__startswith="2") | Q(code__startswith="2")
| Q(code__startswith="3"))\ | Q(code__startswith="3"))\
@ -469,29 +469,29 @@ def journal(request, period_spec):
.filter(~Q(balance__gt=0)) .filter(~Q(balance__gt=0))
debit_records = [Record( debit_records = [Record(
transaction=Transaction(date=period.start), transaction=Transaction(date=period.start),
subject=x, account=x,
is_credit=False, is_credit=False,
amount=x.balance amount=x.balance
) for x in brought_forward_subjects if x.balance > 0] ) for x in brought_forward_accounts if x.balance > 0]
credit_records = [Record( credit_records = [Record(
transaction=Transaction(date=period.start), transaction=Transaction(date=period.start),
subject=x, account=x,
is_credit=True, is_credit=True,
amount=-x.balance amount=-x.balance
) for x in brought_forward_subjects if x.balance < 0] ) for x in brought_forward_accounts if x.balance < 0]
sum_debits = sum([x.amount for x in debit_records]) sum_debits = sum([x.amount for x in debit_records])
sum_credits = sum([x.amount for x in credit_records]) sum_credits = sum([x.amount for x in credit_records])
if sum_debits < sum_credits: if sum_debits < sum_credits:
debit_records.append(Record( debit_records.append(Record(
transaction=Transaction(date=period.start), transaction=Transaction(date=period.start),
subject=Subject.objects.filter(code="3351").first(), account=Account.objects.filter(code="3351").first(),
is_credit=False, is_credit=False,
amount=sum_credits - sum_debits amount=sum_credits - sum_debits
)) ))
elif sum_debits > sum_credits: elif sum_debits > sum_credits:
credit_records.append(Record( credit_records.append(Record(
transaction=Transaction(date=period.start), transaction=Transaction(date=period.start),
subject=Subject.objects.filter(code="3351").first(), account=Account.objects.filter(code="3351").first(),
is_credit=True, is_credit=True,
amount=sum_debits - sum_credits amount=sum_debits - sum_credits
)) ))
@ -501,6 +501,7 @@ def journal(request, period_spec):
return render(request, "accounting/journal.html", { return render(request, "accounting/journal.html", {
"item_list": pagination.items, "item_list": pagination.items,
"pagination": pagination, "pagination": pagination,
"reports": ReportUrl(period=period),
"period": period, "period": period,
}) })
@ -537,7 +538,7 @@ def trial_balance(request, period_spec):
period = _get_period(period_spec) period = _get_period(period_spec)
# The accounts # The accounts
nominal = list( nominal = list(
Subject.objects.filter( Account.objects.filter(
Q(record__transaction__date__gte=period.start), Q(record__transaction__date__gte=period.start),
Q(record__transaction__date__lte=period.end), Q(record__transaction__date__lte=period.end),
~(Q(code__startswith="1") ~(Q(code__startswith="1")
@ -556,7 +557,7 @@ def trial_balance(request, period_spec):
When(balance__lt=0, then=-F("balance")), When(balance__lt=0, then=-F("balance")),
default=None))) default=None)))
real = list( real = list(
Subject.objects Account.objects
.filter(Q(record__transaction__date__lte=period.end), .filter(Q(record__transaction__date__lte=period.end),
(Q(code__startswith="1") (Q(code__startswith="1")
| Q(code__startswith="2") | Q(code__startswith="2")
@ -576,17 +577,17 @@ def trial_balance(request, period_spec):
default=None))) default=None)))
balance = Record.objects.filter( balance = Record.objects.filter(
(Q(transaction__date__lt=period.start) (Q(transaction__date__lt=period.start)
& ~(Q(subject__code__startswith="1") & ~(Q(account__code__startswith="1")
| Q(subject__code__startswith="2") | Q(account__code__startswith="2")
| Q(subject__code__startswith="3"))) | Q(account__code__startswith="3")))
| (Q(transaction__date__lte=period.end) | (Q(transaction__date__lte=period.end)
& Q(subject__code="3351")))\ & Q(account__code="3351")))\
.aggregate( .aggregate(
balance=Sum(Case( balance=Sum(Case(
When(is_credit=True, then=-1), When(is_credit=True, then=-1),
default=1) * F("amount")))["balance"] default=1) * F("amount")))["balance"]
if balance is not None and balance != 0: if balance is not None and balance != 0:
brought_forward = Subject.objects.filter(code="3351").first() brought_forward = Account.objects.filter(code="3351").first()
if balance > 0: if balance > 0:
brought_forward.debit = balance brought_forward.debit = balance
brought_forward.credit = 0 brought_forward.credit = 0
@ -596,7 +597,7 @@ def trial_balance(request, period_spec):
real.append(brought_forward) real.append(brought_forward)
accounts = nominal + real accounts = nominal + real
accounts.sort(key=lambda x: x.code) accounts.sort(key=lambda x: x.code)
total_account = Subject() total_account = Account()
total_account.title = pgettext("Accounting|", "Total") total_account.title = pgettext("Accounting|", "Total")
total_account.debit = sum([x.debit for x in accounts total_account.debit = sum([x.debit for x in accounts
if x.debit is not None]) if x.debit is not None])
@ -642,7 +643,7 @@ def income_statement(request, period_spec):
period = _get_period(period_spec) period = _get_period(period_spec)
# The accounts # The accounts
accounts = list( accounts = list(
Subject.objects.filter( Account.objects.filter(
Q(record__transaction__date__gte=period.start), Q(record__transaction__date__gte=period.start),
Q(record__transaction__date__lte=period.end), Q(record__transaction__date__lte=period.end),
~(Q(code__startswith="1") ~(Q(code__startswith="1")
@ -653,17 +654,17 @@ def income_statement(request, period_spec):
When(record__is_credit=True, then=1), When(record__is_credit=True, then=1),
default=-1) * F("record__amount"))) default=-1) * F("record__amount")))
.filter(balance__isnull=False)) .filter(balance__isnull=False))
groups = list(Subject.objects.filter( groups = list(Account.objects.filter(
code__in=[x.code[:2] for x in accounts])) code__in=[x.code[:2] for x in accounts]))
sections = list(Subject.objects.filter( sections = list(Account.objects.filter(
Q(code="4") | Q(code="5") | Q(code="6") Q(code="4") | Q(code="5") | Q(code="6")
| Q(code="7") | Q(code="8") | Q(code="9")).order_by("code")) | Q(code="7") | Q(code="8") | Q(code="9")).order_by("code"))
cumulative_accounts = { cumulative_accounts = {
"5": Subject(title=pgettext("Accounting|", "Gross Income")), "5": Account(title=pgettext("Accounting|", "Gross Income")),
"6": Subject(title=pgettext("Accounting|", "Operating Income")), "6": Account(title=pgettext("Accounting|", "Operating Income")),
"7": Subject(title=pgettext("Accounting|", "Before Tax Income")), "7": Account(title=pgettext("Accounting|", "Before Tax Income")),
"8": Subject(title=pgettext("Accounting|", "After Tax Income")), "8": Account(title=pgettext("Accounting|", "After Tax Income")),
"9": Subject.objects.get(code="3353"), "9": Account.objects.get(code="3353"),
} }
cumulative_total = 0 cumulative_total = 0
for section in sections: for section in sections:
@ -726,7 +727,7 @@ def balance_sheet(request, period_spec):
period = _get_period(period_spec) period = _get_period(period_spec)
# The accounts # The accounts
accounts = list( accounts = list(
Subject.objects Account.objects
.filter(Q(record__transaction__date__lte=period.end), .filter(Q(record__transaction__date__lte=period.end),
(Q(code__startswith="1") (Q(code__startswith="1")
| Q(code__startswith="2") | Q(code__startswith="2")
@ -740,37 +741,37 @@ def balance_sheet(request, period_spec):
balance = Record.objects\ balance = Record.objects\
.filter( .filter(
Q(transaction__date__lt=period.start) Q(transaction__date__lt=period.start)
& ~((Q(subject__code__startswith="1") & ~((Q(account__code__startswith="1")
| Q(subject__code__startswith="2") | Q(account__code__startswith="2")
| Q(subject__code__startswith="3")) | Q(account__code__startswith="3"))
& ~Q(subject__code="3351")))\ & ~Q(account__code="3351")))\
.aggregate( .aggregate(
balance=Sum(Case( balance=Sum(Case(
When(is_credit=True, then=-1), When(is_credit=True, then=-1),
default=1) * F("amount")))["balance"] default=1) * F("amount")))["balance"]
if balance is not None and balance != 0: if balance is not None and balance != 0:
brought_forward = Subject.objects.get(code="3351") brought_forward = Account.objects.get(code="3351")
brought_forward.balance = -balance brought_forward.balance = -balance
accounts.append(brought_forward) accounts.append(brought_forward)
balance = Record.objects\ balance = Record.objects\
.filter( .filter(
Q(transaction__date__gte=period.start) Q(transaction__date__gte=period.start)
& Q(transaction__date__lte=period.end) & Q(transaction__date__lte=period.end)
& ~((Q(subject__code__startswith="1") & ~((Q(account__code__startswith="1")
| Q(subject__code__startswith="2") | Q(account__code__startswith="2")
| Q(subject__code__startswith="3")) | Q(account__code__startswith="3"))
& ~Q(subject__code="3351")))\ & ~Q(account__code="3351")))\
.aggregate( .aggregate(
balance=Sum(Case( balance=Sum(Case(
When(is_credit=True, then=-1), When(is_credit=True, then=-1),
default=1) * F("amount")))["balance"] default=1) * F("amount")))["balance"]
if balance is not None and balance != 0: if balance is not None and balance != 0:
net_income = Subject.objects.get(code="3353") net_income = Account.objects.get(code="3353")
net_income.balance = -balance net_income.balance = -balance
accounts.append(net_income) accounts.append(net_income)
groups = list(Subject.objects.filter( groups = list(Account.objects.filter(
code__in=[x.code[:2] for x in accounts])) code__in=[x.code[:2] for x in accounts]))
sections = list(Subject.objects.filter( sections = list(Account.objects.filter(
Q(code="1") | Q(code="2") | Q(code="3")).order_by("code")) Q(code="1") | Q(code="2") | Q(code="3")).order_by("code"))
for section in sections: for section in sections:
section.groups = [x for x in groups section.groups = [x for x in groups
@ -808,8 +809,8 @@ def search(request):
records = [] records = []
else: else:
records = Record.objects.filter( records = Record.objects.filter(
get_multi_lingual_search("subject__title", query) get_multi_lingual_search("account__title", query)
| Q(subject__code__icontains=query) | Q(account__code__icontains=query)
| Q(summary__icontains=query) | Q(summary__icontains=query)
| Q(transaction__note__icontains=query)) | Q(transaction__note__icontains=query))
pagination = Pagination(request, records, True) pagination = Pagination(request, records, True)
@ -835,35 +836,35 @@ def _get_period(period_spec):
return Period(period_spec, data_start, data_end) return Period(period_spec, data_start, data_end)
def _cash_subjects(): def _cash_accounts():
"""Returns the subjects for the cash account reports. """Returns the cash accounts.
Returns: Returns:
list[Subject]: The subjects for the cash account reports. list[Account]: The cash accounts.
""" """
subjects = list(Subject.objects.filter( accounts = list(Account.objects.filter(
code__in=Record.objects.filter( code__in=Record.objects.filter(
Q(subject__code__startswith="11") Q(account__code__startswith="11")
| Q(subject__code__startswith="12") | Q(account__code__startswith="12")
| Q(subject__code__startswith="21") | Q(account__code__startswith="21")
| Q(subject__code__startswith="22")) | Q(account__code__startswith="22"))
.values("subject__code"))) .values("account__code")))
subjects.insert(0, Subject( accounts.insert(0, Account(
code="0", code="0",
title=pgettext( title=pgettext(
"Accounting|", "current assets and liabilities"), "Accounting|", "current assets and liabilities"),
)) ))
return subjects return accounts
def _ledger_subjects(): def _ledger_accounts():
"""Returns the subjects for the ledger reports. """Returns the accounts for the ledger.
Returns: Returns:
list[Subject]: The subjects for the ledger reports. list[Account]: The accounts for the ledger.
""" """
# TODO: Te be replaced with the Django model queries # TODO: Te be replaced with the Django model queries
return list(Subject.objects.raw("""SELECT s.* return list(Account.objects.raw("""SELECT s.*
FROM accounting_subjects AS s FROM accounting_subjects AS s
WHERE s.code IN (SELECT s.code WHERE s.code IN (SELECT s.code
FROM accounting_subjects AS s FROM accounting_subjects AS s