django-ledger 0.5.6.4__py3-none-any.whl → 0.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of django-ledger might be problematic. Click here for more details.
- django_ledger/__init__.py +1 -1
- django_ledger/admin/entity.py +14 -0
- django_ledger/forms/account.py +13 -4
- django_ledger/io/io_core.py +20 -16
- django_ledger/io/io_digest.py +1 -1
- django_ledger/io/io_middleware.py +2 -4
- django_ledger/models/accounts.py +11 -1
- django_ledger/models/closing_entry.py +4 -4
- django_ledger/models/coa.py +269 -90
- django_ledger/models/entity.py +21 -2
- django_ledger/models/mixins.py +1 -1
- django_ledger/models/transactions.py +209 -111
- django_ledger/models/utils.py +117 -116
- django_ledger/templates/django_ledger/account/account_list.html +2 -2
- django_ledger/templates/django_ledger/account/account_update.html +18 -16
- django_ledger/urls/chart_of_accounts.py +3 -3
- django_ledger/views/account.py +36 -10
- django_ledger/views/coa.py +8 -9
- django_ledger/views/mixins.py +10 -8
- {django_ledger-0.5.6.4.dist-info → django_ledger-0.6.0.dist-info}/METADATA +81 -131
- {django_ledger-0.5.6.4.dist-info → django_ledger-0.6.0.dist-info}/RECORD +25 -26
- django_ledger/static/django_ledger/bundle/djetler.bundle.js.LICENSE.txt +0 -28
- {django_ledger-0.5.6.4.dist-info → django_ledger-0.6.0.dist-info}/AUTHORS.md +0 -0
- {django_ledger-0.5.6.4.dist-info → django_ledger-0.6.0.dist-info}/LICENSE +0 -0
- {django_ledger-0.5.6.4.dist-info → django_ledger-0.6.0.dist-info}/WHEEL +0 -0
- {django_ledger-0.5.6.4.dist-info → django_ledger-0.6.0.dist-info}/top_level.txt +0 -0
django_ledger/models/utils.py
CHANGED
|
@@ -6,152 +6,165 @@ Contributions to this module:
|
|
|
6
6
|
* Miguel Sanda <msanda@arrobalytics.com>
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
+
from django.apps import apps
|
|
10
|
+
|
|
9
11
|
|
|
10
12
|
class LazyLoader:
|
|
11
13
|
"""
|
|
12
|
-
|
|
14
|
+
A class that provides lazy-loading functionality for various models in the django_ledger app.
|
|
15
|
+
|
|
16
|
+
Attributes:
|
|
17
|
+
app_config (AppConfig): The AppConfig object for the django_ledger app.
|
|
18
|
+
|
|
19
|
+
ENTITY_MODEL (str): The name of the entity model.
|
|
20
|
+
LEDGER_MODEL (str): The name of the ledger model.
|
|
21
|
+
JE_MODEL (str): The name of the journal entry model.
|
|
22
|
+
TRANSACTION_MODEL (str): The name of the transaction model.
|
|
23
|
+
ACCOUNT_MODEL (str): The name of the account model.
|
|
24
|
+
COA_MODEL (str): The name of the chart of account model.
|
|
25
|
+
|
|
26
|
+
ENTITY_STATE_MODEL (str): The name of the entity state model.
|
|
27
|
+
ENTITY_UNIT_MODEL (str): The name of the entity unit model.
|
|
28
|
+
CLOSING_ENTRY_MODEL (str): The name of the closing entry model.
|
|
29
|
+
CLOSING_ENTRY_TRANSACTION_MODEL (str): The name of the closing entry transaction model.
|
|
30
|
+
|
|
31
|
+
BANK_ACCOUNT_MODEL (str): The name of the bank account model.
|
|
32
|
+
PURCHASE_ORDER_MODEL (str): The name of the purchase order model.
|
|
33
|
+
|
|
34
|
+
CUSTOMER_MODEL (str): The name of the customer model.
|
|
35
|
+
INVOICE_MODEL (str): The name of the invoice model.
|
|
36
|
+
BILL_MODEL (str): The name of the bill model.
|
|
37
|
+
UOM_MODEL (str): The name of the unit of measure model.
|
|
38
|
+
VENDOR_MODEL (str): The name of the vendor model.
|
|
39
|
+
ESTIMATE_MODEL (str): The name of the estimate model.
|
|
40
|
+
ITEM_MODEL (str): The name of the item model.
|
|
41
|
+
ITEM_TRANSACTION_MODEL (str): The name of the item transaction model.
|
|
42
|
+
|
|
43
|
+
ENTITY_DATA_GENERATOR (EntityDataGenerator): The EntityDataGenerator class used for generating entity data.
|
|
44
|
+
BALANCE_SHEET_REPORT_CLASS (BalanceSheetReport): The BalanceSheetReport class used for generating balance sheet reports.
|
|
45
|
+
INCOME_STATEMENT_REPORT_CLASS (IncomeStatementReport): The IncomeStatementReport class used for generating income statement reports.
|
|
46
|
+
CASH_FLOW_STATEMENT_REPORT_CLASS (CashFlowStatementReport): The CashFlowStatementReport class used for generating cash flow statement reports.
|
|
47
|
+
|
|
48
|
+
Methods:
|
|
49
|
+
get_entity_model() -> Model: Returns the entity model.
|
|
50
|
+
get_entity_unit_model() -> Model: Returns the entity unit model.
|
|
51
|
+
get_entity_state_model() -> Model: Returns the entity state model.
|
|
52
|
+
get_bank_account_model() -> Model: Returns the bank account model.
|
|
53
|
+
get_account_model() -> Model: Returns the account model.
|
|
54
|
+
get_coa_model() -> Model: Returns the chart of account model.
|
|
55
|
+
get_txs_model() -> Model: Returns the transaction model.
|
|
56
|
+
get_purchase_order_model() -> Model: Returns the purchase order model.
|
|
57
|
+
get_ledger_model() -> Model: Returns the ledger model.
|
|
58
|
+
get_journal_entry_model() -> Model: Returns the journal entry model.
|
|
59
|
+
get_item_model() -> Model: Returns the item model.
|
|
60
|
+
get_item_transaction_model() -> Model: Returns the item transaction model.
|
|
61
|
+
get_customer_model() -> Model: Returns the customer model.
|
|
62
|
+
get_bill_model() -> Model: Returns the bill model.
|
|
63
|
+
get_invoice_model() -> Model: Returns the invoice model.
|
|
64
|
+
get_uom_model() -> Model: Returns the unit of measure model.
|
|
65
|
+
get_vendor_model() -> Model: Returns the vendor model.
|
|
66
|
+
get_estimate_model() -> Model: Returns the estimate model.
|
|
67
|
+
get_closing_entry_model() -> Model: Returns the closing entry model.
|
|
68
|
+
get_closing_entry_transaction_model() -> Model: Returns the closing entry transaction model.
|
|
69
|
+
get_entity_data_generator() -> EntityDataGenerator: Returns the EntityDataGenerator class.
|
|
70
|
+
get_balance_sheet_report_class() -> BalanceSheetReport: Returns the BalanceSheetReport class.
|
|
71
|
+
get_income_statement_report_class() -> IncomeStatementReport: Returns the IncomeStatementReport class.
|
|
72
|
+
get_cash_flow_statement_report_class() -> CashFlowStatementReport: Returns the CashFlowStatementReport class.
|
|
13
73
|
"""
|
|
14
|
-
ENTITY_MODEL = None
|
|
15
|
-
ENTITY_STATE_MODEL = None
|
|
16
|
-
UNIT_MODEL = None
|
|
17
|
-
ACCOUNT_MODEL = None
|
|
18
|
-
BANK_ACCOUNT_MODEL = None
|
|
19
|
-
LEDGER_MODEL = None
|
|
20
|
-
TXS_MODEL = None
|
|
21
|
-
JE_MODEL = None
|
|
22
|
-
ITEM_MODEL = None
|
|
23
|
-
ITEM_TRANSACTION_MODEL = None
|
|
24
|
-
CUSTOMER_MODEL = None
|
|
25
|
-
INVOICE_MODEL = None
|
|
26
|
-
BILL_MODEL = None
|
|
27
|
-
UOM_MODEL = None
|
|
28
|
-
VENDOR_MODEL = None
|
|
29
|
-
TRANSACTION_MODEL = None
|
|
30
|
-
ENTITY_UNIT_MODEL = None
|
|
31
|
-
PURCHASE_ORDER_MODEL = None
|
|
32
|
-
ESTIMATE_MODEL = None
|
|
33
|
-
CLOSING_ENTRY_MODEL = None
|
|
34
|
-
CLOSING_ENTRY_TRANSACTION_MODEL = None
|
|
35
74
|
|
|
36
|
-
|
|
75
|
+
app_config = apps.get_app_config(app_label='django_ledger')
|
|
76
|
+
|
|
77
|
+
ENTITY_MODEL = 'entitymodel'
|
|
78
|
+
LEDGER_MODEL = 'ledgermodel'
|
|
79
|
+
JE_MODEL = 'journalentrymodel'
|
|
80
|
+
TRANSACTION_MODEL = 'transactionmodel'
|
|
81
|
+
ACCOUNT_MODEL = 'accountmodel'
|
|
82
|
+
COA_MODEL = 'chartofaccountmodel'
|
|
83
|
+
|
|
84
|
+
ENTITY_STATE_MODEL = 'entitystatemodel'
|
|
85
|
+
ENTITY_UNIT_MODEL = 'entityunitmodel'
|
|
86
|
+
CLOSING_ENTRY_MODEL = 'closingentrymodel'
|
|
87
|
+
CLOSING_ENTRY_TRANSACTION_MODEL = 'closingentrytransactionmodel'
|
|
88
|
+
|
|
89
|
+
BANK_ACCOUNT_MODEL = 'bankaccountmodel'
|
|
90
|
+
PURCHASE_ORDER_MODEL = 'purchaseordermodel'
|
|
91
|
+
|
|
92
|
+
CUSTOMER_MODEL = 'customermodel'
|
|
93
|
+
INVOICE_MODEL = 'invoicemodel'
|
|
94
|
+
BILL_MODEL = 'billmodel'
|
|
95
|
+
UOM_MODEL = 'unitofmeasuremodel'
|
|
96
|
+
VENDOR_MODEL = 'vendormodel'
|
|
97
|
+
ESTIMATE_MODEL = 'estimatemodel'
|
|
98
|
+
ITEM_MODEL = 'itemmodel'
|
|
99
|
+
ITEM_TRANSACTION_MODEL = 'itemtransactionmodel'
|
|
37
100
|
|
|
101
|
+
ENTITY_DATA_GENERATOR = None
|
|
38
102
|
BALANCE_SHEET_REPORT_CLASS = None
|
|
39
103
|
INCOME_STATEMENT_REPORT_CLASS = None
|
|
40
104
|
CASH_FLOW_STATEMENT_REPORT_CLASS = None
|
|
41
105
|
|
|
106
|
+
|
|
107
|
+
|
|
42
108
|
def get_entity_model(self):
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return self.
|
|
109
|
+
return self.app_config.get_model(self.ENTITY_MODEL)
|
|
110
|
+
|
|
111
|
+
def get_entity_unit_model(self):
|
|
112
|
+
return self.app_config.get_model(self.ENTITY_UNIT_MODEL)
|
|
47
113
|
|
|
48
114
|
def get_entity_state_model(self):
|
|
49
|
-
|
|
50
|
-
from django_ledger.models import EntityStateModel
|
|
51
|
-
self.ENTITY_STATE_MODEL = EntityStateModel
|
|
52
|
-
return self.ENTITY_STATE_MODEL
|
|
115
|
+
return self.app_config.get_model(self.ENTITY_STATE_MODEL)
|
|
53
116
|
|
|
54
117
|
def get_bank_account_model(self):
|
|
55
|
-
|
|
56
|
-
from django_ledger.models import BankAccountModel
|
|
57
|
-
self.BANK_ACCOUNT_MODEL = BankAccountModel
|
|
58
|
-
return self.BANK_ACCOUNT_MODEL
|
|
118
|
+
return self.app_config.get_model(self.BANK_ACCOUNT_MODEL)
|
|
59
119
|
|
|
60
120
|
def get_account_model(self):
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return self.
|
|
121
|
+
return self.app_config.get_model(self.ACCOUNT_MODEL)
|
|
122
|
+
|
|
123
|
+
def get_coa_model(self):
|
|
124
|
+
return self.app_config.get_model(self.COA_MODEL)
|
|
65
125
|
|
|
66
126
|
def get_txs_model(self):
|
|
67
|
-
|
|
68
|
-
from django_ledger.models import TransactionModel
|
|
69
|
-
self.TXS_MODEL = TransactionModel
|
|
70
|
-
return self.TXS_MODEL
|
|
127
|
+
return self.app_config.get_model(self.TRANSACTION_MODEL)
|
|
71
128
|
|
|
72
129
|
def get_purchase_order_model(self):
|
|
73
|
-
|
|
74
|
-
from django_ledger.models import PurchaseOrderModel
|
|
75
|
-
self.PURCHASE_ORDER_MODEL = PurchaseOrderModel
|
|
76
|
-
return self.PURCHASE_ORDER_MODEL
|
|
130
|
+
return self.app_config.get_model(self.PURCHASE_ORDER_MODEL)
|
|
77
131
|
|
|
78
132
|
def get_ledger_model(self):
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
self.LEDGER_MODEL = LedgerModel
|
|
82
|
-
return self.LEDGER_MODEL
|
|
83
|
-
|
|
84
|
-
def get_unit_model(self):
|
|
85
|
-
if not self.UNIT_MODEL:
|
|
86
|
-
from django_ledger.models import EntityUnitModel
|
|
87
|
-
self.UNIT_MODEL = EntityUnitModel
|
|
88
|
-
return self.UNIT_MODEL
|
|
133
|
+
self.get_entity_unit_model()
|
|
134
|
+
return self.app_config.get_model(self.LEDGER_MODEL)
|
|
89
135
|
|
|
90
136
|
def get_journal_entry_model(self):
|
|
91
|
-
|
|
92
|
-
from django_ledger.models import JournalEntryModel
|
|
93
|
-
self.JE_MODEL = JournalEntryModel
|
|
94
|
-
return self.JE_MODEL
|
|
137
|
+
return self.app_config.get_model(self.JE_MODEL)
|
|
95
138
|
|
|
96
139
|
def get_item_model(self):
|
|
97
|
-
|
|
98
|
-
from django_ledger.models import ItemModel
|
|
99
|
-
self.ITEM_MODEL = ItemModel
|
|
100
|
-
return self.ITEM_MODEL
|
|
140
|
+
return self.app_config.get_model(self.ITEM_MODEL)
|
|
101
141
|
|
|
102
142
|
def get_item_transaction_model(self):
|
|
103
|
-
|
|
104
|
-
from django_ledger.models import ItemTransactionModel
|
|
105
|
-
self.ITEM_TRANSACTION_MODEL = ItemTransactionModel
|
|
106
|
-
return self.ITEM_TRANSACTION_MODEL
|
|
143
|
+
return self.app_config.get_model(self.ITEM_TRANSACTION_MODEL)
|
|
107
144
|
|
|
108
145
|
def get_customer_model(self):
|
|
109
|
-
|
|
110
|
-
from django_ledger.models import CustomerModel
|
|
111
|
-
self.CUSTOMER_MODEL = CustomerModel
|
|
112
|
-
return self.CUSTOMER_MODEL
|
|
146
|
+
return self.app_config.get_model(self.CUSTOMER_MODEL)
|
|
113
147
|
|
|
114
148
|
def get_bill_model(self):
|
|
115
|
-
|
|
116
|
-
from django_ledger.models import BillModel
|
|
117
|
-
self.BILL_MODEL = BillModel
|
|
118
|
-
return self.BILL_MODEL
|
|
149
|
+
return self.app_config.get_model(self.BILL_MODEL)
|
|
119
150
|
|
|
120
151
|
def get_invoice_model(self):
|
|
121
|
-
|
|
122
|
-
from django_ledger.models import InvoiceModel
|
|
123
|
-
self.INVOICE_MODEL = InvoiceModel
|
|
124
|
-
return self.INVOICE_MODEL
|
|
152
|
+
return self.app_config.get_model(self.INVOICE_MODEL)
|
|
125
153
|
|
|
126
154
|
def get_uom_model(self):
|
|
127
|
-
|
|
128
|
-
from django_ledger.models import UnitOfMeasureModel
|
|
129
|
-
self.UOM_MODEL = UnitOfMeasureModel
|
|
130
|
-
return self.UOM_MODEL
|
|
155
|
+
return self.app_config.get_model(self.UOM_MODEL)
|
|
131
156
|
|
|
132
157
|
def get_vendor_model(self):
|
|
133
|
-
|
|
134
|
-
from django_ledger.models import VendorModel
|
|
135
|
-
self.VENDOR_MODEL = VendorModel
|
|
136
|
-
return self.VENDOR_MODEL
|
|
158
|
+
return self.app_config.get_model(self.VENDOR_MODEL)
|
|
137
159
|
|
|
138
|
-
def
|
|
139
|
-
|
|
140
|
-
from django_ledger.models import TransactionModel
|
|
141
|
-
self.TRANSACTION_MODEL = TransactionModel
|
|
142
|
-
return self.TRANSACTION_MODEL
|
|
160
|
+
def get_estimate_model(self):
|
|
161
|
+
return self.app_config.get_model(self.ESTIMATE_MODEL)
|
|
143
162
|
|
|
144
|
-
def
|
|
145
|
-
|
|
146
|
-
from django_ledger.models import EntityUnitModel
|
|
147
|
-
self.ENTITY_UNIT_MODEL = EntityUnitModel
|
|
148
|
-
return self.ENTITY_UNIT_MODEL
|
|
163
|
+
def get_closing_entry_model(self):
|
|
164
|
+
return self.app_config.get_model(self.CLOSING_ENTRY_MODEL)
|
|
149
165
|
|
|
150
|
-
def
|
|
151
|
-
|
|
152
|
-
from django_ledger.models import EstimateModel
|
|
153
|
-
self.ESTIMATE_MODEL = EstimateModel
|
|
154
|
-
return self.ESTIMATE_MODEL
|
|
166
|
+
def get_closing_entry_transaction_model(self):
|
|
167
|
+
return self.app_config.get_model(self.CLOSING_ENTRY_TRANSACTION_MODEL)
|
|
155
168
|
|
|
156
169
|
def get_entity_data_generator(self):
|
|
157
170
|
if not self.ENTITY_DATA_GENERATOR:
|
|
@@ -159,18 +172,6 @@ class LazyLoader:
|
|
|
159
172
|
self.ENTITY_DATA_GENERATOR = EntityDataGenerator
|
|
160
173
|
return self.ENTITY_DATA_GENERATOR
|
|
161
174
|
|
|
162
|
-
def get_closing_entry_model(self):
|
|
163
|
-
if not self.CLOSING_ENTRY_MODEL:
|
|
164
|
-
from django_ledger.models import ClosingEntryModel
|
|
165
|
-
self.CLOSING_ENTRY_MODEL = ClosingEntryModel
|
|
166
|
-
return self.CLOSING_ENTRY_MODEL
|
|
167
|
-
|
|
168
|
-
def get_closing_entry_transaction_model(self):
|
|
169
|
-
if not self.CLOSING_ENTRY_TRANSACTION_MODEL:
|
|
170
|
-
from django_ledger.models import ClosingEntryTransactionModel
|
|
171
|
-
self.CLOSING_ENTRY_TRANSACTION_MODEL = ClosingEntryTransactionModel
|
|
172
|
-
return self.CLOSING_ENTRY_TRANSACTION_MODEL
|
|
173
|
-
|
|
174
175
|
def get_balance_sheet_report_class(self):
|
|
175
176
|
if not self.BALANCE_SHEET_REPORT_CLASS:
|
|
176
177
|
from django_ledger.report.balance_sheet import BalanceSheetReport
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
{% accounts_table accounts %}
|
|
16
16
|
</div>
|
|
17
17
|
<div class="column is-12 has-text-centered">
|
|
18
|
-
<a href="{
|
|
18
|
+
<a href="{{ coa_model.get_create_coa_account_url }}"
|
|
19
19
|
class="button is-success">{% trans 'Create Account' %}</a>
|
|
20
|
-
<a href="{
|
|
20
|
+
<a href="{{ coa_model.get_coa_list_url }}"
|
|
21
21
|
class="button is-dark">{% trans 'Back to CoA List' %}</a>
|
|
22
22
|
</div>
|
|
23
23
|
</div>
|
|
@@ -4,22 +4,24 @@
|
|
|
4
4
|
{% load django_ledger %}
|
|
5
5
|
|
|
6
6
|
{% block view_content %}
|
|
7
|
-
<div class="
|
|
8
|
-
<div class="
|
|
9
|
-
<div class="
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
<div class="box">
|
|
8
|
+
<div class="columns is-centered is-multiline">
|
|
9
|
+
<div class="column is-12 has-text-centered">
|
|
10
|
+
<h2 class="is-size-3 has-text-info">{{ coa_model.name }}</h2>
|
|
11
|
+
<p class="is-size-4 has-text-danger is-italic">({{ coa_model.slug }})</p>
|
|
12
|
+
<h1 class="is-size-2">{{ account }}</h1>
|
|
13
|
+
</div>
|
|
14
|
+
<div class="column is-8-tablet is-6-desktop">
|
|
15
|
+
<div class="box">
|
|
16
|
+
<form method="post">
|
|
17
|
+
{% csrf_token %}
|
|
18
|
+
{{ form.as_p }}
|
|
19
|
+
<button type="submit" class="button is-primary is-fullwidth djetler_my_1">Submit</button>
|
|
20
|
+
<a class="button is-dark is-small is-fullwidth"
|
|
21
|
+
href="{% url 'django_ledger:account-list' entity_slug=view.kwargs.entity_slug %}">Back</a>
|
|
22
|
+
</form>
|
|
23
|
+
</div>
|
|
19
24
|
</div>
|
|
20
25
|
</div>
|
|
21
26
|
</div>
|
|
22
|
-
{% endblock %}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
{% endblock %}
|
|
@@ -4,13 +4,13 @@ from django_ledger import views
|
|
|
4
4
|
|
|
5
5
|
urlpatterns = [
|
|
6
6
|
path('<slug:entity_slug>/list/',
|
|
7
|
-
views.
|
|
7
|
+
views.ChartOfAccountModelListView.as_view(),
|
|
8
8
|
name='coa-list'),
|
|
9
9
|
path('<slug:entity_slug>/detail/<slug:coa_slug>/',
|
|
10
|
-
views.
|
|
10
|
+
views.ChartOfAccountModelListView.as_view(),
|
|
11
11
|
name='coa-detail'),
|
|
12
12
|
path('<slug:entity_slug>/update/<slug:coa_slug>/',
|
|
13
|
-
views.
|
|
13
|
+
views.ChartOfAccountModelUpdateView.as_view(),
|
|
14
14
|
name='coa-update'),
|
|
15
15
|
|
|
16
16
|
# ACTIONS....
|
django_ledger/views/account.py
CHANGED
|
@@ -17,7 +17,7 @@ from django.views.generic.detail import SingleObjectMixin
|
|
|
17
17
|
|
|
18
18
|
from django_ledger.forms.account import AccountModelUpdateForm, AccountModelCreateForm
|
|
19
19
|
from django_ledger.io.io_core import get_localdate
|
|
20
|
-
from django_ledger.models import
|
|
20
|
+
from django_ledger.models import ChartOfAccountModel
|
|
21
21
|
from django_ledger.models.accounts import AccountModel
|
|
22
22
|
from django_ledger.views.mixins import (
|
|
23
23
|
YearlyReportMixIn, MonthlyReportMixIn, QuarterlyReportMixIn, DjangoLedgerSecurityMixIn,
|
|
@@ -27,6 +27,18 @@ from django_ledger.views.mixins import (
|
|
|
27
27
|
|
|
28
28
|
class BaseAccountModelViewQuerySetMixIn:
|
|
29
29
|
queryset = None
|
|
30
|
+
coa_model = None
|
|
31
|
+
|
|
32
|
+
def get_coa_model(self) -> ChartOfAccountModel:
|
|
33
|
+
if self.coa_model is None:
|
|
34
|
+
coa_slug = self.kwargs.get('coa_slug')
|
|
35
|
+
if coa_slug:
|
|
36
|
+
coa_model_qs = self.AUTHORIZED_ENTITY_MODEL.chartofaccountmodel_set.all().active()
|
|
37
|
+
coa_model = get_object_or_404(coa_model_qs, slug__exact=coa_slug)
|
|
38
|
+
else:
|
|
39
|
+
coa_model = self.AUTHORIZED_ENTITY_MODEL.default_coa
|
|
40
|
+
self.coa_model = coa_model
|
|
41
|
+
return self.coa_model
|
|
30
42
|
|
|
31
43
|
def get_queryset(self):
|
|
32
44
|
if self.queryset is None:
|
|
@@ -39,8 +51,15 @@ class BaseAccountModelViewQuerySetMixIn:
|
|
|
39
51
|
).order_by(
|
|
40
52
|
'coa_model', 'role', 'code').not_coa_root()
|
|
41
53
|
|
|
42
|
-
|
|
43
|
-
|
|
54
|
+
coa_slug = self.kwargs.get('coa_slug')
|
|
55
|
+
account_pk = self.kwargs.get('account_pk')
|
|
56
|
+
|
|
57
|
+
if coa_slug:
|
|
58
|
+
qs = qs.filter(coa_model__slug__exact=coa_slug)
|
|
59
|
+
elif account_pk:
|
|
60
|
+
qs = qs.filter(uuid__exact=account_pk)
|
|
61
|
+
else:
|
|
62
|
+
qs = qs.filter(coa_model__slug__exact=self.AUTHORIZED_ENTITY_MODEL.default_coa.slug)
|
|
44
63
|
|
|
45
64
|
self.queryset = qs
|
|
46
65
|
return super().get_queryset()
|
|
@@ -93,7 +112,8 @@ class AccountModelUpdateView(DjangoLedgerSecurityMixIn, BaseAccountModelViewQuer
|
|
|
93
112
|
# Set here because user_model is needed to instantiate an instance of MoveNodeForm (AccountModelUpdateForm)
|
|
94
113
|
account_model.USER_MODEL = self.request.user
|
|
95
114
|
return AccountModelUpdateForm(
|
|
96
|
-
|
|
115
|
+
entity_model=self.AUTHORIZED_ENTITY_MODEL,
|
|
116
|
+
coa_model=self.get_coa_model(),
|
|
97
117
|
user_model=self.request.user,
|
|
98
118
|
**self.get_form_kwargs()
|
|
99
119
|
)
|
|
@@ -119,7 +139,8 @@ class AccountModelCreateView(DjangoLedgerSecurityMixIn, BaseAccountModelViewQuer
|
|
|
119
139
|
def get_form(self, form_class=None):
|
|
120
140
|
return AccountModelCreateForm(
|
|
121
141
|
user_model=self.request.user,
|
|
122
|
-
|
|
142
|
+
entity_model=self.AUTHORIZED_ENTITY_MODEL,
|
|
143
|
+
coa_model=self.get_coa_model(),
|
|
123
144
|
**self.get_form_kwargs()
|
|
124
145
|
)
|
|
125
146
|
|
|
@@ -129,20 +150,25 @@ class AccountModelCreateView(DjangoLedgerSecurityMixIn, BaseAccountModelViewQuer
|
|
|
129
150
|
return context
|
|
130
151
|
|
|
131
152
|
def form_valid(self, form):
|
|
132
|
-
|
|
133
|
-
entity_model_qs = EntityModel.objects.for_user(user_model=self.request.user).select_related('default_coa')
|
|
134
|
-
entity_model: EntityModel = get_object_or_404(entity_model_qs, slug__exact=self.kwargs['entity_slug'])
|
|
153
|
+
entity_model = self.AUTHORIZED_ENTITY_MODEL
|
|
135
154
|
account_model: AccountModel = form.save(commit=False)
|
|
136
155
|
|
|
137
156
|
if not entity_model.has_default_coa():
|
|
138
157
|
entity_model.create_chart_of_accounts(assign_as_default=True, commit=True)
|
|
139
158
|
|
|
140
|
-
coa_model =
|
|
141
|
-
coa_model.
|
|
159
|
+
coa_model = self.get_coa_model()
|
|
160
|
+
coa_model.insert_account(account_model=account_model)
|
|
142
161
|
return HttpResponseRedirect(self.get_success_url())
|
|
143
162
|
|
|
144
163
|
def get_success_url(self):
|
|
145
164
|
entity_slug = self.kwargs.get('entity_slug')
|
|
165
|
+
coa_slug = self.kwargs.get('coa_slug')
|
|
166
|
+
if coa_slug:
|
|
167
|
+
return reverse('django_ledger:account-list-coa',
|
|
168
|
+
kwargs={
|
|
169
|
+
'entity_slug': entity_slug,
|
|
170
|
+
'coa_slug': coa_slug
|
|
171
|
+
})
|
|
146
172
|
return reverse('django_ledger:account-list',
|
|
147
173
|
kwargs={
|
|
148
174
|
'entity_slug': entity_slug,
|
django_ledger/views/coa.py
CHANGED
|
@@ -18,21 +18,21 @@ from django_ledger.models.coa import ChartOfAccountModel
|
|
|
18
18
|
from django_ledger.views.mixins import DjangoLedgerSecurityMixIn
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
class
|
|
21
|
+
class ChartOfAccountModelModelBaseViewMixIn(DjangoLedgerSecurityMixIn):
|
|
22
22
|
queryset = None
|
|
23
23
|
|
|
24
24
|
def get_queryset(self):
|
|
25
25
|
if self.queryset is None:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
).select_related('entity').order_by('-updated')
|
|
26
|
+
entity_model = self.get_authorized_entity_instance()
|
|
27
|
+
self.queryset = entity_model.chartofaccountmodel_set.all().select_related(
|
|
28
|
+
'entity').order_by('-updated')
|
|
30
29
|
return super().get_queryset()
|
|
31
30
|
|
|
32
31
|
|
|
33
|
-
class
|
|
32
|
+
class ChartOfAccountModelListView(ChartOfAccountModelModelBaseViewMixIn, ListView):
|
|
34
33
|
template_name = 'django_ledger/chart_of_accounts/coa_list.html'
|
|
35
34
|
extra_context = {
|
|
35
|
+
'page_title': _('Chart of Account List'),
|
|
36
36
|
'header_title': _('Chart of Account List'),
|
|
37
37
|
}
|
|
38
38
|
context_object_name = 'coa_list'
|
|
@@ -65,7 +65,7 @@ class ChartOfAccountsListView(DjangoLedgerSecurityMixIn, ChartOfAccountsModelMod
|
|
|
65
65
|
)
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
class
|
|
68
|
+
class ChartOfAccountModelUpdateView(ChartOfAccountModelModelBaseViewMixIn, UpdateView):
|
|
69
69
|
context_object_name = 'coa'
|
|
70
70
|
slug_url_kwarg = 'coa_slug'
|
|
71
71
|
template_name = 'django_ledger/chart_of_accounts/coa_update.html'
|
|
@@ -86,9 +86,8 @@ class ChartOfAccountsUpdateView(DjangoLedgerSecurityMixIn, ChartOfAccountsModelM
|
|
|
86
86
|
|
|
87
87
|
|
|
88
88
|
# todo: centralize this functionality into a separate class for ALL Action views...
|
|
89
|
-
class CharOfAccountModelActionView(
|
|
89
|
+
class CharOfAccountModelActionView(ChartOfAccountModelModelBaseViewMixIn,
|
|
90
90
|
RedirectView,
|
|
91
|
-
ChartOfAccountsModelModelViewQuerySetMixIn,
|
|
92
91
|
SingleObjectMixin):
|
|
93
92
|
http_method_names = ['get']
|
|
94
93
|
slug_url_kwarg = 'coa_slug'
|
django_ledger/views/mixins.py
CHANGED
|
@@ -299,14 +299,6 @@ class DjangoLedgerSecurityMixIn(PermissionRequiredMixin):
|
|
|
299
299
|
def get_login_url(self):
|
|
300
300
|
return reverse('django_ledger:login')
|
|
301
301
|
|
|
302
|
-
def get_authorized_entity_queryset(self):
|
|
303
|
-
return EntityModel.objects.for_user(
|
|
304
|
-
user_model=self.request.user).only(
|
|
305
|
-
'uuid', 'slug', 'name', 'default_coa', 'admin')
|
|
306
|
-
|
|
307
|
-
def get_authorized_entity_instance(self) -> Optional[EntityModel]:
|
|
308
|
-
return self.AUTHORIZED_ENTITY_MODEL
|
|
309
|
-
|
|
310
302
|
def has_permission(self):
|
|
311
303
|
if self.request.user.is_superuser:
|
|
312
304
|
if 'entity_slug' in self.kwargs:
|
|
@@ -329,6 +321,16 @@ class DjangoLedgerSecurityMixIn(PermissionRequiredMixin):
|
|
|
329
321
|
return True
|
|
330
322
|
return False
|
|
331
323
|
|
|
324
|
+
def get_authorized_entity_queryset(self):
|
|
325
|
+
return EntityModel.objects.for_user(
|
|
326
|
+
user_model=self.request.user).only(
|
|
327
|
+
'uuid', 'slug', 'name', 'default_coa', 'admin')
|
|
328
|
+
|
|
329
|
+
def get_authorized_entity_instance(self) -> Optional[EntityModel]:
|
|
330
|
+
if self.AUTHORIZED_ENTITY_MODEL is None:
|
|
331
|
+
raise Http404()
|
|
332
|
+
return self.AUTHORIZED_ENTITY_MODEL
|
|
333
|
+
|
|
332
334
|
|
|
333
335
|
class EntityUnitMixIn:
|
|
334
336
|
UNIT_SLUG_KWARG = 'unit_slug'
|