-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
153 lines (121 loc) · 4.4 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from __future__ import unicode_literals
from django.db import models
# from django.utils import timezone
# from django.db.models import Q
# Create your models here.
# Costanti
default_um = 1
class Anagrafica(models.Model):
nome = models.CharField(max_length=200)
mail = models.EmailField(max_length=200)
riferimento = models.CharField(max_length=200)
tel = models.CharField(max_length=200)
addr = models.CharField(max_length=200, blank=True, null=True)
note = models.TextField(blank=True, null=True)
def __str__(self):
return self.nome
class Prezzi(models.Model):
comm = models.ForeignKey('formulari.Anagrafica')
mat = models.ForeignKey('formulari.Materiali')
valore = models.CharField(max_length=200)
data = models.DateField(blank=True, null=True)
note = models.TextField(blank=True, null=True)
um = models.ForeignKey('formulari.Um', default=default_um)
autore = models.ForeignKey('auth.User', default=default_um)
def __unicode__(self):
return "%s \u20ac/%s" % (self.valore, self.um)
def alla_ton(self):
if self.um_id == 1:
res = float(self.valore)
elif self.um_id == 3:
res = (float(self.valore)*10)
elif self.um_id == 2:
res = (float(self.valore)*1000)
else:
res = (float(self.valore)*0)
return res
class Formulari(models.Model):
APERTO = 'AP'
RIEPI = 'RP'
CHIUSO = 'CH'
ERRORE = 'ER'
INATTIVO = 'IA'
NODOCS = 'ND'
SCELTA_STATO = (
(APERTO, 'Aperto'),
(RIEPI, 'Riepilogato'),
(CHIUSO, 'Chiuso'),
(ERRORE, 'Errore'),
(INATTIVO, 'Inattivo'),
(NODOCS, 'No Documenti'),
)
comm = models.ForeignKey('formulari.Anagrafica')
cod = models.CharField(max_length=200)
data = models.DateField()
prod = models.ForeignKey('formulari.Produttori', default=default_um)
mat = models.ForeignKey('formulari.Materiali', default=default_um)
prez = models.FloatField()
qu = models.FloatField()
imp = models.FloatField(blank=True, null=True)
um = models.ForeignKey('formulari.Um', default=default_um)
ripa = models.ForeignKey('formulari.Ripartizioni')
autore = models.ForeignKey('auth.User', default=default_um)
stato = models.CharField(
max_length=2, choices=SCELTA_STATO, default=APERTO,)
riepi = models.ForeignKey('formulari.Riepiloghi',
models.SET_NULL, blank=True, null=True,)
def __str__(self):
return self.cod
def importo(self):
return "%s \u20ac" % (self.prez * self.qu)
def importop(self):
return (self.prez * self.qu)
def prezzo(self):
return "%s \u20ac/%s" % (self.prez, self.um)
def quantita(self):
return "%s %s" % (self.qu, self.um)
class Materiali(models.Model):
mat = models.CharField(max_length=200)
cod = models.CharField(max_length=200)
def __str__(self):
return "%s %s" % (self.mat, self.cod)
class Produttori(models.Model):
nome = models.CharField(max_length=200)
mail = models.CharField(max_length=200)
riferimento = models.CharField(max_length=200)
tel = models.CharField(max_length=200)
note = models.TextField(blank=True, null=True)
def __str__(self):
return self.nome
class Ripartizioni(models.Model):
nome = models.CharField(max_length=200)
mail = models.EmailField(max_length=200)
riferimento = models.CharField(max_length=200)
tel = models.CharField(max_length=200)
note = models.TextField(blank=True, null=True)
def __unicode__(self):
return self.nome
class Um(models.Model):
nome = models.CharField(max_length=2)
def __str__(self):
return self.nome
class Riepiloghi(models.Model):
PRONTO = 'PR'
INVIATO = 'IN'
PAGATO = 'PA'
ERRORE = 'ER'
SCELTA_STATO = (
(PRONTO, 'Pronto'),
(INVIATO, 'Inviato'),
(PAGATO, 'Pagato'),
(ERRORE, 'Errore'),
)
comm = models.ForeignKey('formulari.Anagrafica')
data = models.DateField()
autore = models.ForeignKey('auth.User', default=default_um)
doc = models.FileField(upload_to='upld/riepiloghi/', blank=True, null=True)
ric = models.FileField(upload_to='upld/ricevute/', blank=True, null=True)
stato = models.CharField(
max_length=2, choices=SCELTA_STATO, default=PRONTO,)
def __str__(self):
return "R.%s di %s" % (self.pk, self.comm)