Renamed BankTransfer payment method to DirectDebt

This commit is contained in:
Marc 2014-07-29 20:25:57 +00:00
parent 6902f9e559
commit 4e90044263
4 changed files with 41 additions and 26 deletions

View file

@ -2,6 +2,7 @@ import sys
from django.contrib import messages from django.contrib import messages
from django.db import transaction from django.db import transaction
from django.utils.translation import ugettext_lazy as _
from orchestra.admin.decorators import action_with_confirmation from orchestra.admin.decorators import action_with_confirmation
@ -23,25 +24,32 @@ def change_ticket_state_factory(action, final_state):
reason = form.cleaned_data['reason'] reason = form.cleaned_data['reason']
for ticket in queryset: for ticket in queryset:
if ticket.state != final_state: if ticket.state != final_state:
changes = {'state': (ticket.state, final_state)} changes = {
'state': (ticket.state, final_state)
}
is_read = ticket.is_read_by(request.user) is_read = ticket.is_read_by(request.user)
getattr(ticket, action)() getattr(ticket, action)()
modeladmin.log_change(request, ticket, "Marked as %s" % final_state.lower()) msg = _("Marked as %s") % final_state.lower()
modeladmin.log_change(request, ticket, msg)
content = markdown_formated_changes(changes) content = markdown_formated_changes(changes)
content += reason content += reason
ticket.messages.create(content=content, author=request.user) ticket.messages.create(content=content, author=request.user)
if is_read and not ticket.is_read_by(request.user): if is_read and not ticket.is_read_by(request.user):
ticket.mark_as_read_by(request.user) ticket.mark_as_read_by(request.user)
msg = "%s selected tickets are now %s." % (queryset.count(), final_state.lower()) context = {
'count': queryset.count(),
'state': final_state.lower()
}
msg = _("%s selected tickets are now %s.") % context
modeladmin.message_user(request, msg) modeladmin.message_user(request, msg)
else: else:
context['form'] = form context['form'] = form
# action_with_confirmation must display form validation errors # action_with_confirmation must display form validation errors
return True return True
change_ticket_state.url_name = action change_ticket_state.url_name = action
change_ticket_state.verbose_name = u'%s\u2026' % action change_ticket_state.verbose_name = action
change_ticket_state.short_description = '%s selected tickets' % action.capitalize() change_ticket_state.short_description = _('%s selected tickets') % action.capitalize()
change_ticket_state.description = 'Mark ticket as %s.' % final_state.lower() change_ticket_state.description = _('Mark ticket as %s.') % final_state.lower()
change_ticket_state.__name__ = action change_ticket_state.__name__ = action
return change_ticket_state return change_ticket_state
@ -49,7 +57,8 @@ def change_ticket_state_factory(action, final_state):
action_map = { action_map = {
Ticket.RESOLVED: 'resolve', Ticket.RESOLVED: 'resolve',
Ticket.REJECTED: 'reject', Ticket.REJECTED: 'reject',
Ticket.CLOSED: 'close' } Ticket.CLOSED: 'close'
}
thismodule = sys.modules[__name__] thismodule = sys.modules[__name__]
@ -62,19 +71,25 @@ for state, name in action_map.items():
def take_tickets(modeladmin, request, queryset): def take_tickets(modeladmin, request, queryset):
for ticket in queryset: for ticket in queryset:
if ticket.owner != request.user: if ticket.owner != request.user:
changes = {'owner': (ticket.owner, request.user)} changes = {
'owner': (ticket.owner, request.user)
}
is_read = ticket.is_read_by(request.user) is_read = ticket.is_read_by(request.user)
ticket.take(request.user) ticket.take(request.user)
modeladmin.log_change(request, ticket, "Taken") modeladmin.log_change(request, ticket, _("Taken"))
content = markdown_formated_changes(changes) content = markdown_formated_changes(changes)
ticket.messages.create(content=content, author=request.user) ticket.messages.create(content=content, author=request.user)
if is_read and not ticket.is_read_by(request.user): if is_read and not ticket.is_read_by(request.user):
ticket.mark_as_read_by(request.user) ticket.mark_as_read_by(request.user)
msg = "%s selected tickets are now owned by %s." % (queryset.count(), request.user) context = {
'count': queryset.count(),
'user': request.user
}
msg = _("%(count)s selected tickets are now owned by %(user)s.") % context
modeladmin.message_user(request, msg) modeladmin.message_user(request, msg)
take_tickets.url_name = 'take' take_tickets.url_name = 'take'
take_tickets.short_description = 'Take selected tickets' take_tickets.short_description = _("Take selected tickets")
take_tickets.description = 'Make yourself owner of the ticket.' take_tickets.description = _("Make yourself owner of the ticket.")
@transaction.atomic @transaction.atomic
@ -82,7 +97,7 @@ def mark_as_unread(modeladmin, request, queryset):
""" Mark a tickets as unread """ """ Mark a tickets as unread """
for ticket in queryset: for ticket in queryset:
ticket.mark_as_unread_by(request.user) ticket.mark_as_unread_by(request.user)
msg = "%s selected tickets have been marked as unread." % queryset.count() msg = _("%s selected tickets have been marked as unread.") % queryset.count()
modeladmin.message_user(request, msg) modeladmin.message_user(request, msg)
@ -91,7 +106,7 @@ def mark_as_read(modeladmin, request, queryset):
""" Mark a tickets as unread """ """ Mark a tickets as unread """
for ticket in queryset: for ticket in queryset:
ticket.mark_as_read_by(request.user) ticket.mark_as_read_by(request.user)
msg = "%s selected tickets have been marked as read." % queryset.count() msg = _("%s selected tickets have been marked as read.") % queryset.count()
modeladmin.message_user(request, msg) modeladmin.message_user(request, msg)
@ -99,11 +114,11 @@ def mark_as_read(modeladmin, request, queryset):
def set_default_queue(modeladmin, request, queryset): def set_default_queue(modeladmin, request, queryset):
""" Set a queue as default issues queue """ """ Set a queue as default issues queue """
if queryset.count() != 1: if queryset.count() != 1:
messages.warning(request, "Please, select only one queue.") messages.warning(request, _("Please, select only one queue."))
return return
Queue.objects.filter(default=True).update(default=False) Queue.objects.filter(default=True).update(default=False)
queue = queryset.get() queue = queryset.get()
queue.default = True queue.default = True
queue.save() queue.save()
modeladmin.log_change(request, queue, "Chosen as default.") modeladmin.log_change(request, queue, _("Chosen as default."))
messages.info(request, "Chosen '%s' as default queue." % queue) messages.info(request, _("Chosen '%s' as default queue.") % queue)

View file

@ -6,7 +6,7 @@ from orchestra.admin.utils import admin_colored, admin_link
from orchestra.apps.accounts.admin import AccountAdminMixin from orchestra.apps.accounts.admin import AccountAdminMixin
from .actions import process_transactions from .actions import process_transactions
from .methods import BankTransfer from .methods import DirectDebit
from .models import PaymentSource, Transaction, PaymentProcess from .models import PaymentSource, Transaction, PaymentProcess
@ -35,7 +35,7 @@ class TransactionAdmin(admin.ModelAdmin):
class PaymentSourceAdmin(AccountAdminMixin, admin.ModelAdmin): class PaymentSourceAdmin(AccountAdminMixin, admin.ModelAdmin):
list_display = ('label', 'method', 'number', 'account_link', 'is_active') list_display = ('label', 'method', 'number', 'account_link', 'is_active')
list_filter = ('method', 'is_active') list_filter = ('method', 'is_active')
form = BankTransfer().get_form() form = DirectDebit().get_form()
# TODO select payment source method # TODO select payment source method

View file

@ -24,7 +24,7 @@ class PaymentSourceDataForm(forms.ModelForm):
return super(PaymentSourceDataForm, self).save(commit=commit) return super(PaymentSourceDataForm, self).save(commit=commit)
class BankTransferForm(PaymentSourceDataForm): class DirectDebitForm(PaymentSourceDataForm):
iban = IBANFormField(label='IBAN', iban = IBANFormField(label='IBAN',
widget=forms.TextInput(attrs={'size': '50'})) widget=forms.TextInput(attrs={'size': '50'}))
name = forms.CharField(max_length=128, label=_("Name"), name = forms.CharField(max_length=128, label=_("Name"),

View file

@ -13,7 +13,7 @@ from rest_framework import serializers
from orchestra.utils import plugins from orchestra.utils import plugins
from . import settings from . import settings
from .forms import BankTransferForm, CreditCardForm from .forms import DirectDebitForm, CreditCardForm
class PaymentMethod(plugins.Plugin): class PaymentMethod(plugins.Plugin):
@ -37,7 +37,7 @@ class PaymentMethod(plugins.Plugin):
return data[self.number_field] return data[self.number_field]
class BankTransferSerializer(serializers.Serializer): class DirectDebitSerializer(serializers.Serializer):
iban = serializers.CharField(label='IBAN', validators=[IBANValidator()], iban = serializers.CharField(label='IBAN', validators=[IBANValidator()],
min_length=min(IBAN_COUNTRY_CODE_LENGTH.values()), max_length=34) min_length=min(IBAN_COUNTRY_CODE_LENGTH.values()), max_length=34)
name = serializers.CharField(label=_("Name"), max_length=128) name = serializers.CharField(label=_("Name"), max_length=128)
@ -47,12 +47,12 @@ class CreditCardSerializer(serializers.Serializer):
pass pass
class BankTransfer(PaymentMethod): class DirectDebit(PaymentMethod):
verbose_name = _("Bank transfer") verbose_name = _("Direct debit")
label_field = 'name' label_field = 'name'
number_field = 'iban' number_field = 'iban'
form = BankTransferForm form = DirectDebitForm
serializer = BankTransferSerializer serializer = DirectDebitSerializer
def _process_transactions(self, transactions): def _process_transactions(self, transactions):
for transaction in transactions: for transaction in transactions: