From 0acc97fa90d6877d3e71f6cca4704ef96f255d67 Mon Sep 17 00:00:00 2001
From: Skia
Date: Wed, 5 Oct 2016 20:17:37 +0200
Subject: [PATCH] Fix operation create view
---
.../templates/accounting/journal_details.jinja | 4 +++-
accounting/urls.py | 2 +-
accounting/views.py | 15 ++++++++++-----
3 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/accounting/templates/accounting/journal_details.jinja b/accounting/templates/accounting/journal_details.jinja
index 75e28d8f..3e499dda 100644
--- a/accounting/templates/accounting/journal_details.jinja
+++ b/accounting/templates/accounting/journal_details.jinja
@@ -13,12 +13,14 @@
{% trans %}General journal:{% endtrans %} {{ object.name }}
+ {% trans %}New label{% endtrans %}
+ {% trans %}Label list{% endtrans %}
{% trans %}Amount: {% endtrans %}{{ object.amount }} € -
{% trans %}Effective amount: {% endtrans %}{{ object.effective_amount }} €
{% if object.closed %}
{% trans %}Journal is closed, you can not create operation{% endtrans %}
{% else %}
- {% trans %}New operation{% endtrans %}
+ {% trans %}New operation{% endtrans %}
{% endif %}
diff --git a/accounting/urls.py b/accounting/urls.py
index d9d1de50..15626460 100644
--- a/accounting/urls.py
+++ b/accounting/urls.py
@@ -27,7 +27,7 @@ urlpatterns = [
url(r'^journal/(?P[0-9]+)$', JournalDetailView.as_view(), name='journal_details'),
url(r'^journal/(?P[0-9]+)/edit$', JournalEditView.as_view(), name='journal_edit'),
# Operations
- url(r'^operation/create$', OperationCreateView.as_view(), name='op_new'),
+ url(r'^operation/create/(?P[0-9]+)$', OperationCreateView.as_view(), name='op_new'),
url(r'^operation/(?P[0-9]+)$', OperationEditView.as_view(), name='op_edit'),
# Companies
url(r'^company/create$', CompanyCreateView.as_view(), name='co_new'),
diff --git a/accounting/views.py b/accounting/views.py
index 6a1e61be..de424400 100644
--- a/accounting/views.py
+++ b/accounting/views.py
@@ -209,8 +209,10 @@ class OperationForm(forms.ModelForm):
company = AutoCompleteSelectField('companies', help_text=None, required=False)
def __init__(self, *args, **kwargs):
+ club_account = kwargs.pop('club_account', None)
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":
self.fields['user'].initial = self.instance.target_id
elif self.instance.target_type == "ACCOUNT":
@@ -268,12 +270,15 @@ class OperationCreateView(CanCreateMixin, CreateView):
form_class = OperationForm
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):
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:
- ret['journal'] = self.journal.id
+ if self.journal is not None:
+ ret['journal'] = self.journal.id
return ret
def get_context_data(self, **kwargs):