mirror of https://gitlab.federez.net/re2o/re2o
9 changed files with 128 additions and 61 deletions
@ -0,0 +1,41 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Generated by Django 1.10.7 on 2018-07-03 13:53 |
||||
|
from __future__ import unicode_literals |
||||
|
|
||||
|
import cotisations.payment_methods.mixins |
||||
|
from django.db import migrations, models |
||||
|
import django.db.models.deletion |
||||
|
|
||||
|
|
||||
|
def add_solde(apps, schema_editor): |
||||
|
OptionalUser = apps.get_model('preferences', 'OptionalUser') |
||||
|
options, _created = OptionalUser.objects.get_or_create() |
||||
|
|
||||
|
Payment = apps.get_model('cotisations', 'Paiement') |
||||
|
BalancePayment = apps.get_model('cotisations', 'BalancePayment') |
||||
|
|
||||
|
solde, _created = Payment.objects.get_or_create(moyen="solde") |
||||
|
balance = BalancePayment() |
||||
|
balance.payment = solde |
||||
|
balance.minimum_balance = options.solde_negatif |
||||
|
balance.save() |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('cotisations', '0032_chequepayment_comnpaypayment'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.CreateModel( |
||||
|
name='BalancePayment', |
||||
|
fields=[ |
||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
|
('minimum_balance', models.DecimalField(decimal_places=2, help_text='The minimal amount of money allowed for the balance at the end of a payment. You can specify negative amount.', max_digits=5, verbose_name='Minimum balance')), |
||||
|
('payment', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method', to='cotisations.Paiement')), |
||||
|
], |
||||
|
bases=(cotisations.payment_methods.mixins.PaymentMethodMixin, models.Model), |
||||
|
), |
||||
|
migrations.RunPython(add_solde) |
||||
|
] |
||||
@ -1,6 +1,7 @@ |
|||||
from . import comnpay, cheque, urls |
from . import comnpay, cheque, balance, urls |
||||
|
|
||||
PAYMENT_METHODS = [ |
PAYMENT_METHODS = [ |
||||
comnpay, |
comnpay, |
||||
cheque, |
cheque, |
||||
|
balance, |
||||
] |
] |
||||
|
|||||
Binary file not shown.
@ -0,0 +1,7 @@ |
|||||
|
""" |
||||
|
This module contains a method to pay online using user balance. |
||||
|
""" |
||||
|
from . import models |
||||
|
NAME = "BALANCE" |
||||
|
|
||||
|
PaymentMethod = models.BalancePayment |
||||
@ -0,0 +1,50 @@ |
|||||
|
from django.db import models |
||||
|
from django.shortcuts import redirect |
||||
|
from django.urls import reverse |
||||
|
from django.utils.translation import ugettext as _ |
||||
|
from django.utils.translation import ugettext_lazy as _l |
||||
|
from django.contrib import messages |
||||
|
|
||||
|
|
||||
|
from cotisations.models import Paiement |
||||
|
from cotisations.payment_methods.mixins import PaymentMethodMixin |
||||
|
|
||||
|
|
||||
|
class BalancePayment(PaymentMethodMixin, models.Model): |
||||
|
""" |
||||
|
The model allowing you to pay with a cheque. |
||||
|
""" |
||||
|
payment = models.OneToOneField( |
||||
|
Paiement, |
||||
|
related_name='payment_method', |
||||
|
editable=False |
||||
|
) |
||||
|
minimum_balance = models.DecimalField( |
||||
|
verbose_name=_l("Minimum balance"), |
||||
|
help_text=_l("The minimal amount of money allowed for the balance" |
||||
|
" at the end of a payment. You can specify negative " |
||||
|
"amount." |
||||
|
), |
||||
|
max_digits=5, |
||||
|
decimal_places=2, |
||||
|
) |
||||
|
|
||||
|
def end_payment(self, invoice, request): |
||||
|
user = invoice.user |
||||
|
total_price = invoice.prix_total() |
||||
|
if float(user.solde) - float(total_price) < self.minimum_balance: |
||||
|
invoice.valid = False |
||||
|
invoice.save() |
||||
|
messages.error( |
||||
|
request, |
||||
|
_("Your balance is too low for this operation.") |
||||
|
) |
||||
|
return redirect(reverse( |
||||
|
'users:profil', |
||||
|
kwargs={'userid': user.id} |
||||
|
)) |
||||
|
return invoice.paiement.end_payment( |
||||
|
invoice, |
||||
|
request, |
||||
|
use_payment_method=False |
||||
|
) |
||||
Loading…
Reference in new issue