Replaced the regular payments with the regular account settings in the summary helper, to remove the dependency on the local JavaScript codes in the accounting application.

This commit is contained in:
依瑪貓 2020-08-31 10:15:06 +08:00
parent 4cb92dd309
commit 1da6cf3208
8 changed files with 292 additions and 77 deletions

View File

@ -7,8 +7,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: mia-accounting 3.0\n" "Project-Id-Version: mia-accounting 3.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-08-27 23:04+0800\n" "POT-Creation-Date: 2020-08-31 09:53+0800\n"
"PO-Revision-Date: 2020-08-27 23:07+0800\n" "PO-Revision-Date: 2020-08-31 09:58+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"
@ -195,22 +195,22 @@ msgstr "勞保{month}"
msgid "Health insurance for {month}" msgid "Health insurance for {month}"
msgstr "健保{month}" msgstr "健保{month}"
#: accounting/management/commands/accounting_sample.py:246 #: accounting/management/commands/accounting_sample.py:247
msgid "Income Tax" msgid "Income Tax"
msgstr "代扣所得稅" msgstr "代扣所得稅"
#: accounting/management/commands/accounting_sample.py:247 #: accounting/management/commands/accounting_sample.py:248
#, python-brace-format #, python-brace-format
msgid "Payroll for {month}" msgid "Payroll for {month}"
msgstr "{month}份薪水" msgstr "{month}份薪水"
#: accounting/templates/accounting/account_detail.html:37 #: accounting/templates/accounting/account_detail.html:37
#: accounting/templates/accounting/transaction_expense_detail.html:39 #: accounting/templates/accounting/transaction_expense_detail.html:39
#: accounting/templates/accounting/transaction_expense_form.html:47 #: accounting/templates/accounting/transaction_expense_form.html:45
#: accounting/templates/accounting/transaction_income_detail.html:39 #: accounting/templates/accounting/transaction_income_detail.html:39
#: accounting/templates/accounting/transaction_income_form.html:47 #: accounting/templates/accounting/transaction_income_form.html:45
#: accounting/templates/accounting/transaction_transfer_detail.html:39 #: accounting/templates/accounting/transaction_transfer_detail.html:39
#: accounting/templates/accounting/transaction_transfer_form.html:47 #: accounting/templates/accounting/transaction_transfer_form.html:45
msgid "Error:" msgid "Error:"
msgstr "錯誤:" msgstr "錯誤:"
@ -246,12 +246,12 @@ msgstr "取消"
#: accounting/templates/accounting/account_detail.html:71 #: accounting/templates/accounting/account_detail.html:71
#: accounting/templates/accounting/account_form.html:42 #: accounting/templates/accounting/account_form.html:42
#: accounting/templates/accounting/transaction_expense_detail.html:73 #: accounting/templates/accounting/transaction_expense_detail.html:73
#: accounting/templates/accounting/transaction_expense_form.html:54 #: accounting/templates/accounting/transaction_expense_form.html:52
#: accounting/templates/accounting/transaction_income_detail.html:73 #: accounting/templates/accounting/transaction_income_detail.html:73
#: accounting/templates/accounting/transaction_income_form.html:54 #: accounting/templates/accounting/transaction_income_form.html:52
#: accounting/templates/accounting/transaction_sort_form.html:43 #: accounting/templates/accounting/transaction_sort_form.html:43
#: accounting/templates/accounting/transaction_transfer_detail.html:73 #: accounting/templates/accounting/transaction_transfer_detail.html:73
#: accounting/templates/accounting/transaction_transfer_form.html:54 #: accounting/templates/accounting/transaction_transfer_form.html:52
msgid "Back" msgid "Back"
msgstr "回上頁" msgstr "回上頁"
@ -274,7 +274,7 @@ msgid "Ledger"
msgstr "分類帳" msgstr "分類帳"
#: accounting/templates/accounting/account_detail.html:107 #: accounting/templates/accounting/account_detail.html:107
#: accounting/views.py:1028 #: accounting/views.py:1076
msgid "This account is in use." msgid "This account is in use."
msgstr "會計科目使用中。" msgstr "會計科目使用中。"
@ -347,10 +347,10 @@ msgid "Add a New Account"
msgstr "建新會計科目" msgstr "建新會計科目"
#: accounting/templates/accounting/account_form.html:81 #: accounting/templates/accounting/account_form.html:81
#: accounting/templates/accounting/transaction_expense_form.html:117 #: accounting/templates/accounting/transaction_expense_form.html:116
#: accounting/templates/accounting/transaction_income_form.html:116 #: accounting/templates/accounting/transaction_income_form.html:115
#: accounting/templates/accounting/transaction_sort_form.html:137 #: accounting/templates/accounting/transaction_sort_form.html:137
#: accounting/templates/accounting/transaction_transfer_form.html:149 #: accounting/templates/accounting/transaction_transfer_form.html:148
msgid "Save" msgid "Save"
msgstr "儲存" msgstr "儲存"
@ -626,18 +626,18 @@ msgstr "期間"
#: accounting/templates/accounting/report-trial-balance.html:146 #: accounting/templates/accounting/report-trial-balance.html:146
#: accounting/templates/accounting/transaction_expense_detail.html:146 #: accounting/templates/accounting/transaction_expense_detail.html:146
#: accounting/templates/accounting/transaction_expense_detail.html:164 #: accounting/templates/accounting/transaction_expense_detail.html:164
#: accounting/templates/accounting/transaction_expense_form.html:95 #: accounting/templates/accounting/transaction_expense_form.html:94
#: accounting/templates/accounting/transaction_income_detail.html:146 #: accounting/templates/accounting/transaction_income_detail.html:146
#: accounting/templates/accounting/transaction_income_detail.html:164 #: accounting/templates/accounting/transaction_income_detail.html:164
#: accounting/templates/accounting/transaction_income_form.html:94 #: accounting/templates/accounting/transaction_income_form.html:93
#: accounting/templates/accounting/transaction_transfer_detail.html:142 #: accounting/templates/accounting/transaction_transfer_detail.html:142
#: accounting/templates/accounting/transaction_transfer_detail.html:160 #: accounting/templates/accounting/transaction_transfer_detail.html:160
#: accounting/templates/accounting/transaction_transfer_detail.html:189 #: accounting/templates/accounting/transaction_transfer_detail.html:189
#: accounting/templates/accounting/transaction_transfer_detail.html:207 #: accounting/templates/accounting/transaction_transfer_detail.html:207
#: accounting/templates/accounting/transaction_transfer_form.html:96 #: accounting/templates/accounting/transaction_transfer_form.html:95
#: accounting/templates/accounting/transaction_transfer_form.html:126 #: accounting/templates/accounting/transaction_transfer_form.html:125
#: accounting/views.py:132 accounting/views.py:241 accounting/views.py:381 #: accounting/views.py:135 accounting/views.py:244 accounting/views.py:384
#: accounting/views.py:568 #: accounting/views.py:571
msgid "Total" msgid "Total"
msgstr "合計" msgstr "合計"
@ -756,7 +756,7 @@ msgstr "%(prep_period)s的日記簿"
#: accounting/templates/accounting/report-trial-balance.html:84 #: accounting/templates/accounting/report-trial-balance.html:84
#: accounting/templates/accounting/search.html:78 #: accounting/templates/accounting/search.html:78
#: accounting/templates/accounting/transaction_transfer_detail.html:121 #: accounting/templates/accounting/transaction_transfer_detail.html:121
#: accounting/templates/accounting/transaction_transfer_form.html:75 #: accounting/templates/accounting/transaction_transfer_form.html:74
msgid "Debit" msgid "Debit"
msgstr "借方" msgstr "借方"
@ -766,7 +766,7 @@ msgstr "借方"
#: accounting/templates/accounting/report-trial-balance.html:85 #: accounting/templates/accounting/report-trial-balance.html:85
#: accounting/templates/accounting/search.html:79 #: accounting/templates/accounting/search.html:79
#: accounting/templates/accounting/transaction_transfer_detail.html:168 #: accounting/templates/accounting/transaction_transfer_detail.html:168
#: accounting/templates/accounting/transaction_transfer_form.html:105 #: accounting/templates/accounting/transaction_transfer_form.html:104
msgid "Credit" msgid "Credit"
msgstr "貸方" msgstr "貸方"
@ -864,12 +864,12 @@ msgid "To Transfer"
msgstr "改轉帳" msgstr "改轉帳"
#: accounting/templates/accounting/transaction_expense_detail.html:123 #: accounting/templates/accounting/transaction_expense_detail.html:123
#: accounting/templates/accounting/transaction_expense_form.html:65 #: accounting/templates/accounting/transaction_expense_form.html:64
#: accounting/templates/accounting/transaction_income_detail.html:123 #: accounting/templates/accounting/transaction_income_detail.html:123
#: accounting/templates/accounting/transaction_income_form.html:65 #: accounting/templates/accounting/transaction_income_form.html:64
#: accounting/templates/accounting/transaction_sort_form.html:49 #: accounting/templates/accounting/transaction_sort_form.html:49
#: accounting/templates/accounting/transaction_transfer_detail.html:115 #: accounting/templates/accounting/transaction_transfer_detail.html:115
#: accounting/templates/accounting/transaction_transfer_form.html:65 #: accounting/templates/accounting/transaction_transfer_form.html:64
msgid "Date:" msgid "Date:"
msgstr "日期:" msgstr "日期:"
@ -881,11 +881,11 @@ msgid "$"
msgstr "$" msgstr "$"
#: accounting/templates/accounting/transaction_expense_detail.html:172 #: accounting/templates/accounting/transaction_expense_detail.html:172
#: accounting/templates/accounting/transaction_expense_form.html:105 #: accounting/templates/accounting/transaction_expense_form.html:104
#: accounting/templates/accounting/transaction_income_detail.html:172 #: accounting/templates/accounting/transaction_income_detail.html:172
#: accounting/templates/accounting/transaction_income_form.html:104 #: accounting/templates/accounting/transaction_income_form.html:103
#: accounting/templates/accounting/transaction_transfer_detail.html:217 #: accounting/templates/accounting/transaction_transfer_detail.html:217
#: accounting/templates/accounting/transaction_transfer_form.html:137 #: accounting/templates/accounting/transaction_transfer_form.html:136
msgid "Notes:" msgid "Notes:"
msgstr "註記:" msgstr "註記:"
@ -940,62 +940,119 @@ msgstr "沒有這個會計科目。"
msgid "You cannot select a parent account." msgid "You cannot select a parent account."
msgstr "請勿選擇上層會計科目。" msgstr "請勿選擇上層會計科目。"
#: accounting/views.py:308 #: accounting/views.py:311
msgid "Brought Forward" msgid "Brought Forward"
msgstr "上期結轉" msgstr "上期結轉"
#: accounting/views.py:622 #: accounting/views.py:625
msgid "Gross Income" msgid "Gross Income"
msgstr "營業毛利" msgstr "營業毛利"
#: accounting/views.py:623 #: accounting/views.py:626
msgid "Operating Income" msgid "Operating Income"
msgstr "營業淨利" msgstr "營業淨利"
#: accounting/views.py:624 #: accounting/views.py:627
msgid "Before Tax Income" msgid "Before Tax Income"
msgstr "稅前淨利" msgstr "稅前淨利"
#: accounting/views.py:625 #: accounting/views.py:628
msgid "After Tax Income" msgid "After Tax Income"
msgstr "稅後淨利" msgstr "稅後淨利"
#: accounting/views.py:802 #: accounting/views.py:805
msgid "This transaction was not modified." msgid "This transaction was not modified."
msgstr "會計傳票未異動。" msgstr "會計傳票未異動。"
#: accounting/views.py:803 #: accounting/views.py:806
msgid "This transaction was saved successfully." msgid "This transaction was saved successfully."
msgstr "會計傳票已存檔。" msgstr "會計傳票已存檔。"
#: accounting/views.py:910 #: accounting/views.py:809
msgid "Pension"
msgstr "國民年金"
#: accounting/views.py:809
msgid "Pension for (last_month_name)"
msgstr "國民年金(last_month_no)月"
#: accounting/views.py:811
msgid "Health insurance"
msgstr "健保"
#: accounting/views.py:812
msgid "Health insurance for (last_month_name)"
msgstr "健保(last_month_no)月"
#: accounting/views.py:813
msgid "Electricity bill"
msgstr "電費"
#: accounting/views.py:814
msgid ""
"Electricity bill for (last_bimonthly_from_name)-(last_bimonthly_to_name)"
msgstr "電費(last_bimonthly_from_no)(last_bimonthly_to_no)月"
#: accounting/views.py:817
msgid "Water bill"
msgstr "水費"
#: accounting/views.py:818
msgid "Water bill for (last_bimonthly_from_name)-(last_bimonthly_to_name)"
msgstr "水費(last_bimonthly_from_no)(last_bimonthly_to_no)月"
#: accounting/views.py:821
msgid "Gas bill"
msgstr "瓦斯費"
#: accounting/views.py:822
msgid "Gas bill for (last_bimonthly_from_name)-(last_bimonthly_to_name)"
msgstr "瓦斯費(last_bimonthly_from_no)(last_bimonthly_to_no)月"
#: accounting/views.py:825
msgid "Phone bill"
msgstr "電話費"
#: accounting/views.py:826
msgid "Phone bill for (last_month_name)"
msgstr "電話費(last_month_no)月"
#: accounting/views.py:830
msgid "Payroll"
msgstr "薪水"
#: accounting/views.py:830
msgid "Payroll for (last_month_name)"
msgstr "(last_month_no)月份薪水"
#: accounting/views.py:958
msgid "This transaction was deleted successfully." msgid "This transaction was deleted successfully."
msgstr "會計傳票已刪除。" msgstr "會計傳票已刪除。"
#: accounting/views.py:926 #: accounting/views.py:974
msgid "The transaction orders were not modified." msgid "The transaction orders were not modified."
msgstr "會計傳票次序未異動。" msgstr "會計傳票次序未異動。"
#: accounting/views.py:928 #: accounting/views.py:976
msgid "The transaction orders were saved successfully." msgid "The transaction orders were saved successfully."
msgstr "會計傳票次序已儲存。" msgstr "會計傳票次序已儲存。"
#: accounting/views.py:987 #: accounting/views.py:1035
msgid "This account was not modified." msgid "This account was not modified."
msgstr "會計科目未異動。" msgstr "會計科目未異動。"
#: accounting/views.py:988 #: accounting/views.py:1036
msgid "This account was saved successfully." msgid "This account was saved successfully."
msgstr "會計科目已存檔。" msgstr "會計科目已存檔。"
#: accounting/views.py:1032 #: accounting/views.py:1080
msgid "This account was deleted successfully." msgid "This account was deleted successfully."
msgstr "會計科目已刪除。" msgstr "會計科目已刪除。"
#: accounting/views.py:1073 #: accounting/views.py:1121
msgid "---Accounts In Use---" msgid "---Accounts In Use---"
msgstr "-----使用中科目-----" msgstr "-----使用中科目-----"
#: accounting/views.py:1078 #: accounting/views.py:1126
msgid "---Accounts Not In Use---" msgid "---Accounts Not In Use---"
msgstr "-----未使用科目-----" msgstr "-----未使用科目-----"

View File

@ -7,8 +7,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: mia-accounting-js 3.0\n" "Project-Id-Version: mia-accounting-js 3.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-08-09 21:54+0800\n" "POT-Creation-Date: 2020-08-31 09:42+0800\n"
"PO-Revision-Date: 2020-08-11 10:14+0800\n" "PO-Revision-Date: 2020-08-31 09:58+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"
@ -53,6 +53,54 @@ msgstr "子科目的代碼會太長最長5位數字。"
msgid "Please fill in the title." msgid "Please fill in the title."
msgstr "請填寫標題。" msgstr "請填寫標題。"
#: accounting/static/accounting/js/summary-helper.js:254
msgid "January"
msgstr "一月"
#: accounting/static/accounting/js/summary-helper.js:255
msgid "February"
msgstr "二月"
#: accounting/static/accounting/js/summary-helper.js:256
msgid "March"
msgstr "三月"
#: accounting/static/accounting/js/summary-helper.js:257
msgid "April"
msgstr "四月"
#: accounting/static/accounting/js/summary-helper.js:258
msgid "May"
msgstr "五月"
#: accounting/static/accounting/js/summary-helper.js:259
msgid "June"
msgstr "六月"
#: accounting/static/accounting/js/summary-helper.js:260
msgid "July"
msgstr "七月"
#: accounting/static/accounting/js/summary-helper.js:261
msgid "August"
msgstr "八月"
#: accounting/static/accounting/js/summary-helper.js:262
msgid "September"
msgstr "九月"
#: accounting/static/accounting/js/summary-helper.js:263
msgid "October"
msgstr "十月"
#: accounting/static/accounting/js/summary-helper.js:264
msgid "November"
msgstr "十一月"
#: accounting/static/accounting/js/summary-helper.js:265
msgid "December"
msgstr "十二月"
#: accounting/static/accounting/js/transaction-form.js:376 #: accounting/static/accounting/js/transaction-form.js:376
msgid "Please fill in the date." msgid "Please fill in the date."
msgstr "請填寫日期。" msgstr "請填寫日期。"

View File

@ -178,27 +178,8 @@ function loadKnownSummaryCategories(type) {
}); });
}); });
// The regular payments // The regular accounts
const regularPayments = getRegularPayments(); loadRegularAccounts(type);
["debit", "credit"].forEach(function (type) {
summaryCategories[type].regular = [];
summaryAccounts[type].regular = {};
regularPayments[type].forEach(function (item) {
summaryCategories[type].regular.push(item);
summaryAccounts[type].regular[item.title] = item.account;
});
});
const regularPaymentButtons = $("#summary-regular-payments");
regularPaymentButtons.html("");
summaryCategories[type].regular.forEach(function (item) {
regularPaymentButtons.append(
$("<span/>")
.attr("title", item.summary)
.addClass("btn btn-outline-primary")
.addClass("btn-summary-helper")
.addClass("btn-summary-regular")
.text(item.title));
});
$(".btn-summary-general-category") $(".btn-summary-general-category")
.on("click", function () { .on("click", function () {
@ -221,14 +202,89 @@ function loadKnownSummaryCategories(type) {
setBusSummary(); setBusSummary();
setSummaryAccount("bus", this.innerText); setSummaryAccount("bus", this.innerText);
}); });
}
/**
* Loads the regular accounts.
*
* @param {string} type the record type
* @private
*/
function loadRegularAccounts(type) {
const regularAccounts = JSON.parse(document.getElementById("regular-accounts").value);
setRegularAccountSummary(regularAccounts);
Object.keys(regularAccounts).forEach(function (type) {
summaryCategories[type].regular = [];
summaryAccounts[type].regular = {};
regularAccounts[type].forEach(function (item) {
summaryCategories[type].regular.push(item);
summaryAccounts[type].regular[item.title] = item.account;
});
console.log(summaryAccounts[type].regular);
});
const regularAccountButtons = $("#summary-regular-accounts");
regularAccountButtons.html("");
summaryCategories[type].regular.forEach(function (item) {
regularAccountButtons.append(
$("<span/>")
.attr("title", item.summary)
.addClass("btn btn-outline-primary")
.addClass("btn-summary-helper")
.addClass("btn-summary-regular")
.text(item.title));
});
$(".btn-summary-regular") $(".btn-summary-regular")
.on("click", function () { .on("click", function () {
$("#summary-summary").get(0).value = this.title; $("#summary-summary").get(0).value = this.title;
setSummaryRegularPaymentButtons(this.innerText); setSummaryRegularAccountButtons(this.innerText);
setSummaryAccount("regular", this.innerText); setSummaryAccount("regular", this.innerText);
}); });
} }
/**
* Sets the summary of the regular accounts according to the date
*
* @param {{}} regularAccounts the regular account data
* @private
*/
function setRegularAccountSummary(regularAccounts)
{
const monthNames = [
"",
gettext("January"),
gettext("February"),
gettext("March"),
gettext("April"),
gettext("May"),
gettext("June"),
gettext("July"),
gettext("August"),
gettext("September"),
gettext("October"),
gettext("November"),
gettext("December"),
];
const today = new Date($("#txn-date").get(0).value);
const thisMonth = today.getMonth() + 1;
const lastMonth = (thisMonth + 10) % 12 + 1;
const lastBimonthlyFrom = ((thisMonth + thisMonth % 2 + 8) % 12 + 1);
const lastBimonthlyTo = ((thisMonth + thisMonth % 2 + 9) % 12 + 1);
Object.keys(regularAccounts).forEach(function (type) {
regularAccounts[type].forEach(function (item) {
item.summary = item.format
.replaceAll("(month_no)", String(thisMonth))
.replaceAll("(month_name)", monthNames[thisMonth])
.replaceAll("(last_month_no)", String(lastMonth))
.replaceAll("(last_month_name)", monthNames[lastMonth])
.replaceAll("(last_bimonthly_from_no)", String(lastBimonthlyFrom))
.replaceAll("(last_bimonthly_from_name)", monthNames[lastBimonthlyFrom])
.replaceAll("(last_bimonthly_to_no)", String(lastBimonthlyTo))
.replaceAll("(last_bimonthly_to_name)", monthNames[lastBimonthlyTo]);
});
});
}
/** /**
* Parses the summary and sets up the summary helper. * Parses the summary and sets up the summary helper.
* *
@ -459,11 +515,11 @@ function setBusSummary() {
} }
/** /**
* Sets the regular payment buttons. * Sets the regular account buttons.
* *
* @param {string} category the regular payment * @param {string} category the regular account
*/ */
function setSummaryRegularPaymentButtons(category) { function setSummaryRegularAccountButtons(category) {
$(".btn-summary-regular").each(function () { $(".btn-summary-regular").each(function () {
if (this.innerText === category) { if (this.innerText === category) {
this.classList.remove("btn-outline-primary"); this.classList.remove("btn-outline-primary");

View File

@ -134,11 +134,11 @@ First written: 2020/4/3
</div> </div>
</div> </div>
<!-- Regular payments --> <!-- Regular accounts -->
<div id="summary-tab-content-regular" class="summary-tab-content d-none"> <div id="summary-tab-content-regular" class="summary-tab-content d-none">
<div class="row"> <div class="row">
<div class="col-sm-12"> <div class="col-sm-12">
<div id="summary-regular-payments" class="summary-categories-known"></div> <div id="summary-regular-accounts" class="summary-categories-known"></div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -32,7 +32,6 @@ First written: 2020/7/23
{% static "accounting/css/transactions.css" as file %}{% add_css file %} {% static "accounting/css/transactions.css" as file %}{% add_css file %}
{% static "accounting/css/summary-helper.css" as file %}{% add_css file %} {% static "accounting/css/summary-helper.css" as file %}{% add_css file %}
{% static "accounting/js/transaction-form.js" as file %}{% add_js file %} {% static "accounting/js/transaction-form.js" as file %}{% add_js file %}
{% static "js/regular-payments.js" as file %}{% add_js file %}
{% static "accounting/js/summary-helper.js" as file %}{% add_js file %} {% static "accounting/js/summary-helper.js" as file %}{% add_js file %}
{% endblock %} {% endblock %}
@ -56,6 +55,7 @@ First written: 2020/7/23
<input id="account-option-url" type="hidden" value="{% url "accounting:api.accounts.options" %}" /> <input id="account-option-url" type="hidden" value="{% url "accounting:api.accounts.options" %}" />
<input id="summary-categories" type="hidden" value="{{ summary_categories }}" /> <input id="summary-categories" type="hidden" value="{{ summary_categories }}" />
<input id="regular-accounts" type="hidden" value="{{ regular_accounts }}" />
<input id="new-record-template" type="hidden" value="{{ new_record_template }}" /> <input id="new-record-template" type="hidden" value="{{ new_record_template }}" />
<form id="txn-form" action="{% if form.transaction %}{% url "accounting:transactions.update" "expense" form.transaction as url %}{% url_keep_return url %}{% else %}{% url "accounting:transactions.create" "expense" as url %}{% url_keep_return url %}{% endif %}" method="post"> <form id="txn-form" action="{% if form.transaction %}{% url "accounting:transactions.update" "expense" form.transaction as url %}{% url_keep_return url %}{% else %}{% url "accounting:transactions.create" "expense" as url %}{% url_keep_return url %}{% endif %}" method="post">
{% csrf_token %} {% csrf_token %}

View File

@ -32,7 +32,6 @@ First written: 2020/7/23
{% static "accounting/css/transactions.css" as file %}{% add_css file %} {% static "accounting/css/transactions.css" as file %}{% add_css file %}
{% static "accounting/css/summary-helper.css" as file %}{% add_css file %} {% static "accounting/css/summary-helper.css" as file %}{% add_css file %}
{% static "accounting/js/transaction-form.js" as file %}{% add_js file %} {% static "accounting/js/transaction-form.js" as file %}{% add_js file %}
{% static "js/regular-payments.js" as file %}{% add_js file %}
{% static "accounting/js/summary-helper.js" as file %}{% add_js file %} {% static "accounting/js/summary-helper.js" as file %}{% add_js file %}
{% endblock %} {% endblock %}
@ -56,6 +55,7 @@ First written: 2020/7/23
<input id="account-option-url" type="hidden" value="{% url "accounting:api.accounts.options" %}" /> <input id="account-option-url" type="hidden" value="{% url "accounting:api.accounts.options" %}" />
<input id="summary-categories" type="hidden" value="{{ summary_categories }}" /> <input id="summary-categories" type="hidden" value="{{ summary_categories }}" />
<input id="regular-accounts" type="hidden" value="{{ regular_accounts }}" />
<input id="new-record-template" type="hidden" value="{{ new_record_template }}" /> <input id="new-record-template" type="hidden" value="{{ new_record_template }}" />
<form id="txn-form" action="{% if form.transaction %}{% url "accounting:transactions.update" "income" form.transaction as url %}{% url_keep_return url %}{% else %}{% url "accounting:transactions.create" "income" as url %}{% url_keep_return url %}{% endif %}" method="post"> <form id="txn-form" action="{% if form.transaction %}{% url "accounting:transactions.update" "income" form.transaction as url %}{% url_keep_return url %}{% else %}{% url "accounting:transactions.create" "income" as url %}{% url_keep_return url %}{% endif %}" method="post">
{% csrf_token %} {% csrf_token %}

View File

@ -32,7 +32,6 @@ First written: 2020/7/23
{% static "accounting/css/transactions.css" as file %}{% add_css file %} {% static "accounting/css/transactions.css" as file %}{% add_css file %}
{% static "accounting/css/summary-helper.css" as file %}{% add_css file %} {% static "accounting/css/summary-helper.css" as file %}{% add_css file %}
{% static "accounting/js/transaction-form.js" as file %}{% add_js file %} {% static "accounting/js/transaction-form.js" as file %}{% add_js file %}
{% static "js/regular-payments.js" as file %}{% add_js file %}
{% static "accounting/js/summary-helper.js" as file %}{% add_js file %} {% static "accounting/js/summary-helper.js" as file %}{% add_js file %}
{% endblock %} {% endblock %}
@ -56,6 +55,7 @@ First written: 2020/7/23
<input id="account-option-url" type="hidden" value="{% url "accounting:api.accounts.options" %}" /> <input id="account-option-url" type="hidden" value="{% url "accounting:api.accounts.options" %}" />
<input id="summary-categories" type="hidden" value="{{ summary_categories }}" /> <input id="summary-categories" type="hidden" value="{{ summary_categories }}" />
<input id="regular-accounts" type="hidden" value="{{ regular_accounts }}" />
<input id="new-record-template" type="hidden" value="{{ new_record_template }}" /> <input id="new-record-template" type="hidden" value="{{ new_record_template }}" />
<form id="txn-form" action="{% if form.transaction %}{% url "accounting:transactions.update" "transfer" form.transaction as url %}{% url_keep_return url %}{% else %}{% url "accounting:transactions.create" "transfer" as url %}{% url_keep_return url %}{% endif %}" method="post"> <form id="txn-form" action="{% if form.transaction %}{% url "accounting:transactions.update" "transfer" form.transaction as url %}{% url_keep_return url %}{% else %}{% url "accounting:transactions.create" "transfer" as url %}{% url_keep_return url %}{% endif %}" method="post">
{% csrf_token %} {% csrf_token %}

View File

@ -20,8 +20,9 @@
""" """
import json import json
import re import re
from typing import Dict, Optional from typing import Dict, Optional, List, Tuple
from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.db import transaction from django.db import transaction
from django.db.models import Sum, Case, When, F, Q, Count, BooleanField, \ from django.db.models import Sum, Case, When, F, Q, Count, BooleanField, \
@ -34,7 +35,7 @@ from django.template.loader import render_to_string
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.translation import gettext as _, gettext_noop from django.utils.translation import gettext as _, gettext_noop, gettext
from django.views.decorators.http import require_GET, require_POST from django.views.decorators.http import require_GET, require_POST
from django.views.generic import ListView, DetailView from django.views.generic import ListView, DetailView
@ -803,11 +804,42 @@ class TransactionFormView(FormView):
form_class = TransactionForm form_class = TransactionForm
not_modified_message = gettext_noop("This transaction was not modified.") not_modified_message = gettext_noop("This transaction was not modified.")
success_message = gettext_noop("This transaction was saved successfully.") success_message = gettext_noop("This transaction was saved successfully.")
DEFAULT_REGULAR_ACCOUNTS = {
"debit": [
(gettext_noop("Pension"),
gettext_noop("Pension for (last_month_name)"),
"1314"),
(gettext_noop("Health insurance"),
gettext_noop("Health insurance for (last_month_name)"),
"6262"),
(gettext_noop("Electricity bill"),
gettext_noop("Electricity bill for (last_bimonthly_from_name)"
"-(last_bimonthly_to_name)"),
"6261"),
(gettext_noop("Water bill"),
gettext_noop("Water bill for (last_bimonthly_from_name)"
"-(last_bimonthly_to_name)"),
"6261"),
(gettext_noop("Gas bill"),
gettext_noop("Gas bill for (last_bimonthly_from_name)"
"-(last_bimonthly_to_name)"),
"6261"),
(gettext_noop("Phone bill"),
gettext_noop("Phone bill for (last_month_name)"),
"6261"),
],
"credit": [
(gettext_noop("Payroll"),
gettext_noop("Payroll for (last_month_name)"),
"4611"),
],
}
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
"""Returns the context data for the template.""" """Returns the context data for the template."""
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context["summary_categories"] = self._get_summary_categories() context["summary_categories"] = self._get_summary_categories()
context["regular_accounts"] = self._get_regular_accounts()
context["new_record_template"] = self._get_new_record_template_json() context["new_record_template"] = self._get_new_record_template_json()
return context return context
@ -864,6 +896,28 @@ class TransactionFormView(FormView):
# US-ASCII # US-ASCII
return json.dumps(categories) return json.dumps(categories)
@staticmethod
def _get_regular_accounts() -> str:
"""Returns the regular account data, as JSON.
Returns:
Two lists of the (title, format pattern, account code) tuple, sorted by
debit or credit.
"""
try:
regular = settings.REGULAR_ACCOUNTS
regular = {t: [{"title": x[0],
"format": x[1],
"account": x[2]} for x in regular[t]]
for t in regular}
except AttributeError:
regular = TransactionFormView.DEFAULT_REGULAR_ACCOUNTS
regular = {t: [{"title": gettext(x[0]),
"format": gettext(x[1]),
"account": x[2]} for x in regular[t]]
for t in regular}
return json.dumps(regular)
def _get_new_record_template_json(self) -> str: def _get_new_record_template_json(self) -> str:
context = {"record_type": "TTT", "no": "NNN"} context = {"record_type": "TTT", "no": "NNN"}
template_name = "accounting/include/record_form-transfer.html"\ template_name = "accounting/include/record_form-transfer.html"\