Skip to content

Commit

Permalink
Fixed issues after bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Even Fjeldstad committed Sep 26, 2024
1 parent bf7a7d8 commit fd9f1c5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
35 changes: 11 additions & 24 deletions itkufs/accounting/management/commands/createuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,18 @@

CONSOLE_LOG_FORMAT = "%(levelname)-8s %(message)s"


class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option(
"-g",
"--group",
dest="group_slug",
help="Group to create new account in",
),
make_option(
"-u",
"--user",
dest="username",
help="User to create uFS user and account for",
),
make_option(
"-y",
"--yes",
action="store_const",
const=1,
dest="yes",
default=0,
help="Do not ask for confirmation",
),
)
def add_arguments(self, parser):
parser.add_argument('-g', '--group',
help="Group to create new account in", dest="group_slug")

parser.add_argument('-u', '--user',
help="User to create uFS user and account for", dest="username")

parser.add_argument('-y', '--yes', action='store_const', const=1,
dest="yes", default=0,
help="Do not ask for confirmation")

def __init__(self):
self.logger = self._setup_logging()
Expand Down
10 changes: 9 additions & 1 deletion itkufs/accounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Value,
F,
ExpressionWrapper,
IntegerField,
)
from django.contrib.auth.models import User
from django.urls import reverse
Expand Down Expand Up @@ -913,7 +914,14 @@ class Meta:
unique_together = (("transaction", "account"),)
verbose_name = _("transaction entry")
verbose_name_plural = _("transaction entries")
ordering = ("credit", "debit")
ordering = (
Case(
When(credit__gt=0, then=Value(1)),
When(debit__gt=0, then=Value(0)),
output_field=IntegerField(),
),
"account__name",
)

def __str__(self):
return _("%(account)s: debit %(debit)s, credit %(credit)s") % {
Expand Down
2 changes: 1 addition & 1 deletion itkufs/common/static/common/ufs.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Element.observe(window, 'load', Transaction.init);

var Multiselect = {
init: function() {
$$('select[multiple=multiple]').each( // Use css selector to get right nodes.
$$('select[multiple]').each( // Use css selector to get right nodes.
function(selected) {
// Create sibling select
var available = new Element('select', {
Expand Down
2 changes: 1 addition & 1 deletion itkufs/reports/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def save(self, group: Optional[Group] = None, **kwargs):

if original_commit:
list.save()
list.extra_accounts = self.cleaned_data["extra_accounts"]
list.extra_accounts.set(self.cleaned_data["extra_accounts"])

return list

Expand Down
6 changes: 5 additions & 1 deletion itkufs/reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.db import transaction as db_transaction
from django.db.models import Q, Sum, Case, When
from django.db.models import Q, Sum, Case, When, DecimalField
from django.db.models.functions import Coalesce
from django.forms.models import inlineformset_factory, model_to_dict
from django.http import Http404, HttpResponseRedirect, HttpResponse, HttpRequest
Expand Down Expand Up @@ -339,17 +339,21 @@ def balance(request: HttpRequest, group: Group, is_admin=False):
Sum(
Case(
When(normal_balance__gt=0, then="normal_balance"),
output_field=DecimalField()
)
),
0,
output_field=DecimalField()
),
negative_sum=Coalesce(
Sum(
Case(
When(normal_balance__lt=0, then="normal_balance"),
output_field=DecimalField()
)
),
0,
output_field=DecimalField()
),
)
)
Expand Down

0 comments on commit fd9f1c5

Please sign in to comment.