mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-20 17:41:55 +02:00
RecurrentTransaction amount history
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
from django import forms
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from note_kfet.inputs import Autocomplete
|
||||
from note_kfet.inputs import Autocomplete, AmountInput
|
||||
|
||||
from .models import TransactionTemplate, NoteClub
|
||||
|
||||
@ -24,11 +24,6 @@ class TransactionTemplateForm(forms.ModelForm):
|
||||
model = TransactionTemplate
|
||||
fields = '__all__'
|
||||
|
||||
# Le champ de destination est remplacé par un champ d'auto-complétion.
|
||||
# Quand des lettres sont tapées, une requête est envoyée sur l'API d'auto-complétion
|
||||
# et récupère les aliases valides
|
||||
# Pour force le type d'une note, il faut rajouter le paramètre :
|
||||
# forward=(forward.Const('TYPE', 'note_type') où TYPE est dans {user, club, special}
|
||||
widgets = {
|
||||
'destination':
|
||||
Autocomplete(
|
||||
@ -41,4 +36,5 @@ class TransactionTemplateForm(forms.ModelForm):
|
||||
'placeholder': 'Note ...',
|
||||
},
|
||||
),
|
||||
'amount': AmountInput(),
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
import json
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
@ -80,6 +81,33 @@ class TransactionTemplateUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, Up
|
||||
form_class = TransactionTemplateForm
|
||||
success_url = reverse_lazy('note:template_list')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
if "logs" in settings.INSTALLED_APPS:
|
||||
from logs.models import Changelog
|
||||
update_logs = Changelog.objects.filter(
|
||||
model=ContentType.objects.get_for_model(TransactionTemplate),
|
||||
instance_pk=self.object.pk,
|
||||
action="edit",
|
||||
)
|
||||
price_history = []
|
||||
for log in update_logs.all():
|
||||
old_dict = json.loads(log.previous)
|
||||
new_dict = json.loads(log.data)
|
||||
old_price = old_dict["amount"]
|
||||
new_price = new_dict["amount"]
|
||||
if old_price != new_price:
|
||||
price_history.append(dict(price=old_price, time=log.timestamp))
|
||||
|
||||
price_history.append(dict(price=self.object.amount, time=None))
|
||||
|
||||
price_history.reverse()
|
||||
|
||||
context["price_history"] = price_history
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class ConsoView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user