Added the accounting_amount template filter and applied it in the cash account.

This commit is contained in:
依瑪貓 2020-07-14 10:48:10 +08:00
parent 9cab1c2194
commit 46b20ab500
3 changed files with 45 additions and 3 deletions

View File

@ -22,6 +22,7 @@ First written: 2020/7/1
{% endcomment %}
{% load i18n %}
{% load humanize %}
{% load accounting %}
{% block settings %}
{% blocktrans asvar title with subject=subject.title_zhtw period=period.description context "Accounting|" %}Cash Account for {{ subject }} in {{ period }}{% endblocktrans %}
@ -106,9 +107,9 @@ First written: 2020/7/1
{{ text|force_escape }}
</span>
{% endif %}</td>
<td class="amount">{% if record.credit_amount is not None %}{{ record.credit_amount|intcomma:False }}{% endif %}</td>
<td class="amount">{% if record.debit_amount is not None %}{{ record.debit_amount|intcomma:False }}{% endif %}</td>
<td class="amount">{{ record.balance|intcomma:False }}</td>
<td class="amount">{{ record.credit_amount|accounting_amount }}</td>
<td class="amount">{{ record.debit_amount|accounting_amount }}</td>
<td class="amount">{{ record.balance|accounting_amount }}</td>
<td class="actions">
{% if record.sn is not None %}
<a href="{{ record.transaction.get_absolute_url }}" class="btn btn-info" role="button">

View File

View File

@ -0,0 +1,41 @@
# The accounting application of the Mia project.
# by imacat <imacat@mail.imacat.idv.tw>, 2020/7/13
# Copyright (c) 2020 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The template tags and filters of the accounting application.
"""
import re
from django import template
register = template.Library()
@register.filter
def accounting_amount(value):
if value is None:
return ""
print(value)
s = str(abs(value))
while True:
m = re.match("^([1-9][0-9]*)([0-9]{3})", s)
if m is None:
break
s = m.group(1) + "," + m.group(2)
if value < 0:
s = "(%s)" % (s)
return s