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 CommonAModel, CommonBModel, Organization, User, Dict, File
from utils.model import SoftModel, BaseModel
from simple_history.models import HistoricalRecords



class Equipment(CommonBModel):
    """
    设备台账信息
    """
    state_choices = (
        (1, '运转正常'),
        (0, '停用'),
        (2, '报废')
    )
    type_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.CharField('设备状态', max_length=11, choices=state_choices, default=1)
    parameter = models.TextField('技术参数', null=True, blank=True)
    place = models.CharField('存放位置', max_length=50, null=True, blank=True)
    keeper = models.ForeignKey(User, verbose_name='保管人', on_delete=models.CASCADE, null=True, blank=True)
    description = models.CharField('描述', max_length=200, blank=True, null=True)

    class Meta:
        verbose_name = '设备信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.number + '-' + self.name
    