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

View File

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

View File

@ -97,7 +97,7 @@ First written: 2020/7/20
</tr>
{% for item in group.details %}
<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="actions">
<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>
{% for item in group.details %}
<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="actions">
<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>
{% for item in group.details %}
<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="actions">
<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 }}
</li>
{% 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 %}">
{{ item.title|title }}
<div class="float-right">
@ -266,7 +266,7 @@ First written: 2020/7/20
{{ group.title|title }}
</li>
{% 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 %}">
{{ item.title|title }}
<div class="float-right">
@ -295,8 +295,8 @@ First written: 2020/7/20
{{ group.title|title }}
</li>
{% for item in group.details %}
<li class="list-group-item d-flex justify-content-between align-items-center subject">
{# TODO: Link to the income statement for subject #3353 #}
<li class="list-group-item d-flex justify-content-between align-items-center account">
{# TODO: Link to the income statement for account #3353 #}
<a class="list-group-item-action" href="{% url "accounting:ledger" item.code period.spec %}">
{{ item.title|title }}
<div class="float-right">

View File

@ -27,7 +27,7 @@ First written: 2020/7/15
{% load accounting %}
{% 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 %}
{% static "accounting/css/report.css" as css %}
{% setvar "css" css %}
@ -66,20 +66,20 @@ First written: 2020/7/15
{% endwith %}
<div class="btn-group">
<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-md-none">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</span>
<span class="d-none d-md-inline">{{ current_account.title|title }}</span>
<span class="d-md-none">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</span>
</button>
<div class="dropdown-menu subject-picker">
<div class="dropdown-header">{% trans "Shortcuts" context "Accounting|Subject|" as text %}{{ text|force_escape }}</div>
{% for subject in shortcut_subjects %}
<a class="dropdown-item {% if subject.code == current_subject.code %} active {% endif %}>" href="{% url "accounting:cash-summary" subject.code %}">
{{ subject.title|title }}
<div class="dropdown-menu account-picker">
<div class="dropdown-header">{% trans "Shortcuts" context "Accounting|Account|" as text %}{{ text|force_escape }}</div>
{% for account in shortcut_accounts %}
<a class="dropdown-item {% if account.code == current_account.code %} active {% endif %}>" href="{% url "accounting:cash-summary" account.code %}">
{{ account.title|title }}
</a>
{% endfor %}
<div class="dropdown-header">{% trans "All" context "Accounting|Subject|" as text %}{{ text|force_escape }}</div>
{% for subject in all_sibjects %}
<a class="dropdown-item {% if subject.code == current_subject.code %} active {% endif %}>" href="{% url "accounting:cash-summary" subject.code %}">
{{ subject.code }} {{ subject.title|title }}
<div class="dropdown-header">{% trans "All" context "Accounting|Account|" as text %}{{ text|force_escape }}</div>
{% for account in all_accounts %}
<a class="dropdown-item {% if account.code == current_account.code %} active {% endif %}>" href="{% url "accounting:cash-summary" account.code %}">
{{ account.code }} {{ account.title|title }}
</a>
{% endfor %}
</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="actions">
{% 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>
<span class="d-none d-lg-inline">{% trans "View" context "Accounting|" as text %}{{ text|force_escape }}</span>
</a>
@ -127,7 +127,7 @@ First written: 2020/7/15
{% for item in item_list %}
<li class="list-group-item {% if item.balance < 0 %} list-group-item-danger {% endif %}">
{% 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 }}
<div>
<span class="badge badge-success badge-pill">

View File

@ -27,7 +27,7 @@ First written: 2020/7/1
{% load accounting %}
{% 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 "use_period_chooser" True %}
{% static "accounting/css/report.css" as css %}
@ -67,20 +67,20 @@ First written: 2020/7/1
{% endwith %}
<div class="btn-group">
<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-md-none">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</span>
<span class="d-none d-md-inline">{{ current_account.title|title }}</span>
<span class="d-md-none">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</span>
</button>
<div class="dropdown-menu subject-picker">
<div class="dropdown-header">{% trans "Shortcuts" context "Accounting|Subject|" as text %}{{ text|force_escape }}</div>
{% for subject in shortcut_subjects %}
<a class="dropdown-item {% if subject.code == current_subject.code %} active {% endif %}>" href="{% url "accounting:cash" subject.code period.spec %}">
{{ subject.title|title }}
<div class="dropdown-menu account-picker">
<div class="dropdown-header">{% trans "Shortcuts" context "Accounting|Account|" as text %}{{ text|force_escape }}</div>
{% for account in shortcut_accounts %}
<a class="dropdown-item {% if account.code == current_account.code %} active {% endif %}>" href="{% url "accounting:cash" account.code period.spec %}">
{{ account.title|title }}
</a>
{% endfor %}
<div class="dropdown-header">{% trans "All" context "Accounting|Subject|" as text %}{{ text|force_escape }}</div>
{% for subject in all_sibjects %}
<a class="dropdown-item {% if subject.code == current_subject.code %} active {% endif %}>" href="{% url "accounting:cash" subject.code period.spec %}">
{{ subject.code }} {{ subject.title|title }}
<div class="dropdown-header">{% trans "All" context "Accounting|Account|" as text %}{{ text|force_escape }}</div>
{% for account in all_accounts %}
<a class="dropdown-item {% if account.code == current_account.code %} active {% endif %}>" href="{% url "accounting:cash" account.code period.spec %}">
{{ account.code }} {{ account.title|title }}
</a>
{% endfor %}
</div>
@ -102,7 +102,7 @@ First written: 2020/7/1
<thead>
<tr>
<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 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>
@ -114,7 +114,7 @@ First written: 2020/7/1
{% for item in item_list %}
<tr class="{% if not item.is_balanced or item.has_order_hole %} table-danger {% endif %}">
<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 %}
<span class="badge badge-danger badge-pill">
{% 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 %}">
{% if item.sn is not None %}
<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">
{{ item.transaction.date|smart_date }} {{ item.subject.title|title }}
<div class="date-account-line d-flex justify-content-between align-items-center">
{{ item.transaction.date|smart_date }} {{ item.account.title|title }}
</div>
<div class="d-flex justify-content-between align-items-center">
<div>
@ -185,8 +185,8 @@ First written: 2020/7/1
</div>
</a>
{% else %}
<div class="date-subject-line d-flex justify-content-between align-items-center">
{{ item.transaction.date|smart_date }} {{ item.subject.title }}
<div class="date-account-line d-flex justify-content-between align-items-center">
{{ item.transaction.date|smart_date }} {{ item.account.title }}
</div>
<div class="d-flex justify-content-between align-items-center">
<div>{{ item.summary|default:"" }}</div>

View File

@ -62,7 +62,7 @@ First written: 2020/7/9
</span>
<span class="d-md-none">{% trans "Book" context "Accounting|" as text %}{{ text|force_escape }}</span>
</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 }}">
<i class="fas fa-money-bill-wave"></i>
{% trans "Cash Account" context "Accounting|" as text %}
@ -108,9 +108,9 @@ First written: 2020/7/9
{% trans "Search" context "Accounting|" as text %}
{{ text|force_escape }}
</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>
{% trans "Subjects" context "Accounting|" as text %}
{% trans "Accounts" context "Accounting|" as text %}
{{ text|force_escape }}
</a>
</div>

View File

@ -108,7 +108,7 @@ First written: 2020/7/19
</tr>
{% for item in group.details %}
<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"></td>
<td class="actions">
@ -171,7 +171,7 @@ First written: 2020/7/19
{{ group.title|title }}
</li>
{% 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 %}">
{{ item.title|title }}
<div class="float-right">

View File

@ -82,7 +82,7 @@ First written: 2020/7/17
<thead>
<tr>
<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 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>
@ -94,7 +94,7 @@ First written: 2020/7/17
{% for item in item_list %}
<tr class="{% if not item.is_balanced or item.has_order_hole %} table-danger {% endif %}">
<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 %}
<span class="badge badge-danger badge-pill">
{% trans "Unbalanced" context "Accounting|" as text %}
@ -129,8 +129,8 @@ First written: 2020/7/17
{% if item.sn is not None %}
<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="date-subject-line">
{{ item.transaction.date|smart_date }} {{ item.subject.title|title }}
<div class="date-account-line">
{{ item.transaction.date|smart_date }} {{ item.account.title|title }}
</div>
<div class="d-flex justify-content-between align-items-center">
<div>
@ -166,8 +166,8 @@ First written: 2020/7/17
</a>
{% else %}
<div class="{% if item.is_credit %} journal-credit {% else %} journal-debit {% endif %}">
<div class="date-subject-line">
{{ item.transaction.date|smart_date }} {{ item.subject.title|title }}
<div class="date-account-line">
{{ item.transaction.date|smart_date }} {{ item.account.title|title }}
</div>
<div class="d-flex justify-content-between align-items-center">
<div>

View File

@ -27,7 +27,7 @@ First written: 2020/7/16
{% load accounting %}
{% 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 %}
{% static "accounting/css/report.css" as css %}
{% setvar "css" css %}
@ -66,13 +66,13 @@ First written: 2020/7/16
{% endwith %}
<div class="btn-group">
<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-md-none">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</span>
<span class="d-none d-md-inline">{{ current_account.title|title }}</span>
<span class="d-md-none">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</span>
</button>
<div class="dropdown-menu subject-picker">
{% for subject in subjects %}
<a class="dropdown-item {% if subject.code == current_subject.code %} active {% endif %}>" href="{% url "accounting:ledger-summary" subject.code %}">
{{ subject.title|title }}
<div class="dropdown-menu account-picker">
{% for account in accounts %}
<a class="dropdown-item {% if account.code == current_account.code %} active {% endif %}>" href="{% url "accounting:ledger-summary" account.code %}">
{{ account.title|title }}
</a>
{% endfor %}
</div>
@ -96,7 +96,7 @@ First written: 2020/7/16
</thead>
<tbody>
{% 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 class="amount">{{ item.debit|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="actions">
{% 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>
<span class="d-none d-lg-inline">{% trans "View" context "Accounting|" as text %}{{ text|force_escape }}</span>
</a>
@ -118,9 +118,9 @@ First written: 2020/7/16
{# The list for small screens #}
<ul class="list-group d-sm-none">
{% 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 %}
<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 }}
<div>
<span class="badge badge-success badge-pill">

View File

@ -27,7 +27,7 @@ First written: 2020/7/16
{% load accounting %}
{% 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 "use_period_chooser" True %}
{% static "accounting/css/report.css" as css %}
@ -67,13 +67,13 @@ First written: 2020/7/16
{% endwith %}
<div class="btn-group">
<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-md-none">{% trans "Subject" context "Accounting|" as text %}{{ text|force_escape }}</span>
<span class="d-none d-md-inline">{{ current_account.title|title }}</span>
<span class="d-md-none">{% trans "Account" context "Accounting|" as text %}{{ text|force_escape }}</span>
</button>
<div class="dropdown-menu subject-picker">
{% for subject in subjects %}
<a class="dropdown-item {% if subject.code == current_subject.code %} active {% endif %}" href="{% url "accounting:ledger" subject.code period.spec %}">
{{ subject.code }} {{ subject.title|title }}
<div class="dropdown-menu account-picker">
{% for account in accounts %}
<a class="dropdown-item {% if account.code == current_account.code %} active {% endif %}" href="{% url "accounting:ledger" account.code period.spec %}">
{{ account.code }} {{ account.title|title }}
</a>
{% endfor %}
</div>
@ -95,7 +95,7 @@ First written: 2020/7/16
<thead>
<tr>
<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 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>
@ -107,7 +107,7 @@ First written: 2020/7/16
{% 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 %}">
<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 %}
<span class="badge badge-danger badge-pill">
{% 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 %}">
{% if item.sn is not None %}
<a class="list-group-item-action" href="{{ item.transaction.get_absolute_url }}">
<div class="date-subject-line">
{{ item.transaction.date|smart_date }} {{ item.subject.title|title }}
<div class="date-account-line">
{{ item.transaction.date|smart_date }} {{ item.account.title|title }}
</div>
<div class="d-flex justify-content-between align-items-center">
<div>
@ -200,8 +200,8 @@ First written: 2020/7/16
</div>
</a>
{% else %}
<div class="date-subject-line">
{{ item.transaction.date|smart_date }} {{ item.subject.title|title }}
<div class="date-account-line">
{{ item.transaction.date|smart_date }} {{ item.account.title|title }}
</div>
<div class="d-flex justify-content-between align-items-center">
<div>

View File

@ -85,7 +85,7 @@ First written: 2020/7/21
<thead>
<tr>
<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 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>
@ -97,7 +97,7 @@ First written: 2020/7/21
{% for item in item_list %}
<tr class="{% if not item.is_balanced or item.has_order_hole %} table-danger {% endif %}">
<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 %}
<span class="badge badge-danger badge-pill">
{% 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 %}">
<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="date-subject-line">
{{ item.transaction.date|smart_date }} {{ item.subject.title|title }}
<div class="date-account-line">
{{ item.transaction.date|smart_date }} {{ item.account.title|title }}
</div>
<div class="d-flex justify-content-between align-items-center">
<div>

View File

@ -88,7 +88,7 @@ First written: 2020/7/19
<table class="table table-borderless table-hover trial-balance-table">
<thead>
<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 "Credit" 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 = [
path("", views.home, name="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"),
path("cash-summary",
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"),
path("ledger",
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"),
path("ledger-summary",
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"),
path("journal",
reports.journal_default, name="journal.home"),
@ -87,18 +87,18 @@ urlpatterns = [
mia_core_views.todo, name="transactions.update"),
path("transactions/<int:pk>/delete",
mia_core_views.todo, name="transactions.delete"),
path("subjects",
mia_core_views.todo, name="subjects"),
path("subjects/create",
mia_core_views.todo, name="subjects.create"),
path("subjects/store",
mia_core_views.todo, name="subjects.store"),
path("subjects/<str:subject_code>",
mia_core_views.todo, name="subjects.view"),
path("subjects/<str:subject_code>/edit",
mia_core_views.todo, name="subjects.edit"),
path("subjects/<str:subject_code>/update",
mia_core_views.todo, name="subjects.update"),
path("subjects/<str:subject_code>/delete",
mia_core_views.todo, name="subjects.delete"),
path("accounts",
mia_core_views.todo, name="accounts"),
path("accounts/create",
mia_core_views.todo, name="accounts.create"),
path("accounts/store",
mia_core_views.todo, name="accounts.store"),
path("accounts/<str:account_code>",
mia_core_views.todo, name="accounts.view"),
path("accounts/<str:account_code>/edit",
mia_core_views.todo, name="accounts.edit"),
path("accounts/<str:account_code>/update",
mia_core_views.todo, name="accounts.update"),
path("accounts/<str:account_code>/delete",
mia_core_views.todo, name="accounts.delete"),
]

View File

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