Commit fb8e7ceb authored by Skia's avatar Skia 🤘
Browse files

Some templating and migration fix

parent 078b63d9
Pipeline #138 failed with stage
in 1 minute and 48 seconds
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounting', '0003_auto_20160824_1732'),
]
operations = [
migrations.AlterModelOptions(
name='accountingtype',
options={'ordering': ['movement_type', 'code'], 'verbose_name': 'accounting type'},
),
migrations.AlterModelOptions(
name='bankaccount',
options={'ordering': ['club', 'name'], 'verbose_name': 'Bank account'},
),
migrations.AlterModelOptions(
name='clubaccount',
options={'ordering': ['bank_account', 'name'], 'verbose_name': 'Club account'},
),
migrations.AlterModelOptions(
name='generaljournal',
options={'ordering': ['-start_date'], 'verbose_name': 'General journal'},
),
migrations.AlterModelOptions(
name='simplifiedaccountingtype',
options={'ordering': ['accounting_type__movement_type', 'accounting_type__code'], 'verbose_name': 'simplified type'},
),
]
...@@ -48,6 +48,10 @@ class BankAccount(models.Model): ...@@ -48,6 +48,10 @@ class BankAccount(models.Model):
number = models.CharField(_('account number'), max_length=255, blank=True) number = models.CharField(_('account number'), max_length=255, blank=True)
club = models.ForeignKey(Club, related_name="bank_accounts", verbose_name=_("club")) club = models.ForeignKey(Club, related_name="bank_accounts", verbose_name=_("club"))
class Meta:
verbose_name = _("Bank account")
ordering = ['club', 'name']
def is_owned_by(self, user): def is_owned_by(self, user):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
...@@ -70,6 +74,10 @@ class ClubAccount(models.Model): ...@@ -70,6 +74,10 @@ class ClubAccount(models.Model):
club = models.ForeignKey(Club, related_name="club_account", verbose_name=_("club")) club = models.ForeignKey(Club, related_name="club_account", verbose_name=_("club"))
bank_account = models.ForeignKey(BankAccount, related_name="club_accounts", verbose_name=_("bank account")) bank_account = models.ForeignKey(BankAccount, related_name="club_accounts", verbose_name=_("bank account"))
class Meta:
verbose_name = _("Club account")
ordering = ['bank_account', 'name']
def is_owned_by(self, user): def is_owned_by(self, user):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
...@@ -118,6 +126,10 @@ class GeneralJournal(models.Model): ...@@ -118,6 +126,10 @@ class GeneralJournal(models.Model):
amount = CurrencyField(_('amount'), default=0) amount = CurrencyField(_('amount'), default=0)
effective_amount = CurrencyField(_('effective_amount'), default=0) effective_amount = CurrencyField(_('effective_amount'), default=0)
class Meta:
verbose_name = _("General journal")
ordering = ['-start_date']
def is_owned_by(self, user): def is_owned_by(self, user):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
...@@ -259,10 +271,12 @@ class AccountingType(models.Model): ...@@ -259,10 +271,12 @@ class AccountingType(models.Model):
], ],
) )
label = models.CharField(_('label'), max_length=128) label = models.CharField(_('label'), max_length=128)
movement_type = models.CharField(_('movement type'), choices=[('CREDIT', 'Credit'), ('DEBIT', 'Debit'), ('NEUTRAL', 'Neutral')], max_length=12) movement_type = models.CharField(_('movement type'), choices=[('CREDIT', _('Credit')), ('DEBIT', _('Debit')),
('NEUTRAL', _('Neutral'))], max_length=12)
class Meta: class Meta:
verbose_name = _("accounting type") verbose_name = _("accounting type")
ordering = ['movement_type', 'code']
def is_owned_by(self, user): def is_owned_by(self, user):
""" """
...@@ -276,7 +290,7 @@ class AccountingType(models.Model): ...@@ -276,7 +290,7 @@ class AccountingType(models.Model):
return reverse('accounting:type_list') return reverse('accounting:type_list')
def __str__(self): def __str__(self):
return self.code+" - "+self.movement_type+" - "+self.label return self.code+" - "+self.get_movement_type_display()+" - "+self.label
class SimplifiedAccountingType(models.Model): class SimplifiedAccountingType(models.Model):
""" """
...@@ -288,6 +302,7 @@ class SimplifiedAccountingType(models.Model): ...@@ -288,6 +302,7 @@ class SimplifiedAccountingType(models.Model):
class Meta: class Meta:
verbose_name = _("simplified type") verbose_name = _("simplified type")
ordering = ['accounting_type__movement_type', 'accounting_type__code']
@property @property
def movement_type(self): def movement_type(self):
...@@ -300,5 +315,5 @@ class SimplifiedAccountingType(models.Model): ...@@ -300,5 +315,5 @@ class SimplifiedAccountingType(models.Model):
return reverse('accounting:simple_type_list') return reverse('accounting:simple_type_list')
def __str__(self): def __str__(self):
return self.label+" - "+self.accounting_type.code+" - "+self.get_movement_type_display() return self.get_movement_type_display()+" - "+self.accounting_type.code+" - "+self.label
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
</p> </p>
<hr> <hr>
<h2>{% trans %}Bank account: {% endtrans %}{{ object.name }}</h2> <h2>{% trans %}Bank account: {% endtrans %}{{ object.name }}</h2>
{% if user.is_root and not object.club_accounts.exists() %}
<a href="{{ url('accounting:bank_delete', b_account_id=object.id) }}">{% trans %}Delete{% endtrans %}</a>
{% endif %}
<h4>{% trans %}Infos{% endtrans %}</h4> <h4>{% trans %}Infos{% endtrans %}</h4>
<ul> <ul>
<li><strong>{% trans %}IBAN: {% endtrans %}</strong>{{ object.iban }}</li> <li><strong>{% trans %}IBAN: {% endtrans %}</strong>{{ object.iban }}</li>
...@@ -21,9 +24,6 @@ ...@@ -21,9 +24,6 @@
{% for c in object.club_accounts.all() %} {% for c in object.club_accounts.all() %}
<li><a href="{{ url('accounting:club_details', c_account_id=c.id) }}">{{ c }}</a> <li><a href="{{ url('accounting:club_details', c_account_id=c.id) }}">{{ c }}</a>
- <a href="{{ url('accounting:club_edit', c_account_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> - <a href="{{ url('accounting:club_edit', c_account_id=c.id) }}">{% trans %}Edit{% endtrans %}</a>
{% if user.is_root %}
- <a href="{{ url('accounting:club_delete', c_account_id=c.id) }}">{% trans %}Delete{% endtrans %}</a>
{% endif %}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
......
...@@ -19,9 +19,6 @@ ...@@ -19,9 +19,6 @@
{% for a in object_list %} {% for a in object_list %}
<li><a href="{{ url('accounting:bank_details', b_account_id=a.id) }}">{{ a }}</a> <li><a href="{{ url('accounting:bank_details', b_account_id=a.id) }}">{{ a }}</a>
- <a href="{{ url('accounting:bank_edit', b_account_id=a.id) }}">{% trans %}Edit{% endtrans %}</a> - <a href="{{ url('accounting:bank_edit', b_account_id=a.id) }}">{% trans %}Edit{% endtrans %}</a>
{% if user.is_root %}
- <a href="{{ url('accounting:bank_delete', b_account_id=a.id) }}">{% trans %}Delete{% endtrans %}</a>
{% endif %}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
......
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
</p> </p>
<hr> <hr>
<h2>{% trans %}Club account:{% endtrans %} {{ object.name }}</h2> <h2>{% trans %}Club account:{% endtrans %} {{ object.name }}</h2>
{% if user.is_root and not object.journals.exists() %}
<a href="{{ url('accounting:club_delete', c_account_id=object.id) }}">{% trans %}Delete{% endtrans %}</a>
{% endif %}
{% if not object.has_open_journal() %} {% if not object.has_open_journal() %}
<p><a href="{{ url('accounting:journal_new') }}?parent={{ object.id }}">{% trans %}New journal{% endtrans %}</a></p> <p><a href="{{ url('accounting:journal_new') }}?parent={{ object.id }}">{% trans %}New journal{% endtrans %}</a></p>
{% else %} {% else %}
......
...@@ -5,6 +5,14 @@ ...@@ -5,6 +5,14 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<p>
<a href="{{ url('accounting:bank_list') }}">{% trans %}Accounting{% endtrans %}</a> >
<a href="{{ url('accounting:bank_details', b_account_id=object.club_account.bank_account.id) }}">{{object.club_account.bank_account }}</a> >
<a href="{{ url('accounting:club_details', c_account_id=object.club_account.id) }}">{{ object.club_account }}</a> >
<a href="{{ url('accounting:journal_details', j_id=object.id) }}">{{ object.name }}</a> >
{% trans %}Edit operation{% endtrans %}
</p>
<hr>
<h2>{% trans %}Edit operation{% endtrans %}</h2> <h2>{% trans %}Edit operation{% endtrans %}</h2>
<form action="" method="post"> <form action="" method="post">
{% csrf_token %} {% csrf_token %}
...@@ -12,24 +20,12 @@ ...@@ -12,24 +20,12 @@
{{ form.target_id }} {{ form.target_id }}
<p>{{ form.amount.errors }}<label for="{{ form.amount.name }}">{{ form.amount.label }}</label> {{ form.amount }}</p> <p>{{ form.amount.errors }}<label for="{{ form.amount.name }}">{{ form.amount.label }}</label> {{ form.amount }}</p>
<p>{{ form.remark.errors }}<label for="{{ form.remark.name }}">{{ form.remark.label }}</label> {{ form.remark }}</p> <p>{{ form.remark.errors }}<label for="{{ form.remark.name }}">{{ form.remark.label }}</label> {{ form.remark }}</p>
<p>{{ form.target_type.errors }}<label for="{{ form.target_type.name }}">{{ form.target_type.label }}</label> </p> <p>{{ form.target_type.errors }}<label for="{{ form.target_type.name }}">{{ form.target_type.label }}</label> {{ form.target_type }}</p>
{% for choice in form.target_type %} {{ form.user }}
{% if choice.choice_value != "" %} {{ form.club }}
{{ choice }} {{ form.club_account }}
{% if choice.choice_value == "USER" %} {{ form.company }}
{{ form.user }} {{ form.target_label }}
{% elif choice.choice_value == "CLUB" %}
{{ form.club }}
{% elif choice.choice_value == "ACCOUNT" %}
{{ form.club_account }}
{% elif choice.choice_value == "COMPANY" %}
{{ form.company }}
{% elif choice.choice_value == "OTHER" %}
{{ form.target_label }}
{% endif %}
{% else %}
{% endif %}
{% endfor %}
<p>{{ form.date.errors }}<label for="{{ form.date.name }}">{{ form.date.label }}</label> {{ form.date }}</p> <p>{{ form.date.errors }}<label for="{{ form.date.name }}">{{ form.date.label }}</label> {{ form.date }}</p>
<p>{{ form.mode.errors }}<label for="{{ form.mode.name }}">{{ form.mode.label }}</label> {{ form.mode }}</p> <p>{{ form.mode.errors }}<label for="{{ form.mode.name }}">{{ form.mode.label }}</label> {{ form.mode }}</p>
<p>{{ form.cheque_number.errors }}<label for="{{ form.cheque_number.name }}">{{ form.cheque_number.label }}</label> {{ <p>{{ form.cheque_number.errors }}<label for="{{ form.cheque_number.name }}">{{ form.cheque_number.label }}</label> {{
...@@ -48,7 +44,55 @@ ...@@ -48,7 +44,55 @@
{{ super() }} {{ super() }}
<script> <script>
$( function() { $( function() {
} ); var target_type = $('#id_target_type');
var user = $('#id_user_wrapper');
var club = $('#id_club_wrapper');
var club_account = $('#id_club_account_wrapper');
var company = $('#id_company_wrapper');
var other = $('#id_target_label');
function update_targets () {
if (target_type.val() == "USER") {
console.log(user);
user.show();
club.hide();
club_account.hide();
company.hide();
other.hide();
} else if (target_type.val() == "ACCOUNT") {
club_account.show();
user.hide();
club.hide();
company.hide();
other.hide();
} else if (target_type.val() == "CLUB") {
club.show();
user.hide();
club_account.hide();
company.hide();
other.hide();
} else if (target_type.val() == "COMPANY") {
company.show();
user.hide();
club_account.hide();
club.hide();
other.hide();
} else if (target_type.val() == "OTHER") {
other.show();
user.hide();
club.hide();
club_account.hide();
company.hide();
} else {
company.hide();
user.hide();
club_account.hide();
club.hide();
other.hide();
}
}
update_targets();
target_type.change(update_targets);
} );
</script> </script>
{% endblock %} {% endblock %}
......
...@@ -202,7 +202,6 @@ class OperationForm(forms.ModelForm): ...@@ -202,7 +202,6 @@ class OperationForm(forms.ModelForm):
'target_id': HiddenInput, 'target_id': HiddenInput,
'date': SelectDate, 'date': SelectDate,
'invoice': SelectFile, 'invoice': SelectFile,
'target_type': forms.RadioSelect,
} }
user = AutoCompleteSelectField('users', help_text=None, required=False) user = AutoCompleteSelectField('users', help_text=None, required=False)
club_account = AutoCompleteSelectField('club_accounts', help_text=None, required=False) club_account = AutoCompleteSelectField('club_accounts', help_text=None, required=False)
...@@ -272,11 +271,18 @@ class OperationCreateView(CanCreateMixin, CreateView): ...@@ -272,11 +271,18 @@ class OperationCreateView(CanCreateMixin, CreateView):
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(): if 'parent' in self.request.GET.keys():
obj = GeneralJournal.objects.filter(id=int(self.request.GET['parent'])).first() self.journal = GeneralJournal.objects.filter(id=int(self.request.GET['parent'])).first()
if obj is not None: if self.journal is not None:
ret['journal'] = obj.id ret['journal'] = self.journal.id
return ret 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): class OperationEditView(CanEditMixin, UpdateView):
""" """
An edit view, working as detail for the moment An edit view, working as detail for the moment
...@@ -286,6 +292,12 @@ class OperationEditView(CanEditMixin, UpdateView): ...@@ -286,6 +292,12 @@ class OperationEditView(CanEditMixin, UpdateView):
form_class = OperationForm form_class = OperationForm
template_name = 'accounting/operation_edit.jinja' 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 # Company views
class CompanyCreateView(CanCreateMixin, CreateView): class CompanyCreateView(CanCreateMixin, CreateView):
......
from django.core.exceptions import PermissionDenied
from ajax_select import register, LookupChannel from ajax_select import register, LookupChannel
from core.views.site import search_user from core.views.site import search_user
...@@ -6,8 +7,13 @@ from club.models import Club ...@@ -6,8 +7,13 @@ from club.models import Club
from counter.models import Product, Counter from counter.models import Product, Counter
from accounting.models import ClubAccount, Company from accounting.models import ClubAccount, Company
class RightManagedLookupChannel(LookupChannel):
def check_auth(self, request):
if not request.user.subscribed:
raise PermissionDenied
@register('users') @register('users')
class UsersLookup(LookupChannel): class UsersLookup(RightManagedLookupChannel):
model = User model = User
def get_query(self, q, request): def get_query(self, q, request):
...@@ -20,7 +26,7 @@ class UsersLookup(LookupChannel): ...@@ -20,7 +26,7 @@ class UsersLookup(LookupChannel):
return item.get_display_name() return item.get_display_name()
@register('groups') @register('groups')
class GroupsLookup(LookupChannel): class GroupsLookup(RightManagedLookupChannel):
model = Group model = Group
def get_query(self, q, request): def get_query(self, q, request):
...@@ -33,7 +39,7 @@ class GroupsLookup(LookupChannel): ...@@ -33,7 +39,7 @@ class GroupsLookup(LookupChannel):
return item.name return item.name
@register('clubs') @register('clubs')
class ClubLookup(LookupChannel): class ClubLookup(RightManagedLookupChannel):
model = Club model = Club
def get_query(self, q, request): def get_query(self, q, request):
...@@ -46,7 +52,7 @@ class ClubLookup(LookupChannel): ...@@ -46,7 +52,7 @@ class ClubLookup(LookupChannel):
return item.name return item.name
@register('counters') @register('counters')
class CountersLookup(LookupChannel): class CountersLookup(RightManagedLookupChannel):
model = Counter model = Counter
def get_query(self, q, request): def get_query(self, q, request):
...@@ -56,7 +62,7 @@ class CountersLookup(LookupChannel): ...@@ -56,7 +62,7 @@ class CountersLookup(LookupChannel):
return item.name return item.name
@register('products') @register('products')
class ProductsLookup(LookupChannel): class ProductsLookup(RightManagedLookupChannel):
model = Product model = Product
def get_query(self, q, request): def get_query(self, q, request):
...@@ -66,7 +72,7 @@ class ProductsLookup(LookupChannel): ...@@ -66,7 +72,7 @@ class ProductsLookup(LookupChannel):
return item.name return item.name
@register('club_accounts') @register('club_accounts')
class ClubAccountLookup(LookupChannel): class ClubAccountLookup(RightManagedLookupChannel):
model = ClubAccount model = ClubAccount
def get_query(self, q, request): def get_query(self, q, request):
...@@ -76,7 +82,7 @@ class ClubAccountLookup(LookupChannel): ...@@ -76,7 +82,7 @@ class ClubAccountLookup(LookupChannel):
return item.name return item.name
@register('companies') @register('companies')
class CompaniesLookup(LookupChannel): class CompaniesLookup(RightManagedLookupChannel):
model = Company model = Company
def get_query(self, q, request): def get_query(self, q, request):
......
...@@ -377,11 +377,18 @@ class User(AbstractBaseUser): ...@@ -377,11 +377,18 @@ class User(AbstractBaseUser):
escape(self.get_display_name()), escape(self.get_display_name()),
) )
@property
def subscribed(self):
return self.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP)
class AnonymousUser(AuthAnonymousUser): class AnonymousUser(AuthAnonymousUser):
def __init__(self, request): def __init__(self, request):
super(AnonymousUser, self).__init__() super(AnonymousUser, self).__init__()
@property
def subscribed(self):
return False
def is_in_group(self, group_name): def is_in_group(self, group_name):
""" """
The anonymous user is only the public group The anonymous user is only the public group
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
<div id="language_chooser"> <div id="language_chooser">
{% for language in LANGUAGES %} {% for language in LANGUAGES %}
<form action="{{ url('set_language') }}" method="post">{% csrf_token %} <form action="{{ url('set_language') }}" method="post">{% csrf_token %}
<input name="next" value="{{ request.path }}" type="hidden" />
<input name="language" value="{{ language[0] }}" type="hidden" /> <input name="language" value="{{ language[0] }}" type="hidden" />
<input type="submit" value="{{ language[1]}}" /> <input type="submit" value="{{ language[1]}}" />
</form> </form>
......
This diff is collapsed.
...@@ -730,10 +730,18 @@ def migrate_operations(): ...@@ -730,10 +730,18 @@ def migrate_operations():
0: "CASH", 0: "CASH",
None: "CASH", None: "CASH",
} }
MOVEMENT_TYPE = {
-1: "DEBIT",
0: "NEUTRAL",
1: "CREDIT",
None: "NEUTRAL",
}
cur = db.cursor(MySQLdb.cursors.SSDictCursor) cur = db.cursor(MySQLdb.cursors.SSDictCursor)
cur.execute(""" cur.execute("""
SELECT * SELECT *
FROM cpta_operation FROM cpta_operation op
LEFT JOIN cpta_op_clb clb
ON op.id_opclb = clb.id_opclb
""") """)
Operation.objects.all().delete() Operation.objects.all().delete()
print("Operation deleted") print("Operation deleted")
...@@ -748,7 +756,7 @@ def migrate_operations(): ...@@ -748,7 +756,7 @@ def migrate_operations():
if not accounting_type and simple_type: if not accounting_type and simple_type:
accounting_type = simple_type.accounting_type accounting_type = simple_type.accounting_type
if not accounting_type: if not accounting_type:
accounting_type = AccountingType.objects.filter(movement_type="NEUTRAL").first() accounting_type = AccountingType.objects.filter(movement_type=MOVEMENT_TYPE[r['type_mouvement']]).first()
journal = GeneralJournal.objects.filter(id=r['id_classeur']).first() journal = GeneralJournal.objects.filter(id=r['id_classeur']).first()
def get_target_type(): def get_target_type():
if r['id_utilisateur']: if r['id_utilisateur']:
...@@ -808,35 +816,39 @@ def make_operation_links(): ...@@ -808,35 +816,39 @@ def make_operation_links():
def main(): def main():
start = datetime.datetime.now() start = datetime.datetime.now()
print("Start at %s" % start) print("Start at %s" % start)
# migrate_users() # Core
# migrate_profile_pict() migrate_users()
# migrate_clubs() migrate_profile_pict()
# migrate_club_memberships() # Club
# migrate_subscriptions() migrate_clubs()
# update_customer_account() migrate_club_memberships()
# migrate_counters() # Subscriptions
# migrate_permanencies() migrate_subscriptions()
# migrate_typeproducts() # Counters
# migrate_products() update_customer_account()
# migrate_product_pict() migrate_counters()
# migrate_products_to_counter() migrate_permanencies()
# reset_customer_amount() migrate_typeproducts()
# migrate_invoices()