From aa3fa071a41e39f6556b3907b2bc46faa7af6d10 Mon Sep 17 00:00:00 2001 From: Czw996 <459749926@qq.com> Date: Wed, 22 Dec 2021 15:42:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=95=86=E5=93=81=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/goods/serializers.py | 5 +++++ apps/goods/urls.py | 2 +- apps/system/serializers.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/apps/goods/serializers.py b/apps/goods/serializers.py index 676e953..71bb08d 100644 --- a/apps/goods/serializers.py +++ b/apps/goods/serializers.py @@ -135,6 +135,11 @@ class GoodsSerializer(BaseSerializer): instance = self.validate_foreign_key(GoodsUnit, instance, message='商品单位不存在') return instance + def validate_enable_batch_control(self, value): + if value and (self.team.enable_auto_stock_in or self.team.enable_auto_stock_out): + raise ValidationError('只有同时关闭自动入库、自动出库, 才可以开启商品的批次控制') + return value + def validate_goods_images(self, instances): instances = self.validate_foreign_key_set(GoodsImage, instances, message='商品图片不存在') return instances diff --git a/apps/goods/urls.py b/apps/goods/urls.py index 62e04c2..69fae0c 100644 --- a/apps/goods/urls.py +++ b/apps/goods/urls.py @@ -6,7 +6,7 @@ router = BaseRouter() router.register('goods_categories', GoodsCategoryViewSet, 'goods_category') router.register('goods_units', GoodsUnitViewSet, 'goods_unit') router.register('goods', GoodsViewSet, 'goods') -router.register('goods_images', GoodsViewSet, 'goods_image') +router.register('goods_images', GoodsImageViewSet, 'goods_image') router.register('batchs', BatchViewSet, 'batch') router.register('inventories', InventoryViewSet, 'inventory') urlpatterns = router.urls diff --git a/apps/system/serializers.py b/apps/system/serializers.py index e97a843..8377eb9 100644 --- a/apps/system/serializers.py +++ b/apps/system/serializers.py @@ -3,6 +3,7 @@ from extensions.common.base import * from extensions.serializers import * from extensions.exceptions import * from apps.system.models import * +from apps.goods.models import * class PermissionGroupSerializer(BaseSerializer): @@ -26,6 +27,17 @@ class SystemConfigSerializer(BaseSerializer): model = Team fields = ['enable_auto_stock_in', 'enable_auto_stock_out'] + def validate_enable_batch_control(self, value): + if value and (self.team.enable_auto_stock_in or self.team.enable_auto_stock_out): + raise ValidationError('只有同时关闭自动入库、自动出库, 才可以开启商品的批次控制') + return value + + def validate(self, attrs): + if attrs['enable_auto_stock_in'] or attrs['enable_auto_stock_out']: + if goods := Goods.objects.filter(enable_batch_control=True, team=self.team).first(): + raise ValidationError(f'商品[{goods.name}]已开启批次控制, 无法开启自动出/入库') + return super().validate(attrs) + class RoleSerializer(BaseSerializer):