Some templating and migration fix

This commit is contained in:
Skia
2016-08-24 21:49:46 +02:00
parent 078b63d970
commit fb8e7ceb5b
13 changed files with 358 additions and 196 deletions

View File

@ -202,7 +202,6 @@ class OperationForm(forms.ModelForm):
'target_id': HiddenInput,
'date': SelectDate,
'invoice': SelectFile,
'target_type': forms.RadioSelect,
}
user = AutoCompleteSelectField('users', help_text=None, required=False)
club_account = AutoCompleteSelectField('club_accounts', help_text=None, required=False)
@ -272,11 +271,18 @@ class OperationCreateView(CanCreateMixin, CreateView):
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
self.journal = GeneralJournal.objects.filter(id=int(self.request.GET['parent'])).first()
if self.journal is not None:
ret['journal'] = self.journal.id
return ret
def get_context_data(self, **kwargs):
""" Add journal to the context """
kwargs = super(OperationCreateView, self).get_context_data(**kwargs)
if self.journal:
kwargs['object'] = self.journal
return kwargs
class OperationEditView(CanEditMixin, UpdateView):
"""
An edit view, working as detail for the moment
@ -286,6 +292,12 @@ class OperationEditView(CanEditMixin, UpdateView):
form_class = OperationForm
template_name = 'accounting/operation_edit.jinja'
def get_context_data(self, **kwargs):
""" Add journal to the context """
kwargs = super(OperationCreateView, self).get_context_data(**kwargs)
kwargs['object'] = self.object.journal
return kwargs
# Company views
class CompanyCreateView(CanCreateMixin, CreateView):