feat: utask增加belong_dept字段及相应逻辑

This commit is contained in:
caoqianming 2023-10-26 08:48:10 +08:00
parent bc57f49e6a
commit b1339f6d6b
5 changed files with 33 additions and 2 deletions

View File

@ -16,6 +16,7 @@ class UtaskFilter(filters.FilterSet):
"material": ["exact"], "material": ["exact"],
"material__type": ["exact"], "material__type": ["exact"],
"material__is_hidden": ["exact"], "material__is_hidden": ["exact"],
"belong_dept": ["exact"],
"mgroup__belong_dept__name": ["exact"], "mgroup__belong_dept__name": ["exact"],
"mtask_utask__mgroup": ["exact"], "mtask_utask__mgroup": ["exact"],
"mtask_utask__mgroup__belong_dept": ['exact'], "mtask_utask__mgroup__belong_dept": ['exact'],

View File

@ -0,0 +1,20 @@
# Generated by Django 3.2.12 on 2023-10-26 00:47
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('system', '0002_myschedule'),
('pm', '0009_auto_20231025_1845'),
]
operations = [
migrations.AddField(
model_name='utask',
name='belong_dept',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='utask_belong_dept', to='system.dept', verbose_name='所属部门'),
),
]

View File

@ -1,11 +1,11 @@
from django.db import models from django.db import models
from apps.utils.models import CommonADModel from apps.utils.models import CommonADModel, CommonBDModel
from apps.mtm.models import Material, Mgroup from apps.mtm.models import Material, Mgroup
# Create your models here. # Create your models here.
class Utask(CommonADModel): class Utask(CommonBDModel):
""" """
生产大任务 生产大任务
""" """

View File

@ -5,15 +5,23 @@ from apps.mtm.serializers import MaterialSerializer
from apps.pm.models import Mtask, Utask from apps.pm.models import Mtask, Utask
from apps.sam.models import OrderItem from apps.sam.models import OrderItem
from apps.utils.serializers import CustomModelSerializer from apps.utils.serializers import CustomModelSerializer
from apps.system.models import Dept
class UtaskSerializer(CustomModelSerializer): class UtaskSerializer(CustomModelSerializer):
material_ = MaterialSerializer(source='material', read_only=True) material_ = MaterialSerializer(source='material', read_only=True)
belong_dept = serializers.PrimaryKeyRelatedField(
queryset=Dept.objects.all(), required=False)
class Meta: class Meta:
model = Utask model = Utask
fields = '__all__' fields = '__all__'
def validate(self, attrs):
if 'mgroup' in attrs and attrs['mgroup']:
attrs['belong_dept'] = attrs['mgroup'].belong_dept
return attrs
def update(self, instance, validated_data): def update(self, instance, validated_data):
if instance.state != Mtask.MTASK_CREATED: if instance.state != Mtask.MTASK_CREATED:
raise ValidationError('任务非创建中不可编辑') raise ValidationError('任务非创建中不可编辑')

View File

@ -57,6 +57,8 @@ class PmService:
number, product, count, start_date, end_date = utask.number, utask.material, utask.count, utask.start_date, utask.end_date number, product, count, start_date, end_date = utask.number, utask.material, utask.count, utask.start_date, utask.end_date
# 计算相差天数 # 计算相差天数
rela_days = (end_date - start_date).days + 1 rela_days = (end_date - start_date).days + 1
if utask.mgroup: # 如果存在指定的mgroup则直接排产
pass
# 获取每个产品的加工路线 # 获取每个产品的加工路线
rqs = Route.get_routes(product) rqs = Route.get_routes(product)
# 创建小任务 # 创建小任务