mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-11-26 18:37:12 +00:00
Remove useless category field in RecurrentTransaction (that is the category of the template)
This commit is contained in:
parent
be08c12dca
commit
2b70a05a9e
@ -95,22 +95,16 @@ class Note(PolymorphicModel):
|
||||
"""
|
||||
Save note with it's alias (called in polymorphic children)
|
||||
"""
|
||||
aliases = Alias.objects.filter(name=str(self))
|
||||
if aliases.exists():
|
||||
# Alias exists, so check if it is linked to this note
|
||||
if aliases.first().note != self:
|
||||
raise ValidationError(_('This alias is already taken.'),
|
||||
code="same_alias")
|
||||
# Check that we can save the alias
|
||||
self.clean()
|
||||
|
||||
# Save note
|
||||
super().save(*args, **kwargs)
|
||||
else:
|
||||
# Alias does not exist yet, so check if it can exist
|
||||
|
||||
if not Alias.objects.filter(name=str(self)).exists():
|
||||
a = Alias(name=str(self))
|
||||
a.clean()
|
||||
|
||||
# Save note and alias
|
||||
super().save(*args, **kwargs)
|
||||
# Save alias
|
||||
a.note = self
|
||||
a.save(force_insert=True)
|
||||
|
||||
@ -155,9 +149,9 @@ class NoteUser(Note):
|
||||
def save(self, *args, **kwargs):
|
||||
if self.pk and self.balance < 0:
|
||||
old_note = NoteUser.objects.get(pk=self.pk)
|
||||
super().save(*args, **kwargs)
|
||||
if old_note.balance >= 0:
|
||||
# Passage en négatif
|
||||
super().save(*args, **kwargs)
|
||||
self.last_negative = timezone.now()
|
||||
self._force_save = True
|
||||
self.save(*args, **kwargs)
|
||||
@ -196,6 +190,7 @@ class NoteClub(Note):
|
||||
def save(self, *args, **kwargs):
|
||||
if self.pk and self.balance < 0:
|
||||
old_note = NoteClub.objects.get(pk=self.pk)
|
||||
super().save(*args, **kwargs)
|
||||
if old_note.balance >= 0:
|
||||
# Passage en négatif
|
||||
super().save(*args, **kwargs)
|
||||
@ -203,6 +198,7 @@ class NoteClub(Note):
|
||||
self._force_save = True
|
||||
self.save(*args, **kwargs)
|
||||
self.send_mail_negative_balance()
|
||||
else:
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def send_mail_negative_balance(self):
|
||||
@ -308,7 +304,7 @@ class Alias(models.Model):
|
||||
self.normalized_name = normalized_name
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.normalized_name = self.normalize(self.name)
|
||||
self.clean()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def delete(self, using=None, keep_parents=False):
|
||||
|
@ -273,10 +273,15 @@ class RecurrentTransaction(Transaction):
|
||||
on_delete=models.PROTECT,
|
||||
)
|
||||
|
||||
category = models.ForeignKey(
|
||||
TemplateCategory,
|
||||
on_delete=models.PROTECT,
|
||||
)
|
||||
def clean(self):
|
||||
if self.template.destination != self.destination:
|
||||
raise ValidationError(
|
||||
_("The destination of this transaction must equal to the destination of the template."))
|
||||
return super().clean()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.clean()
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
@ -324,6 +329,10 @@ class SpecialTransaction(Transaction):
|
||||
raise(ValidationError(_("A special transaction is only possible between a"
|
||||
" Note associated to a payment method and a User or a Club")))
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.clean()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Special transaction")
|
||||
verbose_name_plural = _("Special transactions")
|
||||
|
@ -226,7 +226,6 @@ function consume(source, source_alias, dest, quantity, amount, reason, type, cat
|
||||
"source": source.id,
|
||||
"source_alias": source_alias,
|
||||
"destination": dest,
|
||||
"category": category,
|
||||
"template": template
|
||||
})
|
||||
.done(function () {
|
||||
@ -259,7 +258,6 @@ function consume(source, source_alias, dest, quantity, amount, reason, type, cat
|
||||
"source": source,
|
||||
"source_alias": source_alias,
|
||||
"destination": dest,
|
||||
"category": category,
|
||||
"template": template
|
||||
}).done(function() {
|
||||
reset();
|
||||
|
Loading…
Reference in New Issue
Block a user