hberp/hb_server/apps/mtm/models.py

131 lines
4.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
class Material(CommonAModel):
"""
物料
"""
type_choices=(
(1, '成品'),
(2, '半成品'),
(3, '原材料')
)
name = models.CharField('物料名称', max_length=100, unique=True)
number = models.CharField('编号', max_length=100, unique=True)
type = models.CharField('物料类型', choices= type_choices, max_length=20, default=1)
sort_str = models.CharField('排序字符', max_length=100, null=True, blank=True)
process = models.ManyToManyField('mtm.process', through='mtm.ProductProcess', related_name='product_process')
class Meta:
verbose_name = '物料表'
verbose_name_plural = verbose_name
def __str__(self):
return self.name
class Process(CommonAModel):
"""
工序
"""
name = models.CharField('工序名称', max_length=100, unique=True)
number = models.CharField('编号', max_length=100, unique=True)
instruction = models.ForeignKey(File, verbose_name='指导书', on_delete=models.SET_NULL, null=True, blank=True)
instruction_content = models.TextField('指导书内容', null=True, blank=True)
class Meta:
verbose_name = '工序'
verbose_name_plural = verbose_name
def __str__(self):
return self.name
class Step(CommonAModel):
"""
工序步骤
"""
process = models.ForeignKey(Process, on_delete=models.CASCADE, verbose_name='所属工序')
name = models.CharField('工序步骤名称', max_length=100)
number = models.CharField('步骤编号', max_length=100, null=True, blank=True)
instruction_content = models.TextField('相应操作指导', null=True, blank=True)
sort = models.IntegerField('排序号', default=1)
class Meta:
verbose_name = '工序步骤'
verbose_name_plural = verbose_name
def __str__(self):
return self.name
class StepOperationItem(CommonAModel):
"""
操作记录条目
"""
field_type_choices = (
('string', '字符串'),
('int', '整型'),
('float', '浮点'),
('boolean', '布尔'),
('date', '日期'),
('datetime', '日期时间'),
('radio', '单选'),
('checkbox', '多选'),
('select', '单选下拉'),
('selects', '多选下拉'),
('textarea', '文本域'),
)
step = models.ForeignKey(Step, on_delete=models.CASCADE, verbose_name='关联步骤')
field_type = models.CharField('类型', max_length=50, choices=field_type_choices)
field_key = models.CharField('字段标识', max_length=50, help_text='字段类型请尽量特殊,避免与系统中关键字冲突')
field_name = models.CharField('字段名称', max_length=50)
boolean_field_display = models.JSONField('布尔类型显示名', default=dict, blank=True,
help_text='当为布尔类型时候,可以支持自定义显示形式。{"1":"","0":""}或{"1":"需要","0":"不需要"},注意数字也需要引号')
field_choice = models.JSONField('radio、checkbox、select的选项', default=dict, blank=True,
help_text='radio,checkbox,select,multiselect类型可供选择的选项格式为json如:{"1":"中国", "2":"美国"},注意数字也需要引号')
class Meta:
verbose_name = '操作记录条目'
verbose_name_plural = verbose_name
def __str__(self):
return self.field_key + '-' + self.field_name
class ProductProcess(CommonAModel):
"""
产品生产工艺
"""
product = models.ForeignKey(Material, verbose_name='产品', on_delete=models.CASCADE)
process = models.ForeignKey(Process, verbose_name='工序', on_delete=models.CASCADE)
sort = models.IntegerField('排序号', default=1)
class Meta:
verbose_name = '产品生产工序'
verbose_name_plural = verbose_name
class InputMaterial(CommonAModel):
"""
输入物料
"""
material = models.ForeignKey(Material, verbose_name='输入物料', on_delete=models.CASCADE)
number = models.FloatField('消耗量', default=0)
unit = models.CharField('单位', max_length=20)
class Meta:
verbose_name = '输入物料'
verbose_name_plural = verbose_name
class OutputMaterial(CommonAModel):
"""
输出物料
"""
material = models.ForeignKey(Material, verbose_name='输出物料', on_delete=models.CASCADE)
number = models.FloatField('产出量', default=0)
unit = models.CharField('单位', max_length=20)
class Meta:
verbose_name = '输出物料'
verbose_name_plural = verbose_name