views.py 5.77 KB
Newer Older
Skia's avatar
Skia committed
1
2
from django.views.generic import ListView, DetailView, RedirectView
from django.views.generic.edit import UpdateView, CreateView, DeleteView
Skia's avatar
Skia committed
3
from django.shortcuts import render
Skia's avatar
Skia committed
4
from django.core.urlresolvers import reverse_lazy
5
6
from django.forms.models import modelform_factory
from django.forms import HiddenInput
Skia's avatar
Skia committed
7

8
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
Skia's avatar
Skia committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from accounting.models import BankAccount, ClubAccount, GeneralJournal, Operation, AccountingType

# Accounting types

class AccountingTypeListView(CanViewMixin, ListView):
    """
    A list view for the admins
    """
    model = AccountingType
    template_name = 'accounting/accountingtype_list.jinja'

class AccountingTypeEditView(CanViewMixin, UpdateView):
    """
    An edit view for the admins
    """
    model = AccountingType
    pk_url_kwarg = "type_id"
    fields = ['code', 'label', 'movement_type']
Skia's avatar
Skia committed
27
    template_name = 'core/edit.jinja'
Skia's avatar
Skia committed
28

29
class AccountingTypeCreateView(CanCreateMixin, CreateView):
Skia's avatar
Skia committed
30
31
32
33
34
    """
    Create an accounting type (for the admins)
    """
    model = AccountingType
    fields = ['code', 'label', 'movement_type']
Skia's avatar
Skia committed
35
    template_name = 'core/create.jinja'
Skia's avatar
Skia committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

# BankAccount views

class BankAccountListView(CanViewMixin, ListView):
    """
    A list view for the admins
    """
    model = BankAccount
    template_name = 'accounting/bank_account_list.jinja'

class BankAccountEditView(CanViewMixin, UpdateView):
    """
    An edit view for the admins
    """
    model = BankAccount
    pk_url_kwarg = "b_account_id"
Skia's avatar
Skia committed
52
53
    fields = ['name', 'iban', 'number']
    template_name = 'core/edit.jinja'
Skia's avatar
Skia committed
54
55
56
57
58
59
60
61
62

class BankAccountDetailView(CanViewMixin, DetailView):
    """
    A detail view, listing every club account
    """
    model = BankAccount
    pk_url_kwarg = "b_account_id"
    template_name = 'accounting/bank_account_details.jinja'

63
class BankAccountCreateView(CanCreateMixin, CreateView):
Skia's avatar
Skia committed
64
65
66
67
    """
    Create a bank account (for the admins)
    """
    model = BankAccount
Skia's avatar
Skia committed
68
69
    fields = ['name', 'iban', 'number']
    template_name = 'core/create.jinja'
Skia's avatar
Skia committed
70

Skia's avatar
Skia committed
71
class BankAccountDeleteView(CanEditPropMixin, DeleteView): # TODO change Delete to Close
Skia's avatar
Skia committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    """
    Delete a bank account (for the admins)
    """
    model = BankAccount
    pk_url_kwarg = "b_account_id"
    template_name = 'core/delete_confirm.jinja'
    success_url = reverse_lazy('accounting:bank_list')

# ClubAccount views

class ClubAccountEditView(CanViewMixin, UpdateView):
    """
    An edit view for the admins
    """
    model = ClubAccount
    pk_url_kwarg = "c_account_id"
    fields = ['name', 'club', 'bank_account']
Skia's avatar
Skia committed
89
    template_name = 'core/edit.jinja'
Skia's avatar
Skia committed
90
91
92
93
94
95
96
97
98

class ClubAccountDetailView(CanViewMixin, DetailView):
    """
    A detail view, listing every journal
    """
    model = ClubAccount
    pk_url_kwarg = "c_account_id"
    template_name = 'accounting/club_account_details.jinja'

99
class ClubAccountCreateView(CanCreateMixin, CreateView):
Skia's avatar
Skia committed
100
101
102
103
104
    """
    Create a club account (for the admins)
    """
    model = ClubAccount
    fields = ['name', 'club', 'bank_account']
Skia's avatar
Skia committed
105
106
107
108
109
110
111
112
113
    template_name = 'core/create.jinja'

    def get_initial(self):
        ret = super(ClubAccountCreateView, self).get_initial()
        if 'parent' in self.request.GET.keys():
            obj = BankAccount.objects.filter(id=int(self.request.GET['parent'])).first()
            if obj is not None:
                ret['bank_account'] = obj.id
        return ret
Skia's avatar
Skia committed
114

Skia's avatar
Skia committed
115
class ClubAccountDeleteView(CanEditPropMixin, DeleteView): # TODO change Delete to Close
Skia's avatar
Skia committed
116
117
118
119
120
121
122
123
124
125
    """
    Delete a club account (for the admins)
    """
    model = ClubAccount
    pk_url_kwarg = "c_account_id"
    template_name = 'core/delete_confirm.jinja'
    success_url = reverse_lazy('accounting:bank_list')

# Journal views

Skia's avatar
Skia committed
126
class JournalCreateView(CanCreateMixin, CreateView):
Skia's avatar
Skia committed
127
128
129
130
    """
    Create a general journal
    """
    model = GeneralJournal
131
    fields = ['name', 'start_date', 'club_account']
Skia's avatar
Skia committed
132
133
134
135
136
137
138
139
140
    template_name = 'core/create.jinja'

    def get_initial(self):
        ret = super(JournalCreateView, self).get_initial()
        if 'parent' in self.request.GET.keys():
            obj = ClubAccount.objects.filter(id=int(self.request.GET['parent'])).first()
            if obj is not None:
                ret['club_account'] = obj.id
        return ret
Skia's avatar
Skia committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

class JournalDetailView(CanViewMixin, DetailView):
    """
    A detail view, listing every operation
    """
    model = GeneralJournal
    pk_url_kwarg = "j_id"
    template_name = 'accounting/journal_details.jinja'

class JournalEditView(CanEditMixin, UpdateView):
    """
    Update a general journal
    """
    model = GeneralJournal
    pk_url_kwarg = "j_id"
Skia's avatar
Skia committed
156
    fields = ['name', 'start_date', 'end_date', 'club_account', 'closed']
Skia's avatar
Skia committed
157
    template_name = 'core/edit.jinja'
Skia's avatar
Skia committed
158
159
160

# Operation views

161
class OperationCreateView(CanCreateMixin, CreateView):
Skia's avatar
Skia committed
162
163
164
165
    """
    Create an operation
    """
    model = Operation
Skia's avatar
Skia committed
166
167
168
169
170
171
172
173
174
175
176
177
178
    # fields = ['type', 'amount', 'label', 'remark', 'journal', 'date', 'cheque_number', 'accounting_type', 'done']
    form_class = modelform_factory(Operation,
            fields=['amount', 'label', 'remark', 'journal', 'date', 'cheque_number', 'accounting_type', 'done'],
            widgets={'journal': HiddenInput})
    template_name = 'core/create.jinja'

    def get_initial(self):
        ret = super(OperationCreateView, self).get_initial()
        if 'parent' in self.request.GET.keys():
            obj = GeneralJournal.objects.filter(id=int(self.request.GET['parent'])).first()
            if obj is not None:
                ret['journal'] = obj.id
        return ret
Skia's avatar
Skia committed
179

Skia's avatar
Skia committed
180
class OperationEditView(CanEditMixin, UpdateView):
Skia's avatar
Skia committed
181
182
183
184
185
    """
    An edit view, working as detail for the moment
    """
    model = Operation
    pk_url_kwarg = "op_id"
Skia's avatar
Skia committed
186
    fields = ['amount', 'label', 'remark', 'date', 'cheque_number', 'accounting_type', 'done']
Skia's avatar
Skia committed
187
    template_name = 'core/edit.jinja'
Skia's avatar
Skia committed
188