coding utf-8 from django db import models from django contrib auth mod

  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
# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
from django.newforms import ValidationError
from django import newforms as forms
from django.newforms import form_for_model
from check_constraints import Check
from datetime import date
import datetime
TYPE_CHOICES = (
('A', u'Приход'),
('D', u'Расход'),
)
class HandBookManufacturer(models.Model):
manufacturer = models.CharField(u'Производитель',maxlength=20, unique=True)
def __unicode__(self):
return '%s' % (self.manufacturer)
class Admin:
pass
class HandBookModel(models.Model):
handbookmanufacturer = models.ForeignKey(HandBookManufacturer, verbose_name=u"Производитель")
article = models.CharField(u'Артикул',maxlength=15, unique=True)
all_quantity = models.IntegerField(u'Количество', null=True, editable=False, default=0)
class Meta:
constraints = (
("check_all_quantity", Check(all_quantity__gte = 0)),
)
def __unicode__(self):
return '%s, %s' % (self.handbookmanufacturer.manufacturer, self.article)
class Admin:
pass
class Sklad(models.Model):
handbookmodel = models.ForeignKey(HandBookModel)
compbill = models.ForeignKey('CompBill',verbose_name=u"Состав накладной")
def save(self):
super(Sklad, self).save()
if self.compbill.type_effects == 'A':
if self.handbookmodel.all_quantity is None:
self.handbookmodel.all_quantity += self.compbill.quantity_numberbill
else:
self.handbookmodel.all_quantity += self.compbill.quantity_numberbill
else:
self.handbookmodel.all_quantity -= self.compbill.quantity_numberbill
return super(HandBookModel, self.handbookmodel).save()
def __unicode__(self):
return u'Модель %s, c количеством %d' % (self.handbookmodel.article, self.compbill.quantity_numberbill)
class Admin:
pass
class CompBill(models.Model):
quantity_numberbill = models.IntegerField(u'Количество')
bill = models.ForeignKey('Bill', unique=True, verbose_name=u"Накладная")
type_effects = models.CharField(u'Тип записи',max_length=1, choices=TYPE_CHOICES)
class Meta:
constraints = (
("check_quantity_numberbill", Check(quantity_numberbill__gte = 0)),
)
def __unicode__(self):
return '%d' % (self.bill.number_bill)
class Admin:
pass
class Bill(models.Model):
number_bill = models.AutoField(u'Номер накладной','ID', primary_key=True)
date_number_bill = models.DateField(u'Дата накладной', help_text="Формат даты: <em>YYYY-MM-DD</em>.")
user = models.ForeignKey(User, verbose_name=u"Пользователь")
def was_published_today(self):
return self.date_number_bill.date() == datetime.date.today()
# class Meta:
# constraints = (
# ("check_date_pub",Check(date_number_bill__between = [date(2006,01,01),date(2008,01,01)])),
# )
def __unicode__(self):
return '%d' % (self.number_bill)
class Admin:
pass
class OrderReserve(models.Model):
handbookmodel = models.OneToOneField(HandBookModel, verbose_name=u"Модель")
reserving = models.ManyToManyField('Reserving', verbose_name=u"Заявки на резеревирование")
all_quantity_reserve = models.IntegerField(u'Общее количества резерва', null=True, editable=False, default=0)
class Meta:
constraints = (
("check_all_quantity_reserve", Check(all_quantity_reserve__gte = 0)),
)
def save(self):
super(OrderReserve, self).save()
self.all_quantity_reserve = sum(map(lambda x: x.quantity_reserve,self.reserving.all()))
return super(OrderReserve, self).save()
def was_published_today(self):
return self.date_pub.date() == datetime.date.today()
def __unicode__(self):
return '%d' % (self.all_quantity_reserve)
class Admin:
pass
class Reserving(models.Model):
date_pub = models.DateField(u'Дата заявки', help_text="Формат даты: <em>YYYY-MM-DD</em>.")
quantity_reserve = models.IntegerField(u'Количество позиций для резерва')
user = models.ForeignKey(User, verbose_name=u"Пользователь")
class Meta:
constraints = (
("check_quantity_reseve", Check(quantity_reserve__gt = 0)),
# ("check_date_pub",Check(date_pub__between = [date(2007,1,1),date(2008,1,1)])),
)
def __unicode__(self):
return '%d' % (self.quantity_reserve)
class Admin:
pass