Commit 660a3161 authored by Sli's avatar Sli
Browse files

Merge branch 'new_django' into 'master'

upgrade to django 2.2

See merge request !243
parents 9e6c4b32 c3f2d0a1
Pipeline #2089 failed with stage
in 60 minutes and 7 seconds
...@@ -4,6 +4,7 @@ from __future__ import unicode_literals ...@@ -4,6 +4,7 @@ from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models
import django.core.validators import django.core.validators
import accounting.models import accounting.models
import django.db.models.deletion
class Migration(migrations.Migration): class Migration(migrations.Migration):
...@@ -243,6 +244,7 @@ class Migration(migrations.Migration): ...@@ -243,6 +244,7 @@ class Migration(migrations.Migration):
verbose_name="accounting type", verbose_name="accounting type",
to="accounting.AccountingType", to="accounting.AccountingType",
blank=True, blank=True,
on_delete=django.db.models.deletion.CASCADE,
), ),
), ),
], ],
...@@ -267,6 +269,7 @@ class Migration(migrations.Migration): ...@@ -267,6 +269,7 @@ class Migration(migrations.Migration):
verbose_name="simplified accounting types", verbose_name="simplified accounting types",
to="accounting.AccountingType", to="accounting.AccountingType",
related_name="simplified_types", related_name="simplified_types",
on_delete=django.db.models.deletion.CASCADE,
), ),
), ),
], ],
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration): class Migration(migrations.Migration):
...@@ -22,6 +23,7 @@ class Migration(migrations.Migration): ...@@ -22,6 +23,7 @@ class Migration(migrations.Migration):
verbose_name="invoice", verbose_name="invoice",
to="core.SithFile", to="core.SithFile",
blank=True, blank=True,
on_delete=django.db.models.deletion.CASCADE,
), ),
), ),
migrations.AddField( migrations.AddField(
...@@ -31,12 +33,14 @@ class Migration(migrations.Migration): ...@@ -31,12 +33,14 @@ class Migration(migrations.Migration):
verbose_name="journal", verbose_name="journal",
to="accounting.GeneralJournal", to="accounting.GeneralJournal",
related_name="operations", related_name="operations",
on_delete=django.db.models.deletion.CASCADE,
), ),
), ),
migrations.AddField( migrations.AddField(
model_name="operation", model_name="operation",
name="linked_operation", name="linked_operation",
field=models.OneToOneField( field=models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
blank=True, blank=True,
to="accounting.Operation", to="accounting.Operation",
null=True, null=True,
...@@ -54,6 +58,7 @@ class Migration(migrations.Migration): ...@@ -54,6 +58,7 @@ class Migration(migrations.Migration):
verbose_name="simple type", verbose_name="simple type",
to="accounting.SimplifiedAccountingType", to="accounting.SimplifiedAccountingType",
blank=True, blank=True,
on_delete=django.db.models.deletion.CASCADE,
), ),
), ),
migrations.AddField( migrations.AddField(
...@@ -63,6 +68,7 @@ class Migration(migrations.Migration): ...@@ -63,6 +68,7 @@ class Migration(migrations.Migration):
verbose_name="club account", verbose_name="club account",
to="accounting.ClubAccount", to="accounting.ClubAccount",
related_name="journals", related_name="journals",
on_delete=django.db.models.deletion.CASCADE,
), ),
), ),
migrations.AddField( migrations.AddField(
...@@ -72,20 +78,27 @@ class Migration(migrations.Migration): ...@@ -72,20 +78,27 @@ class Migration(migrations.Migration):
verbose_name="bank account", verbose_name="bank account",
to="accounting.BankAccount", to="accounting.BankAccount",
related_name="club_accounts", related_name="club_accounts",
on_delete=django.db.models.deletion.CASCADE,
), ),
), ),
migrations.AddField( migrations.AddField(
model_name="clubaccount", model_name="clubaccount",
name="club", name="club",
field=models.ForeignKey( field=models.ForeignKey(
verbose_name="club", to="club.Club", related_name="club_account" verbose_name="club",
to="club.Club",
related_name="club_account",
on_delete=django.db.models.deletion.CASCADE,
), ),
), ),
migrations.AddField( migrations.AddField(
model_name="bankaccount", model_name="bankaccount",
name="club", name="club",
field=models.ForeignKey( field=models.ForeignKey(
verbose_name="club", to="club.Club", related_name="bank_accounts" verbose_name="club",
to="club.Club",
related_name="bank_accounts",
on_delete=django.db.models.deletion.CASCADE,
), ),
), ),
migrations.AlterUniqueTogether( migrations.AlterUniqueTogether(
......
...@@ -29,6 +29,7 @@ class Migration(migrations.Migration): ...@@ -29,6 +29,7 @@ class Migration(migrations.Migration):
related_name="labels", related_name="labels",
verbose_name="club account", verbose_name="club account",
to="accounting.ClubAccount", to="accounting.ClubAccount",
on_delete=django.db.models.deletion.CASCADE,
), ),
), ),
], ],
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
# #
# #
from django.core.urlresolvers import reverse from django.urls import reverse
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.core import validators from django.core import validators
from django.db import models from django.db import models
...@@ -110,7 +110,12 @@ class BankAccount(models.Model): ...@@ -110,7 +110,12 @@ class BankAccount(models.Model):
name = models.CharField(_("name"), max_length=30) name = models.CharField(_("name"), max_length=30)
iban = models.CharField(_("iban"), max_length=255, blank=True) iban = models.CharField(_("iban"), max_length=255, blank=True)
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"),
on_delete=models.CASCADE,
)
class Meta: class Meta:
verbose_name = _("Bank account") verbose_name = _("Bank account")
...@@ -136,9 +141,17 @@ class BankAccount(models.Model): ...@@ -136,9 +141,17 @@ class BankAccount(models.Model):
class ClubAccount(models.Model): class ClubAccount(models.Model):
name = models.CharField(_("name"), max_length=30) name = models.CharField(_("name"), max_length=30)
club = models.ForeignKey(Club, related_name="club_account", verbose_name=_("club")) club = models.ForeignKey(
Club,
related_name="club_account",
verbose_name=_("club"),
on_delete=models.CASCADE,
)
bank_account = models.ForeignKey( bank_account = models.ForeignKey(
BankAccount, related_name="club_accounts", verbose_name=_("bank account") BankAccount,
related_name="club_accounts",
verbose_name=_("bank account"),
on_delete=models.CASCADE,
) )
class Meta: class Meta:
...@@ -203,7 +216,11 @@ class GeneralJournal(models.Model): ...@@ -203,7 +216,11 @@ class GeneralJournal(models.Model):
name = models.CharField(_("name"), max_length=40) name = models.CharField(_("name"), max_length=40)
closed = models.BooleanField(_("is closed"), default=False) closed = models.BooleanField(_("is closed"), default=False)
club_account = models.ForeignKey( club_account = models.ForeignKey(
ClubAccount, related_name="journals", null=False, verbose_name=_("club account") ClubAccount,
related_name="journals",
null=False,
verbose_name=_("club account"),
on_delete=models.CASCADE,
) )
amount = CurrencyField(_("amount"), default=0) amount = CurrencyField(_("amount"), default=0)
effective_amount = CurrencyField(_("effective_amount"), default=0) effective_amount = CurrencyField(_("effective_amount"), default=0)
...@@ -263,7 +280,11 @@ class Operation(models.Model): ...@@ -263,7 +280,11 @@ class Operation(models.Model):
number = models.IntegerField(_("number")) number = models.IntegerField(_("number"))
journal = models.ForeignKey( journal = models.ForeignKey(
GeneralJournal, related_name="operations", null=False, verbose_name=_("journal") GeneralJournal,
related_name="operations",
null=False,
verbose_name=_("journal"),
on_delete=models.CASCADE,
) )
amount = CurrencyField(_("amount")) amount = CurrencyField(_("amount"))
date = models.DateField(_("date")) date = models.DateField(_("date"))
...@@ -282,6 +303,7 @@ class Operation(models.Model): ...@@ -282,6 +303,7 @@ class Operation(models.Model):
verbose_name=_("invoice"), verbose_name=_("invoice"),
null=True, null=True,
blank=True, blank=True,
on_delete=models.CASCADE,
) )
done = models.BooleanField(_("is done"), default=False) done = models.BooleanField(_("is done"), default=False)
simpleaccounting_type = models.ForeignKey( simpleaccounting_type = models.ForeignKey(
...@@ -290,6 +312,7 @@ class Operation(models.Model): ...@@ -290,6 +312,7 @@ class Operation(models.Model):
verbose_name=_("simple type"), verbose_name=_("simple type"),
null=True, null=True,
blank=True, blank=True,
on_delete=models.CASCADE,
) )
accounting_type = models.ForeignKey( accounting_type = models.ForeignKey(
"AccountingType", "AccountingType",
...@@ -297,6 +320,7 @@ class Operation(models.Model): ...@@ -297,6 +320,7 @@ class Operation(models.Model):
verbose_name=_("accounting type"), verbose_name=_("accounting type"),
null=True, null=True,
blank=True, blank=True,
on_delete=models.CASCADE,
) )
label = models.ForeignKey( label = models.ForeignKey(
"Label", "Label",
...@@ -328,6 +352,7 @@ class Operation(models.Model): ...@@ -328,6 +352,7 @@ class Operation(models.Model):
null=True, null=True,
blank=True, blank=True,
default=None, default=None,
on_delete=models.CASCADE,
) )
class Meta: class Meta:
...@@ -487,6 +512,7 @@ class SimplifiedAccountingType(models.Model): ...@@ -487,6 +512,7 @@ class SimplifiedAccountingType(models.Model):
AccountingType, AccountingType,
related_name="simplified_types", related_name="simplified_types",
verbose_name=_("simplified accounting types"), verbose_name=_("simplified accounting types"),
on_delete=models.CASCADE,
) )
class Meta: class Meta:
...@@ -518,7 +544,10 @@ class Label(models.Model): ...@@ -518,7 +544,10 @@ class Label(models.Model):
name = models.CharField(_("label"), max_length=64) name = models.CharField(_("label"), max_length=64)
club_account = models.ForeignKey( club_account = models.ForeignKey(
ClubAccount, related_name="labels", verbose_name=_("club account") ClubAccount,
related_name="labels",
verbose_name=_("club account"),
on_delete=models.CASCADE,
) )
class Meta: class Meta:
......
...@@ -20,14 +20,14 @@ ...@@ -20,14 +20,14 @@
{% for k,v in statement.items() %} {% for k,v in statement.items() %}
<tr> <tr>
<td>{{ k }}</td> <td>{{ k }}</td>
<td>{{ v }}</td> <td>{{ "%.2f" % v }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<p><strong>{% trans %}Amount: {% endtrans %}</strong>{{ object.amount }}</p> <p><strong>{% trans %}Amount: {% endtrans %}</strong>{{ "%.2f" % object.amount }}</p>
<p><strong>{% trans %}Effective amount: {% endtrans %}</strong>{{ object.effective_amount }}</p> <p><strong>{% trans %}Effective amount: {% endtrans %}</strong>{{ "%.2f" %object.effective_amount }}</p>
</div> </div>
{% endblock %} {% endblock %}
...@@ -18,12 +18,12 @@ ...@@ -18,12 +18,12 @@
{% for k,v in dict['CREDIT'].items() %} {% for k,v in dict['CREDIT'].items() %}
<tr> <tr>
<td>{{ k }}</td> <td>{{ k }}</td>
<td>{{ v }}</td> <td>{{ "%.2f" % v }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% trans %}Total: {% endtrans %}{{ dict['CREDIT_sum'] }} {% trans %}Total: {% endtrans %}{{ "%.2f" % dict['CREDIT_sum'] }}
<h6>{% trans %}Debit{% endtrans %}</h6> <h6>{% trans %}Debit{% endtrans %}</h6>
<table> <table>
...@@ -37,19 +37,19 @@ ...@@ -37,19 +37,19 @@
{% for k,v in dict['DEBIT'].items() %} {% for k,v in dict['DEBIT'].items() %}
<tr> <tr>
<td>{{ k }}</td> <td>{{ k }}</td>
<td>{{ v }}</td> <td>{{ "%.2f" % v }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% trans %}Total: {% endtrans %}{{ dict['DEBIT_sum'] }} {% trans %}Total: {% endtrans %}{{ "%.2f" % dict['DEBIT_sum'] }}
{% endmacro %} {% endmacro %}
{% block content %} {% block content %}
<h3>{% trans %}Statement by nature: {% endtrans %} {{ object.name }}</h3> <h3>{% trans %}Statement by nature: {% endtrans %} {{ object.name }}</h3>
{% for k,v in statement.items() %} {% for k,v in statement.items() %}
<h4 style="background: lightblue; padding: 4px;">{{ k }} : {{ v['CREDIT_sum'] - v['DEBIT_sum'] }}</h4> <h4 style="background: lightblue; padding: 4px;">{{ k }} : {{ "%.2f" % (v['CREDIT_sum'] - v['DEBIT_sum']) }}</h4>
{{ display_tables(v) }} {{ display_tables(v) }}
<hr> <hr>
{% endfor %} {% endfor %}
......
...@@ -28,14 +28,14 @@ ...@@ -28,14 +28,14 @@
{% else %} {% else %}
<td></td> <td></td>
{% endif %} {% endif %}
<td>{{ credit_statement[key] }}</td> <td>{{ "%.2f" % credit_statement[key] }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<p>Total : {{ total_credit }}</p> <p>Total : {{ "%.2f" % total_credit }}</p>
<h4>{% trans %}Debit{% endtrans %}</h4> <h4>{% trans %}Debit{% endtrans %}</h4>
...@@ -56,13 +56,13 @@ ...@@ -56,13 +56,13 @@
{% else %} {% else %}
<td></td> <td></td>
{% endif %} {% endif %}
<td>{{ debit_statement[key] }}</td> <td>{{ "%.2f" % debit_statement[key] }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<p>Total : {{ total_debit }}</p> <p>Total : {{ "%.2f" % total_debit }}</p>
</div> </div>
{% endblock %} {% endblock %}
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
# #
from django.test import TestCase from django.test import TestCase
from django.core.urlresolvers import reverse from django.urls import reverse
from django.core.management import call_command from django.core.management import call_command
from datetime import date from datetime import date
...@@ -272,30 +272,50 @@ class OperationTest(TestCase): ...@@ -272,30 +272,50 @@ class OperationTest(TestCase):
def test_nature_statement(self): def test_nature_statement(self):
self.client.login(username="comptable", password="plop") self.client.login(username="comptable", password="plop")
response_get = self.client.get( response = self.client.get(
reverse("accounting:journal_nature_statement", args=[self.journal.id]) reverse("accounting:journal_nature_statement", args=[self.journal.id])
) )
self.assertTrue( self.assertContains(response, "bob (Troll Penché) : 3.00", status_code=200)
"bob (Troll Pench\\xc3\\xa9) : 3.00" in str(response_get.content)
)
def test_person_statement(self): def test_person_statement(self):
self.client.login(username="comptable", password="plop") self.client.login(username="comptable", password="plop")
response_get = self.client.get( response = self.client.get(
reverse("accounting:journal_person_statement", args=[self.journal.id]) reverse("accounting:journal_person_statement", args=[self.journal.id])
) )
self.assertTrue( self.assertContains(response, "Total : 5575.72", status_code=200)
"<td>3.00</td>" in str(response_get.content) self.assertContains(response, "Total : 71.42")
and '<td><a href="/user/1/">S&#39; Kia</a></td>' self.assertContains(
in str(response_get.content) response,
"""
<td><a href="/user/1/">S&#39; Kia</a></td>
<td>3.00</td>""",
)
self.assertContains(
response,
"""
<td><a href="/user/1/">S&#39; Kia</a></td>
<td>823.00</td>""",
) )
def test_accounting_statement(self): def test_accounting_statement(self):
self.client.login(username="comptable", password="plop") self.client.login(username="comptable", password="plop")
response_get = self.client.get( response = self.client.get(
reverse("accounting:journal_accounting_statement", args=[self.journal.id]) reverse("accounting:journal_accounting_statement", args=[self.journal.id])
) )
self.assertTrue( self.assertContains(
"<td>443 - Cr\\xc3\\xa9dit - Ce code n&#39;existe pas</td>" response,
in str(response_get.content) """
<tr>
<td>443 - Crédit - Ce code n&#39;existe pas</td>
<td>3.00</td>
</tr>""",
status_code=200,
)
self.assertContains(
response,
"""
<p><strong>Montant : </strong>-5504.30 €</p>
<p><strong>Montant effectif: </strong>-5504.30 €</p>""",
) )
...@@ -22,131 +22,133 @@ ...@@ -22,131 +22,133 @@
# #
# #
from django.conf.urls import url from django.urls import re_path
from accounting.views import * from accounting.views import *
urlpatterns = [ urlpatterns = [
# Accounting types # Accounting types
url( re_path(
r"^simple_type$", r"^simple_type$",
SimplifiedAccountingTypeListView.as_view(), SimplifiedAccountingTypeListView.as_view(),
name="simple_type_list", name="simple_type_list",
), ),
url( re_path(
r"^simple_type/create$", r"^simple_type/create$",
SimplifiedAccountingTypeCreateView.as_view(), SimplifiedAccountingTypeCreateView.as_view(),
name="simple_type_new", name="simple_type_new",
), ),
url( re_path(
r"^simple_type/(?P<type_id>[0-9]+)/edit$", r"^simple_type/(?P<type_id>[0-9]+)/edit$",