Renamed all the is_XXX_needed properties to is_need_XXX. For example, especially the is_offset_needed property to is_need_offset, to be clear and understandable.

This commit is contained in:
依瑪貓 2023-03-18 22:52:29 +08:00
parent 98e1bad413
commit 5571c0d01f
21 changed files with 55 additions and 55 deletions

View File

@ -29,7 +29,7 @@ from accounting.utils.user import has_user, get_user_pk
AccountData = tuple[int, str, int, str, str, str, bool]
"""The format of the account data, as a list of (ID, base account code, number,
English, Traditional Chinese, Simplified Chinese, is-offset-needed) tuples."""
English, Traditional Chinese, Simplified Chinese, is-need-offset) tuples."""
def __validate_username(ctx: click.core.Context, param: click.core.Option,
@ -92,14 +92,14 @@ def init_accounts_command(username: str) -> None:
data: list[AccountData] = []
for base in bases_to_add:
l10n: dict[str, str] = {x.locale: x.title for x in base.l10n}
is_offset_needed: bool = __is_offset_needed(base.code)
is_need_offset: bool = __is_need_offset(base.code)
data.append((get_new_id(), base.code, 1, base.title_l10n,
l10n["zh_Hant"], l10n["zh_Hans"], is_offset_needed))
l10n["zh_Hant"], l10n["zh_Hans"], is_need_offset))
__add_accounting_accounts(data, creator_pk)
click.echo(F"{len(data)} added. Accounting accounts initialized.")
def __is_offset_needed(base_code: str) -> bool:
def __is_need_offset(base_code: str) -> bool:
"""Checks that whether entries in the account need offset.
:param base_code: The code of the base account.
@ -134,7 +134,7 @@ def __add_accounting_accounts(data: list[AccountData], creator_pk: int)\
base_code=x[1],
no=x[2],
title_l10n=x[3],
is_offset_needed=x[6],
is_need_offset=x[6],
created_by_id=creator_pk,
updated_by_id=creator_pk)
for x in data]

View File

@ -80,7 +80,7 @@ class AccountForm(FlaskForm):
filters=[strip_text],
validators=[DataRequired(lazy_gettext("Please fill in the title"))])
"""The title."""
is_offset_needed = BooleanField(
is_need_offset = BooleanField(
validators=[NoOffsetNominalAccount()])
"""Whether the the entries of this account need offset."""
@ -103,9 +103,9 @@ class AccountForm(FlaskForm):
obj.no = count + 1
obj.title = self.title.data
if self.base_code.data[0] in {"1", "2", "3"}:
obj.is_offset_needed = self.is_offset_needed.data
obj.is_need_offset = self.is_need_offset.data
else:
obj.is_offset_needed = False
obj.is_need_offset = False
if is_new:
current_user_pk: int = get_current_user_pk()
obj.created_by_id = current_user_pk

View File

@ -48,7 +48,7 @@ def get_account_query() -> list[Account]:
code.contains(k),
Account.id.in_(l10n_matches)]
if k in gettext("Need offset"):
sub_conditions.append(Account.is_offset_needed)
sub_conditions.append(Account.is_need_offset)
conditions.append(sa.or_(*sub_conditions))
return Account.query.filter(*conditions)\

View File

@ -114,7 +114,7 @@ class Account(db.Model):
"""The account number under the base account."""
title_l10n = db.Column("title", db.String, nullable=False)
"""The title."""
is_offset_needed = db.Column(db.Boolean, nullable=False, default=False)
is_need_offset = db.Column(db.Boolean, nullable=False, default=False)
"""Whether the entries of this account need offset."""
created_at = db.Column(db.DateTime(timezone=True), nullable=False,
server_default=db.func.now())
@ -702,7 +702,7 @@ class JournalEntry(db.Model):
:return: True if the entry needs offset, or False otherwise.
"""
if not self.account.is_offset_needed:
if not self.account.is_need_offset:
return False
if self.account.base_code[0] == "1" and not self.is_debit:
return False

View File

@ -97,7 +97,7 @@ class EntryCollector:
code.contains(k),
Account.id.in_(select_l10n)]
if k in gettext("Need offset"):
conditions.append(Account.is_offset_needed)
conditions.append(Account.is_need_offset)
return sa.select(Account.id).filter(sa.or_(*conditions))
@staticmethod

View File

@ -83,16 +83,16 @@ class AccountForm {
#titleError;
/**
* The control of the is-offset-needed option
* The control of the is-need-offset option
* @type {HTMLDivElement}
*/
#isOffsetNeededControl;
#isNeedOffsetControl;
/**
* The is-offset-needed option
* The is-need-offset option
* @type {HTMLInputElement}
*/
#isOffsetNeeded;
#isNeedOffset;
/**
* Constructs the account form.
@ -107,8 +107,8 @@ class AccountForm {
this.#baseError = document.getElementById("accounting-base-error");
this.#title = document.getElementById("accounting-title");
this.#titleError = document.getElementById("accounting-title-error");
this.#isOffsetNeededControl = document.getElementById("accounting-is-offset-needed-control");
this.#isOffsetNeeded = document.getElementById("accounting-is-offset-needed");
this.#isNeedOffsetControl = document.getElementById("accounting-is-need-offset-control");
this.#isNeedOffset = document.getElementById("accounting-is-need-offset");
this.#formElement.onsubmit = () => {
return this.#validateForm();
};
@ -138,12 +138,12 @@ class AccountForm {
this.#baseCode.value = code;
this.#base.innerText = text;
if (["1", "2", "3"].includes(code.substring(0, 1))) {
this.#isOffsetNeededControl.classList.remove("d-none");
this.#isOffsetNeeded.disabled = false;
this.#isNeedOffsetControl.classList.remove("d-none");
this.#isNeedOffset.disabled = false;
} else {
this.#isOffsetNeededControl.classList.add("d-none");
this.#isOffsetNeeded.disabled = true;
this.#isOffsetNeeded.checked = false;
this.#isNeedOffsetControl.classList.add("d-none");
this.#isNeedOffset.disabled = true;
this.#isNeedOffset.checked = false;
}
this.#validateBase();
}

View File

@ -105,7 +105,7 @@ class AccountSelector {
};
this.#clearButton.onclick = () => this.#entryEditor.clearAccount();
for (const option of this.#options) {
option.onclick = () => this.#entryEditor.saveAccount(option.dataset.code, option.dataset.content, option.classList.contains("accounting-account-is-offset-needed"));
option.onclick = () => this.#entryEditor.saveAccount(option.dataset.code, option.dataset.content, option.classList.contains("accounting-account-is-need-offset"));
}
this.#query.addEventListener("input", () => {
this.#filterOptions();

View File

@ -374,10 +374,10 @@ class JournalEntryEditor {
*
* @param code {string} the account code
* @param text {string} the account text
* @param isOffsetNeeded {boolean} true if the journal entries in the account need offset or false otherwise
* @param isNeedOffset {boolean} true if the journal entries in the account need offset or false otherwise
*/
saveAccount(code, text, isOffsetNeeded) {
this.isNeedOffset = isOffsetNeeded;
saveAccount(code, text, isNeedOffset) {
this.isNeedOffset = isNeedOffset;
this.#accountControl.classList.add("accounting-not-empty");
this.accountCode = code;
this.accountText = text;

View File

@ -215,7 +215,7 @@ class SummaryEditor {
#submit() {
bootstrap.Modal.getOrCreateInstance(this.#modal).hide();
if (this.#selectedAccount !== null) {
this.#entryEditor.saveSummaryWithAccount(this.summary.value, this.#selectedAccount.dataset.code, this.#selectedAccount.dataset.text, this.#selectedAccount.classList.contains("accounting-account-is-offset-needed"));
this.#entryEditor.saveSummaryWithAccount(this.summary.value, this.#selectedAccount.dataset.code, this.#selectedAccount.dataset.text, this.#selectedAccount.classList.contains("accounting-account-is-need-offset"));
} else {
this.#entryEditor.saveSummary(this.summary.value);
}

View File

@ -85,7 +85,7 @@ First written: 2023/1/31
<div class="accounting-card col-sm-6">
<div class="accounting-card-title">{{ obj.title }}</div>
<div class="accounting-card-code">{{ obj.code }}</div>
{% if obj.is_offset_needed %}
{% if obj.is_need_offset %}
<div>
<span class="badge rounded-pill bg-info">{{ A_("Need offset") }}</span>
</div>

View File

@ -62,9 +62,9 @@ First written: 2023/2/1
<div id="accounting-title-error" class="invalid-feedback">{% if form.title.errors %}{{ form.title.errors[0] }}{% endif %}</div>
</div>
<div id="accounting-is-offset-needed-control" class="form-check form-switch mb-3 {% if form.base_code.data[0] not in ["1", "2", "3"] %} d-none {% endif %}">
<input id="accounting-is-offset-needed" class="form-check-input" type="checkbox" name="is_offset_needed" value="1" {% if form.is_offset_needed.data %} checked="checked" {% endif %}>
<label class="form-check-label" for="accounting-is-offset-needed">
<div id="accounting-is-need-offset-control" class="form-check form-switch mb-3 {% if form.base_code.data[0] not in ["1", "2", "3"] %} d-none {% endif %}">
<input id="accounting-is-need-offset" class="form-check-input" type="checkbox" name="is_need_offset" value="1" {% if form.is_need_offset.data %} checked="checked" {% endif %}>
<label class="form-check-label" for="accounting-is-need-offset">
{{ A_("The entries in the account need offset.") }}
</label>
</div>

View File

@ -58,7 +58,7 @@ First written: 2023/1/30
{% for item in list %}
<a class="list-group-item list-group-item-action" href="{{ url_for("accounting.account.detail", account=item)|accounting_append_next }}">
{{ item }}
{% if item.is_offset_needed %}
{% if item.is_need_offset %}
<span class="badge rounded-pill bg-info">{{ A_("Need offset") }}</span>
{% endif %}
</a>

View File

@ -37,7 +37,7 @@ First written: 2023/2/25
<ul id="accounting-account-selector-{{ entry_type }}-option-list" class="list-group accounting-selector-list">
{% for account in account_options %}
<li id="accounting-account-selector-{{ entry_type }}-option-{{ account.code }}" class="list-group-item accounting-clickable accounting-account-selector-{{ entry_type }}-option {% if account.is_in_use %} accounting-account-in-use {% endif %} {% if account.is_offset_needed %} accounting-account-is-offset-needed {% endif %}" data-code="{{ account.code }}" data-content="{{ account }}" data-query-values="{{ account.query_values|tojson|forceescape }}" data-bs-toggle="modal" data-bs-target="#accounting-entry-editor-modal">
<li id="accounting-account-selector-{{ entry_type }}-option-{{ account.code }}" class="list-group-item accounting-clickable accounting-account-selector-{{ entry_type }}-option {% if account.is_in_use %} accounting-account-in-use {% endif %} {% if account.is_need_offset %} accounting-account-is-need-offset {% endif %}" data-code="{{ account.code }}" data-content="{{ account }}" data-query-values="{{ account.query_values|tojson|forceescape }}" data-bs-toggle="modal" data-bs-target="#accounting-entry-editor-modal">
{{ account }}
</li>
{% endfor %}

View File

@ -177,7 +177,7 @@ First written: 2023/2/28
{# The suggested accounts #}
<div class="mt-3">
{% for account in summary_editor.accounts %}
<button class="btn btn-outline-primary d-none accounting-summary-editor-{{ summary_editor.type }}-account {% if account.is_offset_needed %} accounting-account-is-offset-needed {% endif %}" type="button" data-code="{{ account.code }}" data-text="{{ account }}">
<button class="btn btn-outline-primary d-none accounting-summary-editor-{{ summary_editor.type }}-account {% if account.is_need_offset %} accounting-account-is-need-offset {% endif %}" type="button" data-code="{{ account.code }}" data-text="{{ account }}">
{{ account }}
</button>
{% endfor %}

View File

@ -81,7 +81,7 @@ class OriginalEntryNeedOffset:
= db.session.get(JournalEntry, field.data)
if original_entry is None:
return
if not original_entry.account.is_offset_needed:
if not original_entry.account.is_need_offset:
raise ValidationError(lazy_gettext(
"The original entry does not need offset."))
@ -186,7 +186,7 @@ class NotStartPayableFromDebit:
or form.original_entry_id.data is not None:
return
account: Account | None = Account.find_by_code(field.data)
if account is not None and account.is_offset_needed:
if account is not None and account.is_need_offset:
raise ValidationError(lazy_gettext(
"A payable entry cannot start from the debit side."))
@ -202,7 +202,7 @@ class NotStartReceivableFromCredit:
or form.original_entry_id.data is not None:
return
account: Account | None = Account.find_by_code(field.data)
if account is not None and account.is_offset_needed:
if account is not None and account.is_need_offset:
raise ValidationError(lazy_gettext(
"A receivable entry cannot start from the credit side."))
@ -361,7 +361,7 @@ class JournalEntryForm(FlaskForm):
else:
return False
account: Account | None = Account.find_by_code(self.account_code.data)
return account is not None and account.is_offset_needed
return account is not None and account.is_need_offset
@property
def offsets(self) -> list[JournalEntry]:

View File

@ -219,7 +219,7 @@ class TransactionForm(FlaskForm):
"""
accounts: list[AccountOption] \
= [AccountOption(x) for x in Account.debit()
if not (x.code[0] == "2" and x.is_offset_needed)]
if not (x.code[0] == "2" and x.is_need_offset)]
in_use: set[int] = set(db.session.scalars(
sa.select(JournalEntry.account_id)
.filter(JournalEntry.is_debit)
@ -236,7 +236,7 @@ class TransactionForm(FlaskForm):
"""
accounts: list[AccountOption] \
= [AccountOption(x) for x in Account.credit()
if not (x.code[0] == "1" and x.is_offset_needed)]
if not (x.code[0] == "1" and x.is_need_offset)]
in_use: set[int] = set(db.session.scalars(
sa.select(JournalEntry.account_id)
.filter(sa.not_(JournalEntry.is_debit))

View File

@ -38,7 +38,7 @@ class AccountOption:
"""The string representation of the account option."""
self.is_in_use: bool = False
"""True if this account is in use, or False otherwise."""
self.is_offset_needed: bool = account.is_offset_needed
self.is_need_offset: bool = account.is_need_offset
"""True if this account needs offset, or False otherwise."""
def __str__(self) -> str:

View File

@ -50,7 +50,7 @@ def get_selectable_original_entries(
(offset.c.id.in_(entry_id_on_form), 0),
(be(offset.c.is_debit == JournalEntry.is_debit), offset.c.amount),
else_=-offset.c.amount))).label("net_balance")
conditions: list[sa.BinaryExpression] = [Account.is_offset_needed]
conditions: list[sa.BinaryExpression] = [Account.is_need_offset]
sub_conditions: list[sa.BinaryExpression] = []
if is_payable:
sub_conditions.append(sa.and_(Account.base_code.startswith("2"),

View File

@ -377,7 +377,7 @@ class AccountTestCase(unittest.TestCase):
data={"csrf_token": self.csrf_token,
"base_code": "6172",
"title": stock.title,
"is_offset_needed": "yes"})
"is_need_offset": "yes"})
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], create_uri)
@ -484,7 +484,7 @@ class AccountTestCase(unittest.TestCase):
data={"csrf_token": self.csrf_token,
"base_code": "6172",
"title": stock.title,
"is_offset_needed": "yes"})
"is_need_offset": "yes"})
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], edit_uri)

View File

@ -113,7 +113,7 @@ class OffsetTestCase(unittest.TestCase):
# The original entry does not need offset
with self.app.app_context():
account = Account.find_by_code(Accounts.RECEIVABLE)
account.is_offset_needed = False
account.is_need_offset = False
db.session.commit()
response = self.client.post(store_uri,
data=txn_data.new_form(self.csrf_token))
@ -121,7 +121,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], create_uri)
with self.app.app_context():
account = Account.find_by_code(Accounts.RECEIVABLE)
account.is_offset_needed = True
account.is_need_offset = True
db.session.commit()
# The original entry is also an offset
@ -219,7 +219,7 @@ class OffsetTestCase(unittest.TestCase):
# The original entry does not need offset
with self.app.app_context():
account = Account.find_by_code(Accounts.RECEIVABLE)
account.is_offset_needed = False
account.is_need_offset = False
db.session.commit()
response = self.client.post(update_uri,
data=txn_data.update_form(self.csrf_token))
@ -227,7 +227,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], edit_uri)
with self.app.app_context():
account = Account.find_by_code(Accounts.RECEIVABLE)
account.is_offset_needed = True
account.is_need_offset = True
db.session.commit()
# The original entry is also an offset
@ -419,7 +419,7 @@ class OffsetTestCase(unittest.TestCase):
# The original entry does not need offset
with self.app.app_context():
account = Account.find_by_code(Accounts.PAYABLE)
account.is_offset_needed = False
account.is_need_offset = False
db.session.commit()
response = self.client.post(store_uri,
data=txn_data.new_form(self.csrf_token))
@ -427,7 +427,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], create_uri)
with self.app.app_context():
account = Account.find_by_code(Accounts.PAYABLE)
account.is_offset_needed = True
account.is_need_offset = True
db.session.commit()
# The original entry is also an offset
@ -525,7 +525,7 @@ class OffsetTestCase(unittest.TestCase):
# The original entry does not need offset
with self.app.app_context():
account = Account.find_by_code(Accounts.PAYABLE)
account.is_offset_needed = False
account.is_need_offset = False
db.session.commit()
response = self.client.post(update_uri,
data=txn_data.update_form(self.csrf_token))
@ -533,7 +533,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], edit_uri)
with self.app.app_context():
account = Account.find_by_code(Accounts.PAYABLE)
account.is_offset_needed = True
account.is_need_offset = True
db.session.commit()
# The original entry is also an offset

View File

@ -152,7 +152,7 @@ class PaginationTestCase(unittest.TestCase):
:param items: All the items in the list.
:param is_reversed: Whether the default page is the last page.
:param result: The expected items on the page.
:param is_paged: Whether the pagination is needed.
:param is_paged: Whether we need pagination.
"""
self.items: list[int] = items
self.is_reversed: bool | None = is_reversed
@ -192,7 +192,7 @@ class PaginationTestCase(unittest.TestCase):
:param query: The query string.
:param items: The original items.
:param result: The expected page content.
:param is_paged: Whether the pagination is needed.
:param is_paged: Whether we need pagination.
:param is_reversed: Whether the list is reversed.
:return: None.
"""