mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-26 11:04:20 +00:00
Fix operation create view
This commit is contained in:
parent
63217b2ead
commit
0acc97fa90
@ -13,12 +13,14 @@
|
|||||||
</p>
|
</p>
|
||||||
<hr>
|
<hr>
|
||||||
<h2>{% trans %}General journal:{% endtrans %} {{ object.name }}</h2>
|
<h2>{% trans %}General journal:{% endtrans %} {{ object.name }}</h2>
|
||||||
|
<p><a href="{{ url('accounting:label_new') }}?parent={{ object.club_account.id }}">{% trans %}New label{% endtrans %}</a></p>
|
||||||
|
<p><a href="{{ url('accounting:label_list', clubaccount_id=object.club_account.id) }}">{% trans %}Label list{% endtrans %}</a></p>
|
||||||
<p><strong>{% trans %}Amount: {% endtrans %}</strong>{{ object.amount }} € -
|
<p><strong>{% trans %}Amount: {% endtrans %}</strong>{{ object.amount }} € -
|
||||||
<strong>{% trans %}Effective amount: {% endtrans %}</strong>{{ object.effective_amount }} €</p>
|
<strong>{% trans %}Effective amount: {% endtrans %}</strong>{{ object.effective_amount }} €</p>
|
||||||
{% if object.closed %}
|
{% if object.closed %}
|
||||||
<p>{% trans %}Journal is closed, you can not create operation{% endtrans %}</p>
|
<p>{% trans %}Journal is closed, you can not create operation{% endtrans %}</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p><a href="{{ url('accounting:op_new') }}?parent={{ object.id }}">{% trans %}New operation{% endtrans %}</a></p>
|
<p><a href="{{ url('accounting:op_new', j_id=object.id) }}">{% trans %}New operation{% endtrans %}</a></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -27,7 +27,7 @@ urlpatterns = [
|
|||||||
url(r'^journal/(?P<j_id>[0-9]+)$', JournalDetailView.as_view(), name='journal_details'),
|
url(r'^journal/(?P<j_id>[0-9]+)$', JournalDetailView.as_view(), name='journal_details'),
|
||||||
url(r'^journal/(?P<j_id>[0-9]+)/edit$', JournalEditView.as_view(), name='journal_edit'),
|
url(r'^journal/(?P<j_id>[0-9]+)/edit$', JournalEditView.as_view(), name='journal_edit'),
|
||||||
# Operations
|
# Operations
|
||||||
url(r'^operation/create$', OperationCreateView.as_view(), name='op_new'),
|
url(r'^operation/create/(?P<j_id>[0-9]+)$', OperationCreateView.as_view(), name='op_new'),
|
||||||
url(r'^operation/(?P<op_id>[0-9]+)$', OperationEditView.as_view(), name='op_edit'),
|
url(r'^operation/(?P<op_id>[0-9]+)$', OperationEditView.as_view(), name='op_edit'),
|
||||||
# Companies
|
# Companies
|
||||||
url(r'^company/create$', CompanyCreateView.as_view(), name='co_new'),
|
url(r'^company/create$', CompanyCreateView.as_view(), name='co_new'),
|
||||||
|
@ -209,8 +209,10 @@ class OperationForm(forms.ModelForm):
|
|||||||
company = AutoCompleteSelectField('companies', help_text=None, required=False)
|
company = AutoCompleteSelectField('companies', help_text=None, required=False)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
club_account = kwargs.pop('club_account', None)
|
||||||
super(OperationForm, self).__init__(*args, **kwargs)
|
super(OperationForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['label'].queryset = self.instance.journal.club_account.labels.order_by('name').all()
|
if club_account:
|
||||||
|
self.fields['label'].queryset = club_account.labels.order_by('name').all()
|
||||||
if self.instance.target_type == "USER":
|
if self.instance.target_type == "USER":
|
||||||
self.fields['user'].initial = self.instance.target_id
|
self.fields['user'].initial = self.instance.target_id
|
||||||
elif self.instance.target_type == "ACCOUNT":
|
elif self.instance.target_type == "ACCOUNT":
|
||||||
@ -268,10 +270,13 @@ class OperationCreateView(CanCreateMixin, CreateView):
|
|||||||
form_class = OperationForm
|
form_class = OperationForm
|
||||||
template_name = 'accounting/operation_edit.jinja'
|
template_name = 'accounting/operation_edit.jinja'
|
||||||
|
|
||||||
|
def get_form(self, form_class=None):
|
||||||
|
self.journal = GeneralJournal.objects.filter(id=self.kwargs['j_id']).first()
|
||||||
|
ca = self.journal.club_account if self.journal else None
|
||||||
|
return self.form_class(club_account=ca, **self.get_form_kwargs())
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
ret = super(OperationCreateView, self).get_initial()
|
ret = super(OperationCreateView, self).get_initial()
|
||||||
if 'parent' in self.request.GET.keys():
|
|
||||||
self.journal = GeneralJournal.objects.filter(id=int(self.request.GET['parent'])).first()
|
|
||||||
if self.journal is not None:
|
if self.journal is not None:
|
||||||
ret['journal'] = self.journal.id
|
ret['journal'] = self.journal.id
|
||||||
return ret
|
return ret
|
||||||
|
Loading…
Reference in New Issue
Block a user