Renamed the is_credit_card_paid() utility to is_payable(), and implemented it in the accounting application.
This commit is contained in:
parent
75cc6b2d00
commit
eac77c725a
@ -7,8 +7,8 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: mia-js 1.0\n"
|
"Project-Id-Version: mia-js 1.0\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2020-08-06 23:59+0800\n"
|
"POT-Creation-Date: 2020-08-07 00:37+0800\n"
|
||||||
"PO-Revision-Date: 2020-08-07 00:01+0800\n"
|
"PO-Revision-Date: 2020-08-07 00:38+0800\n"
|
||||||
"Last-Translator: imacat <imacat@mail.imacat.idv.tw>\n"
|
"Last-Translator: imacat <imacat@mail.imacat.idv.tw>\n"
|
||||||
"Language-Team: Traditional Chinese <imacat@mail.imacat.idv.tw>\n"
|
"Language-Team: Traditional Chinese <imacat@mail.imacat.idv.tw>\n"
|
||||||
"Language: Traditional Chinese\n"
|
"Language: Traditional Chinese\n"
|
||||||
@ -496,7 +496,7 @@ msgstr "%(prep_period)s%(account)s的分類帳"
|
|||||||
|
|
||||||
#: accounting/templates/accounting/ledger.html:112
|
#: accounting/templates/accounting/ledger.html:112
|
||||||
#: accounting/templates/accounting/ledger.html:159
|
#: accounting/templates/accounting/ledger.html:159
|
||||||
msgid "Unpaid"
|
msgid "Payable"
|
||||||
msgstr "未付款"
|
msgstr "未付款"
|
||||||
|
|
||||||
#: accounting/templates/accounting/ledger.html:116
|
#: accounting/templates/accounting/ledger.html:116
|
||||||
@ -756,3 +756,6 @@ msgstr "-----使用中科目-----"
|
|||||||
#: accounting/views.py:1080
|
#: accounting/views.py:1080
|
||||||
msgid "---Accounts Not In Use---"
|
msgid "---Accounts Not In Use---"
|
||||||
msgstr "-----未使用科目-----"
|
msgstr "-----未使用科目-----"
|
||||||
|
|
||||||
|
#~ msgid "Unpaid"
|
||||||
|
#~ msgstr "未付款"
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
from dirtyfields import DirtyFieldsMixin
|
from dirtyfields import DirtyFieldsMixin
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import Sum, Case, When, F, Q
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from mia_core.utils import get_multi_lingual_attr, set_multi_lingual_attr
|
from mia_core.utils import get_multi_lingual_attr, set_multi_lingual_attr
|
||||||
@ -322,8 +323,9 @@ class Record(DirtyFieldsMixin, models.Model):
|
|||||||
self.balance = None
|
self.balance = None
|
||||||
self._is_balanced = None
|
self._is_balanced = None
|
||||||
self._has_order_hole = None
|
self._has_order_hole = None
|
||||||
self._is_credit_card_paid = None
|
self._is_payable = None
|
||||||
self._is_existing_equipment = None
|
self._is_existing_equipment = None
|
||||||
|
self.is_payable = False
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Returns the string representation of this accounting
|
"""Returns the string representation of this accounting
|
||||||
@ -382,17 +384,6 @@ class Record(DirtyFieldsMixin, models.Model):
|
|||||||
def has_order_hole(self, value):
|
def has_order_hole(self, value):
|
||||||
self._has_order_hole = value
|
self._has_order_hole = value
|
||||||
|
|
||||||
@property
|
|
||||||
def is_credit_card_paid(self):
|
|
||||||
# TODO: To be done
|
|
||||||
if self._is_credit_card_paid is None:
|
|
||||||
self._is_credit_card_paid = True
|
|
||||||
return self._is_credit_card_paid
|
|
||||||
|
|
||||||
@is_credit_card_paid.setter
|
|
||||||
def is_credit_card_paid(self, value):
|
|
||||||
self._is_credit_card_paid = value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_existing_equipment(self):
|
def is_existing_equipment(self):
|
||||||
# TODO: To be done
|
# TODO: To be done
|
||||||
|
@ -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 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 item.is_payable %} 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.account.title|title_case }}</td>
|
<td>{{ item.account.title|title_case }}</td>
|
||||||
<td>{{ item.summary|default:"" }}{% if not item.is_balanced %}
|
<td>{{ item.summary|default:"" }}{% if not item.is_balanced %}
|
||||||
@ -107,9 +107,9 @@ First written: 2020/7/16
|
|||||||
<span class="badge badge-danger badge-pill">
|
<span class="badge badge-danger badge-pill">
|
||||||
{{ _("Need Reorder")|force_escape }}
|
{{ _("Need Reorder")|force_escape }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}{% if not item.is_credit_card_paid %}
|
{% endif %}{% if item.is_payable %}
|
||||||
<span class="badge badge-danger badge-pill">
|
<span class="badge badge-danger badge-pill">
|
||||||
{{ _("Unpaid")|force_escape }}
|
{{ _("Payable")|force_escape }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}{% if item.is_existing_equipment %}
|
{% endif %}{% if item.is_existing_equipment %}
|
||||||
<span class="badge badge-info badge-pill">
|
<span class="badge badge-info badge-pill">
|
||||||
@ -135,7 +135,7 @@ First written: 2020/7/16
|
|||||||
{# The list for small screens #}
|
{# The list for small screens #}
|
||||||
<ul class="list-group d-md-none">
|
<ul class="list-group d-md-none">
|
||||||
{% for item in item_list %}
|
{% for item in item_list %}
|
||||||
<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 item.is_payable %} list-group-item-danger {% endif %}{% if item.is_existing_equipment %} list-group-item-info {% endif %}">
|
||||||
{% if item.pk is not None %}
|
{% if item.pk is not None %}
|
||||||
<a class="list-group-item-action" href="{% url_with_return "accounting:transactions.show" item.transaction.type item.transaction %}">
|
<a class="list-group-item-action" href="{% url_with_return "accounting:transactions.show" item.transaction.type item.transaction %}">
|
||||||
<div class="date-account-line">
|
<div class="date-account-line">
|
||||||
@ -154,9 +154,9 @@ First written: 2020/7/16
|
|||||||
{{ _("Need Reorder")|force_escape }}
|
{{ _("Need Reorder")|force_escape }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if not item.is_credit_card_paid %}
|
{% if item.is_payable %}
|
||||||
<span class="badge badge-danger badge-pill">
|
<span class="badge badge-danger badge-pill">
|
||||||
{{ _("Unpaid")|force_escape }}
|
{{ _("Payable")|force_escape }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if item.is_existing_equipment %}
|
{% if item.is_existing_equipment %}
|
||||||
|
@ -323,6 +323,35 @@ def find_order_holes(records):
|
|||||||
and record.transaction.date in holes
|
and record.transaction.date in holes
|
||||||
|
|
||||||
|
|
||||||
|
def find_payable_records(account, records):
|
||||||
|
"""Finds and sets the whether the payable record is paid.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
account (Account): The current ledger account.
|
||||||
|
records (list[Record]): The accounting records.
|
||||||
|
"""
|
||||||
|
if "PAYABLE_ACCOUNTS" not in settings.ACCOUNTING:
|
||||||
|
return
|
||||||
|
if not isinstance(settings.ACCOUNTING["PAYABLE_ACCOUNTS"], list):
|
||||||
|
return
|
||||||
|
if account.code not in settings.ACCOUNTING["PAYABLE_ACCOUNTS"]:
|
||||||
|
return
|
||||||
|
rows = Record.objects\
|
||||||
|
.filter(
|
||||||
|
account__code__in=settings.ACCOUNTING["PAYABLE_ACCOUNTS"],
|
||||||
|
summary__isnull=False)\
|
||||||
|
.values("account__code", "summary")\
|
||||||
|
.annotate(
|
||||||
|
balance=Sum(Case(When(is_credit=True, then=1), default=-1)
|
||||||
|
* F("amount")))\
|
||||||
|
.filter(~Q(balance=0))
|
||||||
|
keys = ["%s-%s" % (x["account__code"], x["summary"]) for x in rows]
|
||||||
|
for x in [x for x in records
|
||||||
|
if x.pk is not None
|
||||||
|
and F"{x.account.code}-{x.summary}" in keys]:
|
||||||
|
x.is_payable = True
|
||||||
|
|
||||||
|
|
||||||
def get_summary_categories():
|
def get_summary_categories():
|
||||||
"""Finds and returns the summary categories and their corresponding account
|
"""Finds and returns the summary categories and their corresponding account
|
||||||
hints.
|
hints.
|
||||||
|
@ -45,7 +45,7 @@ from .utils import ReportUrl, get_cash_accounts, get_ledger_accounts, \
|
|||||||
find_imbalanced, find_order_holes, fill_txn_from_post, \
|
find_imbalanced, find_order_holes, fill_txn_from_post, \
|
||||||
sort_post_txn_records, make_txn_form_from_status, \
|
sort_post_txn_records, make_txn_form_from_status, \
|
||||||
make_txn_form_from_model, make_txn_form_from_post, MonthlySummary, \
|
make_txn_form_from_model, make_txn_form_from_post, MonthlySummary, \
|
||||||
get_summary_categories
|
get_summary_categories, find_payable_records
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(require_GET, name="dispatch")
|
@method_decorator(require_GET, name="dispatch")
|
||||||
@ -340,6 +340,7 @@ def ledger(request, account, period):
|
|||||||
records = pagination.items
|
records = pagination.items
|
||||||
find_imbalanced(records)
|
find_imbalanced(records)
|
||||||
find_order_holes(records)
|
find_order_holes(records)
|
||||||
|
find_payable_records(account, records)
|
||||||
return render(request, "accounting/ledger.html", {
|
return render(request, "accounting/ledger.html", {
|
||||||
"item_list": records,
|
"item_list": records,
|
||||||
"pagination": pagination,
|
"pagination": pagination,
|
||||||
|
@ -7,7 +7,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: mia 1.0\n"
|
"Project-Id-Version: mia 1.0\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2020-08-06 23:59+0800\n"
|
"POT-Creation-Date: 2020-08-07 00:37+0800\n"
|
||||||
"PO-Revision-Date: 2020-08-07 00:01+0800\n"
|
"PO-Revision-Date: 2020-08-07 00:01+0800\n"
|
||||||
"Last-Translator: imacat <imacat@mail.imacat.idv.tw>\n"
|
"Last-Translator: imacat <imacat@mail.imacat.idv.tw>\n"
|
||||||
"Language-Team: Traditional Chinese <imacat@mail.imacat.idv.tw>\n"
|
"Language-Team: Traditional Chinese <imacat@mail.imacat.idv.tw>\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user