mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-11-26 18:37:12 +00:00
Transaction types are now properties
This commit is contained in:
parent
7313e5a337
commit
4909a7f09c
@ -7,7 +7,7 @@ from django.utils import timezone
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from polymorphic.models import PolymorphicModel
|
from polymorphic.models import PolymorphicModel
|
||||||
|
|
||||||
from .notes import Note, NoteClub
|
from .notes import Note, NoteClub, NoteSpecial
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Defines transactions
|
Defines transactions
|
||||||
@ -111,20 +111,6 @@ class Transaction(PolymorphicModel):
|
|||||||
verbose_name=_('amount'),
|
verbose_name=_('amount'),
|
||||||
)
|
)
|
||||||
|
|
||||||
type = models.CharField(
|
|
||||||
verbose_name=_('type'),
|
|
||||||
choices=(
|
|
||||||
('gift', _('Gift')),
|
|
||||||
('transfer', _('Transfer')),
|
|
||||||
('template', _('Template')),
|
|
||||||
('credit', _('Credit')),
|
|
||||||
('debit', _('Debit')),
|
|
||||||
('membership', _('membership transaction')),
|
|
||||||
),
|
|
||||||
default='transfer',
|
|
||||||
max_length=10,
|
|
||||||
)
|
|
||||||
|
|
||||||
reason = models.CharField(
|
reason = models.CharField(
|
||||||
verbose_name=_('reason'),
|
verbose_name=_('reason'),
|
||||||
max_length=255,
|
max_length=255,
|
||||||
@ -175,6 +161,10 @@ class Transaction(PolymorphicModel):
|
|||||||
def total(self):
|
def total(self):
|
||||||
return self.amount * self.quantity
|
return self.amount * self.quantity
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type(self):
|
||||||
|
return _('Transfer')
|
||||||
|
|
||||||
|
|
||||||
class TemplateTransaction(Transaction):
|
class TemplateTransaction(Transaction):
|
||||||
"""
|
"""
|
||||||
@ -191,6 +181,10 @@ class TemplateTransaction(Transaction):
|
|||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type(self):
|
||||||
|
return _('Template')
|
||||||
|
|
||||||
|
|
||||||
class SpecialTransaction(Transaction):
|
class SpecialTransaction(Transaction):
|
||||||
"""
|
"""
|
||||||
@ -213,6 +207,10 @@ class SpecialTransaction(Transaction):
|
|||||||
blank=True,
|
blank=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type(self):
|
||||||
|
return _('Credit') if isinstance(self.source, NoteSpecial) else _("Debit")
|
||||||
|
|
||||||
|
|
||||||
class MembershipTransaction(Transaction):
|
class MembershipTransaction(Transaction):
|
||||||
"""
|
"""
|
||||||
@ -229,3 +227,7 @@ class MembershipTransaction(Transaction):
|
|||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("membership transaction")
|
verbose_name = _("membership transaction")
|
||||||
verbose_name_plural = _("membership transactions")
|
verbose_name_plural = _("membership transactions")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type(self):
|
||||||
|
return _('membership transaction')
|
||||||
|
@ -193,7 +193,6 @@ function consume(source, dest, quantity, amount, reason, type, category, templat
|
|||||||
"valid": true,
|
"valid": true,
|
||||||
"polymorphic_ctype": type,
|
"polymorphic_ctype": type,
|
||||||
"resourcetype": "TemplateTransaction",
|
"resourcetype": "TemplateTransaction",
|
||||||
"type": "template",
|
|
||||||
"source": source,
|
"source": source,
|
||||||
"destination": dest,
|
"destination": dest,
|
||||||
"category": category,
|
"category": category,
|
||||||
|
@ -201,8 +201,8 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
$("#type_transfer").removeAttr('checked');
|
$("#type_transfer").removeAttr('checked');
|
||||||
$("#type_credit").removeAttr('checked');
|
$("#type_credit").removeAttr('checked');
|
||||||
$("#type_debit").removeAttr('checked');
|
$("#type_debit").removeAttr('checked');
|
||||||
$("label[for='type_gift']").attr('class', 'btn btn-sm btn-outline-primary');
|
|
||||||
$("label[for='type_transfer']").attr('class', 'btn btn-sm btn-outline-primary');
|
$("label[for='type_transfer']").attr('class', 'btn btn-sm btn-outline-primary');
|
||||||
|
$("label[for='type_credit']").attr('class', 'btn btn-sm btn-outline-primary');
|
||||||
$("label[for='type_debit']").attr('class', 'btn btn-sm btn-outline-primary');
|
$("label[for='type_debit']").attr('class', 'btn btn-sm btn-outline-primary');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -246,7 +246,6 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
"valid": true,
|
"valid": true,
|
||||||
"polymorphic_ctype": {{ polymorphic_ctype }},
|
"polymorphic_ctype": {{ polymorphic_ctype }},
|
||||||
"resourcetype": "Transaction",
|
"resourcetype": "Transaction",
|
||||||
"type": "gift",
|
|
||||||
"source": {{ user.note.id }},
|
"source": {{ user.note.id }},
|
||||||
"destination": dest.id
|
"destination": dest.id
|
||||||
}, function () {
|
}, function () {
|
||||||
@ -276,7 +275,6 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
"valid": true,
|
"valid": true,
|
||||||
"polymorphic_ctype": {{ polymorphic_ctype }},
|
"polymorphic_ctype": {{ polymorphic_ctype }},
|
||||||
"resourcetype": "Transaction",
|
"resourcetype": "Transaction",
|
||||||
"type": "transfer",
|
|
||||||
"source": source.id,
|
"source": source.id,
|
||||||
"destination": dest.id
|
"destination": dest.id
|
||||||
}, function () {
|
}, function () {
|
||||||
@ -298,11 +296,10 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
let special_note = $("#credit_type").val();
|
let special_note = $("#credit_type").val();
|
||||||
let user_note = dests_notes_display[0].id;
|
let user_note = dests_notes_display[0].id;
|
||||||
let given_reason = $("#reason").val();
|
let given_reason = $("#reason").val();
|
||||||
let source, dest, reason, type;
|
let source, dest, reason;
|
||||||
if ($("#type_credit").is(':checked')) {
|
if ($("#type_credit").is(':checked')) {
|
||||||
source = special_note;
|
source = special_note;
|
||||||
dest = user_note;
|
dest = user_note;
|
||||||
type = "credit";
|
|
||||||
reason = "Crédit " + $("#credit_type option:selected").text().toLowerCase();
|
reason = "Crédit " + $("#credit_type option:selected").text().toLowerCase();
|
||||||
if (given_reason.length > 0)
|
if (given_reason.length > 0)
|
||||||
reason += " (" + given_reason + ")";
|
reason += " (" + given_reason + ")";
|
||||||
@ -324,7 +321,6 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
"valid": true,
|
"valid": true,
|
||||||
"polymorphic_ctype": {{ special_polymorphic_ctype }},
|
"polymorphic_ctype": {{ special_polymorphic_ctype }},
|
||||||
"resourcetype": "SpecialTransaction",
|
"resourcetype": "SpecialTransaction",
|
||||||
"type": type,
|
|
||||||
"source": source,
|
"source": source,
|
||||||
"destination": dest,
|
"destination": dest,
|
||||||
"last_name": $("#last_name").val(),
|
"last_name": $("#last_name").val(),
|
||||||
|
Loading…
Reference in New Issue
Block a user