from django.db import models
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
from apps.mtm.models import Material



class WareHouse(CommonAModel):
    """
    仓库信息
    """
    number = models.CharField('仓库编号', max_length=20, unique=True)
    name = models.CharField('仓库名称', max_length=20, unique=True)
    place = models.CharField('具体地点', max_length=50)
    class Meta:
        verbose_name = '仓库信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class Inventory(CommonAModel):
    """
    库存表
    """
    material = models.ForeignKey(Material, on_delete=models.CASCADE, verbose_name='物料信息')
    count = models.IntegerField('数量', default=0)
    warehouse = models.ForeignKey(WareHouse, on_delete=models.CASCADE, verbose_name='所在仓库')
    class Meta:
        verbose_name = '库存表'
        verbose_name_plural = verbose_name



class FIFO(CommonAModel):
    """
    出入库记录
    """
    type_choices = (
        (1, '生产领料'),
        (2, '销售提货'),
        (3, '采购入库'),
        (4, '生产入库')
    )
    type = models.IntegerField('出入库类型', default=1)