mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-12-03 13:46:58 +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)
|
Save note with it's alias (called in polymorphic children)
|
||||||
"""
|
"""
|
||||||
aliases = Alias.objects.filter(name=str(self))
|
# Check that we can save the alias
|
||||||
if aliases.exists():
|
self.clean()
|
||||||
# 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")
|
|
||||||
|
|
||||||
# Save note
|
|
||||||
super().save(*args, **kwargs)
|
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 = Alias(name=str(self))
|
||||||
a.clean()
|
a.clean()
|
||||||
|
|
||||||
# Save note and alias
|
# Save alias
|
||||||
super().save(*args, **kwargs)
|
|
||||||
a.note = self
|
a.note = self
|
||||||
a.save(force_insert=True)
|
a.save(force_insert=True)
|
||||||
|
|
||||||
@ -155,9 +149,9 @@ class NoteUser(Note):
|
|||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if self.pk and self.balance < 0:
|
if self.pk and self.balance < 0:
|
||||||
old_note = NoteUser.objects.get(pk=self.pk)
|
old_note = NoteUser.objects.get(pk=self.pk)
|
||||||
|
super().save(*args, **kwargs)
|
||||||
if old_note.balance >= 0:
|
if old_note.balance >= 0:
|
||||||
# Passage en négatif
|
# Passage en négatif
|
||||||
super().save(*args, **kwargs)
|
|
||||||
self.last_negative = timezone.now()
|
self.last_negative = timezone.now()
|
||||||
self._force_save = True
|
self._force_save = True
|
||||||
self.save(*args, **kwargs)
|
self.save(*args, **kwargs)
|
||||||
@ -196,6 +190,7 @@ class NoteClub(Note):
|
|||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if self.pk and self.balance < 0:
|
if self.pk and self.balance < 0:
|
||||||
old_note = NoteClub.objects.get(pk=self.pk)
|
old_note = NoteClub.objects.get(pk=self.pk)
|
||||||
|
super().save(*args, **kwargs)
|
||||||
if old_note.balance >= 0:
|
if old_note.balance >= 0:
|
||||||
# Passage en négatif
|
# Passage en négatif
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
@ -203,6 +198,7 @@ class NoteClub(Note):
|
|||||||
self._force_save = True
|
self._force_save = True
|
||||||
self.save(*args, **kwargs)
|
self.save(*args, **kwargs)
|
||||||
self.send_mail_negative_balance()
|
self.send_mail_negative_balance()
|
||||||
|
else:
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
def send_mail_negative_balance(self):
|
def send_mail_negative_balance(self):
|
||||||
@ -308,7 +304,7 @@ class Alias(models.Model):
|
|||||||
self.normalized_name = normalized_name
|
self.normalized_name = normalized_name
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.normalized_name = self.normalize(self.name)
|
self.clean()
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
def delete(self, using=None, keep_parents=False):
|
def delete(self, using=None, keep_parents=False):
|
||||||
|
@ -273,10 +273,15 @@ class RecurrentTransaction(Transaction):
|
|||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
)
|
)
|
||||||
|
|
||||||
category = models.ForeignKey(
|
def clean(self):
|
||||||
TemplateCategory,
|
if self.template.destination != self.destination:
|
||||||
on_delete=models.PROTECT,
|
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
|
@property
|
||||||
def type(self):
|
def type(self):
|
||||||
@ -324,6 +329,10 @@ class SpecialTransaction(Transaction):
|
|||||||
raise(ValidationError(_("A special transaction is only possible between a"
|
raise(ValidationError(_("A special transaction is only possible between a"
|
||||||
" Note associated to a payment method and a User or a Club")))
|
" 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:
|
class Meta:
|
||||||
verbose_name = _("Special transaction")
|
verbose_name = _("Special transaction")
|
||||||
verbose_name_plural = _("Special transactions")
|
verbose_name_plural = _("Special transactions")
|
||||||
|
@ -226,7 +226,6 @@ function consume(source, source_alias, dest, quantity, amount, reason, type, cat
|
|||||||
"source": source.id,
|
"source": source.id,
|
||||||
"source_alias": source_alias,
|
"source_alias": source_alias,
|
||||||
"destination": dest,
|
"destination": dest,
|
||||||
"category": category,
|
|
||||||
"template": template
|
"template": template
|
||||||
})
|
})
|
||||||
.done(function () {
|
.done(function () {
|
||||||
@ -259,7 +258,6 @@ function consume(source, source_alias, dest, quantity, amount, reason, type, cat
|
|||||||
"source": source,
|
"source": source,
|
||||||
"source_alias": source_alias,
|
"source_alias": source_alias,
|
||||||
"destination": dest,
|
"destination": dest,
|
||||||
"category": category,
|
|
||||||
"template": template
|
"template": template
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
reset();
|
reset();
|
||||||
|
Loading…
Reference in New Issue
Block a user