8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-27 01:13:46 +00:00

Change le schéma, les ventes effectuées sont maintenant un object à part

This commit is contained in:
Gabriel Detraz 2016-07-11 22:52:55 +02:00
parent d75911794f
commit 684a44aae0
5 changed files with 67 additions and 11 deletions

View file

@ -1,9 +1,12 @@
from django.contrib import admin from django.contrib import admin
from .models import Facture, Article, Banque, Paiement, Cotisation from .models import Facture, Article, Banque, Paiement, Cotisation, Vente
class FactureAdmin(admin.ModelAdmin): class FactureAdmin(admin.ModelAdmin):
list_display = ('user','paiement','name', 'number','prix', 'date','valid') list_display = ('user','paiement','number', 'date','valid')
class VenteAdmin(admin.ModelAdmin):
list_display = ('facture','name','prix','cotisation','duration')
class ArticleAdmin(admin.ModelAdmin): class ArticleAdmin(admin.ModelAdmin):
list_display = ('name','prix','cotisation','duration') list_display = ('name','prix','cotisation','duration')
@ -24,4 +27,5 @@ admin.site.register(Facture, FactureAdmin)
admin.site.register(Article, ArticleAdmin) admin.site.register(Article, ArticleAdmin)
admin.site.register(Banque, BanqueAdmin) admin.site.register(Banque, BanqueAdmin)
admin.site.register(Paiement, PaiementAdmin) admin.site.register(Paiement, PaiementAdmin)
admin.site.register(Vente, VenteAdmin)
admin.site.register(Cotisation, CotisationAdmin) admin.site.register(Cotisation, CotisationAdmin)

View file

@ -42,8 +42,6 @@ class EditFactureForm(NewFactureForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(EditFactureForm, self).__init__(*args, **kwargs) super(EditFactureForm, self).__init__(*args, **kwargs)
self.fields['user'].label = 'Adherent' self.fields['user'].label = 'Adherent'
self.fields['name'].label = 'Designation'
self.fields['prix'].label = 'Prix unitaire'
self.fields['user'].empty_label = "Séléctionner l'adhérent propriétaire" self.fields['user'].empty_label = "Séléctionner l'adhérent propriétaire"
self.fields.pop('article') self.fields.pop('article')

View file

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('cotisations', '0012_auto_20160704_0118'),
]
operations = [
migrations.CreateModel(
name='Vente',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('prix', models.DecimalField(decimal_places=2, max_digits=5)),
('cotisation', models.BooleanField()),
('duration', models.IntegerField(null=True, blank=True, help_text='Durée exprimée en mois entiers')),
],
),
migrations.RemoveField(
model_name='facture',
name='name',
),
migrations.RemoveField(
model_name='facture',
name='prix',
),
migrations.AddField(
model_name='vente',
name='facture',
field=models.ForeignKey(to='cotisations.Facture', on_delete=django.db.models.deletion.PROTECT),
),
]

View file

@ -8,12 +8,28 @@ class Facture(models.Model):
cheque = models.CharField(max_length=255, blank=True) cheque = models.CharField(max_length=255, blank=True)
number = models.IntegerField() number = models.IntegerField()
date = models.DateTimeField(auto_now_add=True) date = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=255)
prix = models.DecimalField(max_digits=5, decimal_places=2)
valid = models.BooleanField(default=True) valid = models.BooleanField(default=True)
def prix(self):
prix = Vente.objects.all().filter(facture=self).aggregate(models.Sum('prix'))['prix__sum']
return prix
def name(self):
name = ' - '.join(vente.name for vente in Vente.objects.all().filter(facture=self))
return name
def __str__(self): def __str__(self):
return str(self.name) + ' ' + str(self.date) + ' ' + str(self.user) return str(self.date) + ' ' + str(self.user)
class Vente(models.Model):
facture = models.ForeignKey('Facture', on_delete=models.PROTECT)
name = models.CharField(max_length=255)
prix = models.DecimalField(max_digits=5, decimal_places=2)
cotisation = models.BooleanField()
duration = models.IntegerField(help_text="Durée exprimée en mois entiers", blank=True, null=True)
def __str__(self):
return str(self.name) + ' ' + str(self.facture)
class Article(models.Model): class Article(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)

View file

@ -9,7 +9,7 @@ from django.contrib.auth.decorators import login_required, permission_required
from django.contrib import messages from django.contrib import messages
from django.db.models import Max, ProtectedError from django.db.models import Max, ProtectedError
from .models import Facture, Article, Cotisation, Paiement, Banque from .models import Facture, Article, Vente, Cotisation, Paiement, Banque
from .forms import NewFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm, NewFactureFormPdf from .forms import NewFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm, NewFactureFormPdf
from users.models import User from users.models import User
from .tex import render_tex from .tex import render_tex
@ -47,9 +47,10 @@ def new_facture(request, userid):
if facture_form.is_valid(): if facture_form.is_valid():
new_facture = facture_form.save(commit=False) new_facture = facture_form.save(commit=False)
article = facture_form.cleaned_data['article'] article = facture_form.cleaned_data['article']
new_facture.prix = sum(art.prix for art in article)
new_facture.name = ' - '.join(art.name for art in article)
new_facture.save() new_facture.save()
for art in article:
new_vente = Vente.objects.create(facture=new_facture, name=art.name, prix=art.prix, cotisation=art.cotisation, duration=art.duration)
new_vente.save()
if any(art.cotisation for art in article): if any(art.cotisation for art in article):
duration = sum(art.duration*facture.number for art in article if art.cotisation) duration = sum(art.duration*facture.number for art in article if art.cotisation)
create_cotis(new_facture, user, duration) create_cotis(new_facture, user, duration)
@ -76,7 +77,6 @@ def new_facture_pdf(request):
return render_tex(request, 'cotisations/factures.tex', {'DATE' : timezone.now(),'dest':destinataire, 'obj':objet, 'detail':detail, 'article':tbl, 'total':prix_total, 'paid':paid, 'asso_name':ASSO_NAME, 'line1':ASSO_ADDRESS_LINE1, 'line2':ASSO_ADDRESS_LINE2, 'siret':ASSO_SIRET, 'email':ASSO_EMAIL, 'phone':ASSO_PHONE}) return render_tex(request, 'cotisations/factures.tex', {'DATE' : timezone.now(),'dest':destinataire, 'obj':objet, 'detail':detail, 'article':tbl, 'total':prix_total, 'paid':paid, 'asso_name':ASSO_NAME, 'line1':ASSO_ADDRESS_LINE1, 'line2':ASSO_ADDRESS_LINE2, 'siret':ASSO_SIRET, 'email':ASSO_EMAIL, 'phone':ASSO_PHONE})
return form({'factureform': facture_form}, 'cotisations/facture.html', request) return form({'factureform': facture_form}, 'cotisations/facture.html', request)
@login_required
@permission_required('cableur') @permission_required('cableur')
def edit_facture(request, factureid): def edit_facture(request, factureid):
try: try: