diff --git a/accounting/migrations/0010_remove_operation_type.py b/accounting/migrations/0010_remove_operation_type.py new file mode 100644 index 00000000..64883343 --- /dev/null +++ b/accounting/migrations/0010_remove_operation_type.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0009_auto_20160622_1030'), + ] + + operations = [ + migrations.RemoveField( + model_name='operation', + name='type', + ), + ] diff --git a/accounting/models.py b/accounting/models.py index 87c62dd4..e14a0d44 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -130,7 +130,7 @@ class GeneralJournal(models.Model): self.amount = 0 self.effective_amount = 0 for o in self.operations.all(): - if o.type == "credit": + if o.accounting_type.movement_type == "credit": if o.done: self.effective_amount += o.amount self.amount += o.amount @@ -154,10 +154,6 @@ class Operation(models.Model): invoice = models.FileField(upload_to='invoices', null=True, blank=True) done = models.BooleanField(_('is done'), default=False) accounting_type = models.ForeignKey('AccountingType', related_name="operations") - type = models.CharField(_('operation type'), max_length=8, choices=[ - ('debit', _('Debit')), - ('credit', _('Credit')), - ]) def save(self): super(Operation, self).save() @@ -186,8 +182,8 @@ class Operation(models.Model): return reverse('accounting:journal_details', kwargs={'j_id': self.journal.id}) def __str__(self): - return "%d | %s | %d € | %s | %s | %s" % ( - self.id, self.type, self.amount, self.date, self.accounting_type, self.done, + return "%d | %d € | %s | %s | %s" % ( + self.id, self.amount, self.date, self.accounting_type, self.done, ) class AccountingType(models.Model): diff --git a/accounting/templates/accounting/bank_account_details.jinja b/accounting/templates/accounting/bank_account_details.jinja index 74695755..93d20581 100644 --- a/accounting/templates/accounting/bank_account_details.jinja +++ b/accounting/templates/accounting/bank_account_details.jinja @@ -11,7 +11,7 @@
Amount: {{ object.amount }} € - Effective amount: {{ object.effective_amount }} €
- +Nb | diff --git a/accounting/views.py b/accounting/views.py index 5563dd4e..953b0fcc 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -24,7 +24,7 @@ class AccountingTypeEditView(CanViewMixin, UpdateView): model = AccountingType pk_url_kwarg = "type_id" fields = ['code', 'label', 'movement_type'] - template_name = 'accounting/account_edit.jinja' + template_name = 'core/edit.jinja' class AccountingTypeCreateView(CanEditPropMixin, CreateView): # TODO: move to CanCreateMixin """ @@ -32,7 +32,7 @@ class AccountingTypeCreateView(CanEditPropMixin, CreateView): # TODO: move to Ca """ model = AccountingType fields = ['code', 'label', 'movement_type'] - template_name = 'accounting/account_edit.jinja' + template_name = 'core/create.jinja' # BankAccount views @@ -49,8 +49,8 @@ class BankAccountEditView(CanViewMixin, UpdateView): """ model = BankAccount pk_url_kwarg = "b_account_id" - fields = ['name', 'rib', 'number'] - template_name = 'accounting/account_edit.jinja' + fields = ['name', 'iban', 'number'] + template_name = 'core/edit.jinja' class BankAccountDetailView(CanViewMixin, DetailView): """ @@ -65,8 +65,8 @@ class BankAccountCreateView(CanEditPropMixin, CreateView): # TODO: move to CanCr Create a bank account (for the admins) """ model = BankAccount - fields = ['name', 'rib', 'number'] - template_name = 'accounting/account_edit.jinja' + fields = ['name', 'iban', 'number'] + template_name = 'core/create.jinja' class BankAccountDeleteView(CanEditPropMixin, DeleteView): # TODO change Delete to Close """ @@ -86,7 +86,7 @@ class ClubAccountEditView(CanViewMixin, UpdateView): model = ClubAccount pk_url_kwarg = "c_account_id" fields = ['name', 'club', 'bank_account'] - template_name = 'accounting/account_edit.jinja' + template_name = 'core/edit.jinja' class ClubAccountDetailView(CanViewMixin, DetailView): """ @@ -102,7 +102,15 @@ class ClubAccountCreateView(CanEditPropMixin, CreateView): # TODO: move to CanCr """ model = ClubAccount fields = ['name', 'club', 'bank_account'] - template_name = 'accounting/account_edit.jinja' + 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 class ClubAccountDeleteView(CanEditPropMixin, DeleteView): # TODO change Delete to Close """ @@ -120,8 +128,16 @@ class JournalCreateView(CanCreateMixin, CreateView): Create a general journal """ model = GeneralJournal - template_name = 'accounting/account_edit.jinja' fields = ['name', 'start_date', 'club_account'] + 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 class JournalDetailView(CanViewMixin, DetailView): """ @@ -138,7 +154,7 @@ class JournalEditView(CanEditMixin, UpdateView): model = GeneralJournal pk_url_kwarg = "j_id" fields = ['name', 'start_date', 'club_account'] - template_name = 'accounting/account_edit.jinja' + template_name = 'core/edit.jinja' # Operation views @@ -147,8 +163,19 @@ class OperationCreateView(CanEditMixin, CreateView): # TODO: move to CanCreateMi Create an operation """ model = Operation - fields = ['type', 'amount', 'label', 'remark', 'journal', 'date', 'cheque_number', 'accounting_type', 'done'] - template_name = 'accounting/account_edit.jinja' + # 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 class OperationEditView(CanViewMixin, UpdateView): """ @@ -157,5 +184,5 @@ class OperationEditView(CanViewMixin, UpdateView): model = Operation pk_url_kwarg = "op_id" fields = ['amount', 'label', 'remark', 'date', 'cheque_number', 'accounting_type', 'done'] - template_name = 'accounting/account_edit.jinja' + template_name = 'core/edit.jinja' diff --git a/accounting/templates/accounting/account_edit.jinja b/core/templates/core/create.jinja similarity index 89% rename from accounting/templates/accounting/account_edit.jinja rename to core/templates/core/create.jinja index 092f0666..611f93ed 100644 --- a/accounting/templates/accounting/account_edit.jinja +++ b/core/templates/core/create.jinja @@ -1,7 +1,7 @@ {% extends "core/base.jinja" %} {% block content %} -