[#1862] Ajout de managers et d'une représentation unicode à Element
[auf_django_coda.git] / auf / django / coda / models.py
1 # encoding: utf-8
2
3 from django.conf import settings
4 from django.db import models
5
6 class ElementManager(models.Manager):
7
8 def __init__(self, niveau):
9 super(ElementManager, self).__init__()
10 self.niveau = niveau
11
12 def get_query_set(self):
13 qs = super(ElementManager, self).get_query_set()
14 return qs.filter(niveau=self.niveau)
15
16
17 class Element(models.Model):
18 id = models.CharField(max_length=74, primary_key=True)
19 niveau = models.IntegerField()
20 code = models.CharField(max_length=72, db_index=True)
21 date_modification = models.DateField()
22 nom = models.CharField(max_length=36)
23
24 # Managers
25 objects = models.Manager()
26 comptes_comptables = ElementManager(1)
27 tiers_operations = ElementManager(2)
28 projets_postes = ElementManager(3)
29
30 class Meta:
31 managed = False
32 db_table = 'coda_element'
33
34 def __unicode__(self):
35 return self.code
36
37 class Ecriture(models.Model):
38 id = models.CharField(max_length=25, primary_key=True)
39 code = models.CharField(max_length=12)
40 numero = models.CharField(max_length=12)
41 date_modification = models.DateField()
42 periode = models.IntegerField()
43 annee = models.IntegerField()
44 date = models.DateField()
45
46 class Meta:
47 managed = False
48 db_table = 'coda_ecriture'
49
50
51 class LigneEcriture(models.Model):
52 DEBIT_CREDIT_CHOICES = (
53 ('D', 'Débit'),
54 ('C', 'Crédit'),
55 )
56 ETAT_PAIEMENT_CHOICES = (
57 ('D', 'D-Disponible'),
58 ('A', 'A-Attente'),
59 ('X', 'X-Fermé (non-lettrable)'),
60 ('P', 'P-Payé'),
61 ('O', 'O-Proposé'),
62 )
63
64 id = models.CharField(max_length=36, primary_key=True)
65 ecriture = models.ForeignKey(Ecriture, related_name='doclines')
66 numero = models.IntegerField()
67 date_modification = models.DateField()
68 compte_comptable = models.ForeignKey(Element, related_name='+')
69 tiers_operation = models.ForeignKey(Element, related_name='+')
70 projet_poste = models.ForeignKey(Element, related_name='+')
71 description = models.CharField(max_length=36)
72 montant_eur = models.DecimalField(max_digits=17, decimal_places=2)
73 debit_credit = models.CharField(max_length=1, choices=DEBIT_CREDIT_CHOICES)
74 numero_facture = models.CharField(max_length=32)
75 numero_avoir = models.CharField(max_length=32)
76 implantation = models.CharField(max_length=32)
77 salarie = models.CharField(max_length=32)
78 numero_cheque = models.CharField(max_length=32)
79 etat_paiement = models.CharField(max_length=1, choices=ETAT_PAIEMENT_CHOICES)
80
81 class Meta:
82 managed = False
83 db_table = 'coda_ligne_ecriture'