Added the get_multi_language_attr() function to the Mia core application, to deal with the multi-lingual attributes, and applied it in the data models.
This commit is contained in:
@ -22,6 +22,8 @@ from django.conf import settings
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
|
||||
from mia_core.utils import get_multi_language_attr
|
||||
|
||||
|
||||
class Subject(models.Model):
|
||||
"""An accounting subject."""
|
||||
@ -50,7 +52,19 @@ class Subject(models.Model):
|
||||
def __str__(self):
|
||||
"""Returns the string representation of this accounting
|
||||
subject."""
|
||||
return self.code.__str__() + " " + self.title_zhtw.__str__()
|
||||
return self.code.__str__() + " " + self.title
|
||||
|
||||
_title = None
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
if self._title is None:
|
||||
self._title = get_multi_language_attr(self, "title")
|
||||
return self._title
|
||||
|
||||
@title.setter
|
||||
def title(self, value):
|
||||
self._title = value
|
||||
|
||||
class Meta:
|
||||
db_table = "accounting_subjects"
|
||||
@ -241,7 +255,7 @@ class Record(models.Model):
|
||||
record."""
|
||||
return "%s %s %s %s" % (
|
||||
self.transaction.date,
|
||||
self.subject.title_zhtw,
|
||||
self.subject.title,
|
||||
self.summary,
|
||||
self.amount)
|
||||
|
||||
|
@ -25,7 +25,7 @@ First written: 2020/7/1
|
||||
{% load accounting %}
|
||||
|
||||
{% block settings %}
|
||||
{% blocktrans asvar title with subject=current_subject.title_zhtw period=period.description context "Accounting|" %}Cash Account for {{ subject }} in {{ period }}{% endblocktrans %}
|
||||
{% blocktrans asvar title with subject=current_subject.title|title period=period.description context "Accounting|" %}Cash Account for {{ subject }} in {{ period }}{% endblocktrans %}
|
||||
{% setvar "title" title %}
|
||||
{% setvar "use_period_chooser" True %}
|
||||
{% endblock %}
|
||||
@ -63,17 +63,17 @@ 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_zhtw }}</span>
|
||||
<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>
|
||||
</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 %}{% endif %}>" href="{% url "accounting:cash" subject.code period.spec %}">{{ subject.title_zhtw|title }}</a>
|
||||
<a class="dropdown-item {% if subject.code == current_subject.code %}{% endif %}>" href="{% url "accounting:cash" subject.code period.spec %}">{{ subject.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 %}{% endif %}>" href="{% url "accounting:cash" subject.code period.spec %}">{{ subject.title_zhtw|title }}</a>
|
||||
<a class="dropdown-item {% if subject.code == current_subject.code %}{% endif %}>" href="{% url "accounting:cash" subject.code period.spec %}">{{ subject.title|title }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
@ -106,7 +106,7 @@ First written: 2020/7/1
|
||||
{% for record in records %}
|
||||
<tr class="{% if not record.transaction.is_balanced or record.transaction.has_order_hole %} table-danger {% endif %}">
|
||||
<td>{{ record.transaction.date|smart_date }}</td>
|
||||
<td>{{ record.subject.title_zhtw }}</td>
|
||||
<td>{{ record.subject.title|title }}</td>
|
||||
<td>{{ record.summary|default:"" }}{% if not record.transaction.is_balanced %}
|
||||
<span class="badge badge-danger badge-pill">
|
||||
{% trans "Unbalanced" context "Accounting|" as text %}
|
||||
@ -141,7 +141,7 @@ First written: 2020/7/1
|
||||
{% if record.sn is not None %}
|
||||
<a class="list-group-item-action" href="{{ record.transaction.get_absolute_url }}">
|
||||
<div class="date-subject-line d-flex justify-content-between align-items-center">
|
||||
{{ record.transaction.date|smart_date }} {{ record.subject.title_zhtw }}
|
||||
{{ record.transaction.date|smart_date }} {{ record.subject.title|title }}
|
||||
</div>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
@ -168,7 +168,7 @@ First written: 2020/7/1
|
||||
</a>
|
||||
{% else %}
|
||||
<div class="date-subject-line d-flex justify-content-between align-items-center">
|
||||
{{ record.transaction.date|smart_date }} {{ record.subject.title_zhtw }}
|
||||
{{ record.transaction.date|smart_date }} {{ record.subject.title }}
|
||||
</div>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>{{ record.summary|default:"" }}</div>
|
||||
|
@ -88,7 +88,7 @@ FROM accounting_subjects AS s
|
||||
ORDER BY s.code"""))
|
||||
subjects.insert(0, Subject(
|
||||
code="0",
|
||||
title_zhtw=pgettext(
|
||||
title=pgettext(
|
||||
"Accounting|", "current assets and liabilities"),
|
||||
))
|
||||
current_subject = None
|
||||
|
Reference in New Issue
Block a user