feat: WMaterialViewSet 添加手动创建和删除接口
- WMaterial 新增 is_manual 字段标记手动创建的库存 - WMaterialViewSet 添加 create 接口,创建时自动设置 is_manual=True - WMaterialViewSet 添加 destroy 接口,仅允许删除手动创建的记录 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6d43b412b7
commit
3e1a087258
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.2.27 on 2026-03-26 08:56
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('wpm', '0127_handoverb_oinfo_json_alter_attlog_create_by_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='wmaterial',
|
||||||
|
name='is_manual',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='手动创建'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -126,6 +126,7 @@ class WMaterial(CommonBDModel):
|
||||||
batch_ofrom = models.TextField('原料批次号', null=True, blank=True)
|
batch_ofrom = models.TextField('原料批次号', null=True, blank=True)
|
||||||
material_ofrom = models.ForeignKey(Material, verbose_name='原料物料', on_delete=models.SET_NULL, null=True, blank=True, related_name='wm_mofrom')
|
material_ofrom = models.ForeignKey(Material, verbose_name='原料物料', on_delete=models.SET_NULL, null=True, blank=True, related_name='wm_mofrom')
|
||||||
number_from = models.TextField("来源于个号", null=True, blank=True)
|
number_from = models.TextField("来源于个号", null=True, blank=True)
|
||||||
|
is_manual = models.BooleanField('手动创建', default=False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def belong_dept_or_mgroup_id(self):
|
def belong_dept_or_mgroup_id(self):
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ from apps.system.models import User
|
||||||
|
|
||||||
from apps.mtm.models import Material, Process, Route, Mgroup, RoutePack, RouteMat
|
from apps.mtm.models import Material, Process, Route, Mgroup, RoutePack, RouteMat
|
||||||
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
|
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
|
||||||
from apps.utils.mixins import CustomListModelMixin, BulkCreateModelMixin, ComplexQueryMixin, BulkDestroyModelMixin, BulkUpdateModelMixin
|
from rest_framework.mixins import DestroyModelMixin
|
||||||
|
from apps.utils.mixins import CustomListModelMixin, CustomCreateModelMixin, BulkCreateModelMixin, ComplexQueryMixin, BulkDestroyModelMixin, BulkUpdateModelMixin
|
||||||
|
|
||||||
from .filters import StLogFilter, SfLogFilter, WMaterialFilter, MlogFilter, HandoverFilter, MlogbFilter, BatchStFilter, MlogbwFilter
|
from .filters import StLogFilter, SfLogFilter, WMaterialFilter, MlogFilter, HandoverFilter, MlogbFilter, BatchStFilter, MlogbwFilter
|
||||||
from .models import SfLog, SfLogExp, StLog, WMaterial, Mlog, Handover, Mlogb, Mlogbw, AttLog, OtherLog, Fmlog, BatchSt, MlogbDefect, MlogUser, BatchLog, Handoverb
|
from .models import SfLog, SfLogExp, StLog, WMaterial, Mlog, Handover, Mlogb, Mlogbw, AttLog, OtherLog, Fmlog, BatchSt, MlogbDefect, MlogUser, BatchLog, Handoverb
|
||||||
|
|
@ -160,14 +161,16 @@ class SfLogExpViewSet(CustomListModelMixin, BulkUpdateModelMixin, CustomGenericV
|
||||||
filterset_fields = ["sflog", "stlog"]
|
filterset_fields = ["sflog", "stlog"]
|
||||||
|
|
||||||
|
|
||||||
class WMaterialViewSet(CustomListModelMixin, CustomGenericViewSet):
|
class WMaterialViewSet(CustomCreateModelMixin, DestroyModelMixin, CustomListModelMixin, CustomGenericViewSet):
|
||||||
"""
|
"""
|
||||||
list: 车间库存
|
list: 车间库存
|
||||||
|
create: 手动创建车间库存
|
||||||
|
destroy: 删除手动创建的车间库存
|
||||||
|
|
||||||
车间库存
|
车间库存
|
||||||
"""
|
"""
|
||||||
|
|
||||||
perms_map = {"get": "*"}
|
perms_map = {"get": "*", "post": "wmaterial.create", "delete": "wmaterial.delete"}
|
||||||
queryset = WMaterial.objects.filter(count__gt=0)
|
queryset = WMaterial.objects.filter(count__gt=0)
|
||||||
serializer_class = WMaterialSerializer
|
serializer_class = WMaterialSerializer
|
||||||
select_related_fields = ["material", "belong_dept", "material__process", "supplier"]
|
select_related_fields = ["material", "belong_dept", "material__process", "supplier"]
|
||||||
|
|
@ -186,6 +189,14 @@ class WMaterialViewSet(CustomListModelMixin, CustomGenericViewSet):
|
||||||
return queryset
|
return queryset
|
||||||
return queryset.exclude(state=WMaterial.WM_SCRAP)
|
return queryset.exclude(state=WMaterial.WM_SCRAP)
|
||||||
|
|
||||||
|
def perform_create(self, serializer):
|
||||||
|
serializer.save(create_by=self.request.user, belong_dept=self.request.user.dept, is_manual=True)
|
||||||
|
|
||||||
|
def perform_destroy(self, instance):
|
||||||
|
if not instance.is_manual:
|
||||||
|
raise ParseError('只能删除手动创建的车间库存')
|
||||||
|
instance.delete()
|
||||||
|
|
||||||
@action(methods=["post"], detail=False, perms_map={"post": "*"}, serializer_class=DeptBatchSerializer)
|
@action(methods=["post"], detail=False, perms_map={"post": "*"}, serializer_class=DeptBatchSerializer)
|
||||||
def batchs(self, request):
|
def batchs(self, request):
|
||||||
"""获取车间的批次号(废弃)
|
"""获取车间的批次号(废弃)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue