hberp/hb_server/apps/em/models.py

89 lines
3.4 KiB
Python

from django.db import models
from django.contrib.auth.models import AbstractUser
from django.db.models.base import Model
import django.utils.timezone as timezone
from django.db.models.query import QuerySet
from apps.system.models import CommonADModel, CommonAModel, CommonBModel, Organization, User, Dict, File
from utils.model import SoftModel, BaseModel
from simple_history.models import HistoricalRecords
class Equipment(CommonAModel):
"""
设备台账信息
"""
EQUIP_STATE_OK = 10
EQUIP_STATE_LIMIT = 20
EQUIP_STATE_FIX = 30
EQUIP_STATE_DISABLE = 40
EQUIP_STATE_scrap = 50
state_choices = (
(EQUIP_STATE_OK, '完好'),
(EQUIP_STATE_LIMIT, '限用'),
(EQUIP_STATE_FIX, '在修'),
(EQUIP_STATE_DISABLE, '禁用'),
(EQUIP_STATE_scrap, '报废')
)
state2_choices = (
(EQUIP_STATE_OK, '合格'),
(EQUIP_STATE_DISABLE, '禁用')
)
EQUIP_TYPE_PRO = 1
EQUIP_TYPE_TEST = 2
type_choices = (
(1, '生产设备'),
(2, '检验工具')
)
mgmtype_choices = (
(1, 'A'),
(2, 'B'),
(3, 'C')
)
way_choices = (
(1, '外检'),
(2, '自检'),
)
usetype_choices = (
(1, '专用'),
(2, '公用'),
)
type = models.IntegerField('类型', choices=type_choices, default=1)
name = models.CharField('设备名称', max_length=50)
number = models.CharField('设备编号', max_length=50, unique=True)
model = models.CharField('规格型号', max_length=60, null=True, blank=True)
factory = models.CharField('生产厂', max_length=50, null=True, blank=True)
production_date = models.DateField('生产日期', null=True, blank=True)
buy_date = models.DateField('购置日期', null=True, blank=True)
state = models.PositiveIntegerField('设备状态', choices=state_choices, default=0)
parameter = models.TextField('技术参数', null=True, blank=True)
place = models.CharField('存放位置', max_length=50, null=True, blank=True)
count = models.IntegerField('数量', default=0)
keeper = models.ForeignKey(User, verbose_name='保管人', on_delete=models.CASCADE, null=True, blank=True)
description = models.CharField('描述', max_length=200, blank=True, null=True)
# 以下是监视测量设备单独字段
mgmtype = models.IntegerField('管理类别', choices=mgmtype_choices, default=1)
way = models.IntegerField('校准或检定方式', choices=way_choices, default=1)
standard = models.CharField('溯源标准或依据', max_length=200, blank=True, null=True)
cycle = models.IntegerField('校准或检定周期(月)', null=True, blank=True)
usetype = models.IntegerField('使用类别', choices=usetype_choices, default=1)
check_date = models.DateField('最近校准检查日期', blank=True, null=True)
next_check_date = models.DateField('预计下次校准检查日期',blank=True, null=True)
class Meta:
verbose_name = '设备信息'
verbose_name_plural = verbose_name
def __str__(self):
return self.number + '-' + self.name
class ECheckRecord(CommonADModel):
"""
校准鉴定记录
"""
equipment = models.ForeignKey(Equipment, verbose_name='校准检定设备', on_delete=models.CASCADE)
check_date = models.DateField('校准检查日期')
description = models.CharField('描述', max_length=200, blank=True, null=True)