diff --git a/hb_server/apps/inm/services.py b/hb_server/apps/inm/services.py index b9df308..aac1d34 100644 --- a/hb_server/apps/inm/services.py +++ b/hb_server/apps/inm/services.py @@ -55,23 +55,18 @@ class InmService: for i in FIFOItem.objects.filter(fifo=instance): material = i.material warehouse = i.warehouse - o1 = Inventory.objects.get(material=material, warehouse=warehouse) - temp_count = o1.count - i.count - if temp_count < 0: - raise ValidationError('仓库库存不足,操作失败') - o1.count = temp_count - o1.save() - print(i.batch) - o2 = MaterialBatch.objects.get(material=material, warehouse=warehouse, batch=i.batch) - temp_count = o2.count - i.count + mb = MaterialBatch.objects.get(material=material, warehouse=warehouse, batch=i.batch) + temp_count = mb.count - i.count if temp_count < 0: raise ValidationError('批次库存不足,操作失败') - o2.count = temp_count - o2.save() - temp_count = material.count - i.count - if temp_count < 0: - raise ValidationError('物料库存不足,操作失败') - material.count = temp_count + mb.count = temp_count + mb.save() + + iv = Inventory.objects.get(material=material, warehouse=warehouse) + iv.count = MaterialBatch.objects.filter(material=material, warehouse=warehouse).count() + iv.save() + + material.count = MaterialBatch.objects.filter(material=material).count() material.save() # 删除IProduct diff --git a/hb_server/apps/sam/migrations/0015_sale_ship_pic.py b/hb_server/apps/sam/migrations/0015_sale_ship_pic.py new file mode 100644 index 0000000..5b18d28 --- /dev/null +++ b/hb_server/apps/sam/migrations/0015_sale_ship_pic.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.9 on 2022-02-25 01:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sam', '0014_auto_20220222_1530'), + ] + + operations = [ + migrations.AddField( + model_name='sale', + name='ship_pic', + field=models.CharField(blank=True, max_length=200, null=True, verbose_name='物流图片'), + ), + ] diff --git a/hb_server/apps/sam/models.py b/hb_server/apps/sam/models.py index 0477da0..ba9a809 100644 --- a/hb_server/apps/sam/models.py +++ b/hb_server/apps/sam/models.py @@ -93,6 +93,7 @@ class Sale(CommonADModel): receiver_phone = models.CharField('收货人联系电话', null=True, blank=True, max_length=20) receiver_address = models.CharField('收获地址', null=True, blank=True, max_length=200) remark = models.CharField('备注', null=True, blank=True, max_length=200) + ship_pic = models.CharField('物流图片', max_length=200, null=True, blank=True) class SaleProduct(BaseModel): """ diff --git a/hb_server/apps/sam/serializers_sale.py b/hb_server/apps/sam/serializers_sale.py index 4fb7589..e9347c0 100644 --- a/hb_server/apps/sam/serializers_sale.py +++ b/hb_server/apps/sam/serializers_sale.py @@ -97,3 +97,6 @@ class SaleProductPackSerializer(serializers.ModelSerializer): class SRemarkItemCreateSerializer(serializers.Serializer): remark = serializers.CharField(min_length=6) + +class SaleUpShipPicSerializer(serializers.Serializer): + path = serializers.CharField(min_length=200) diff --git a/hb_server/apps/sam/views_sale.py b/hb_server/apps/sam/views_sale.py index a97b37f..9135fe1 100644 --- a/hb_server/apps/sam/views_sale.py +++ b/hb_server/apps/sam/views_sale.py @@ -6,7 +6,7 @@ from apps.inm.models import FIFO, FIFOItem, FIFOItemProduct, IProduct, WareHouse from apps.inm.services import InmService from apps.mtm.models import Material, PackItem from apps.sam.models import Sale, SalePack, SaleProduct -from apps.sam.serializers_sale import SRemarkItemCreateSerializer, SaleCreateSerializer, SaleListSerializer, SaleProductCreateSerializer, SaleProductListSerializer, SaleProductPackDetailSerializer, SaleProductPackSerializer +from apps.sam.serializers_sale import SRemarkItemCreateSerializer, SaleCreateSerializer, SaleListSerializer, SaleProductCreateSerializer, SaleProductListSerializer, SaleProductPackDetailSerializer, SaleProductPackSerializer, SaleUpShipPicSerializer from rest_framework import exceptions from django.db import transaction from rest_framework.decorators import action @@ -85,8 +85,6 @@ class SaleViewSet(CreateUpdateModelAMixin, ListModelMixin, RetrieveModelMixin, C fifo.sale = obj fifo.type = FIFO.FIFO_TYPE_SALE_OUT fifo.is_audited = False - fifo.auditor = request.user - fifo.inout_date = timezone.now() fifo.create_by = request.user fifo.number = 'CK' + ranstr(7) fifo.save() @@ -95,6 +93,17 @@ class SaleViewSet(CreateUpdateModelAMixin, ListModelMixin, RetrieveModelMixin, C obj.save() return Response() + + @action(methods=['post'], detail=True, perms_map={'post':'sale_up_ship'}, serializer_class=SaleUpShipPicSerializer) + @transaction.atomic + def up_ship(self, request, pk=None): + """ + 上传物流信息 + """ + obj = self.get_object() + obj.ship_pic = request.data['path'] + obj.save() + return Response() diff --git a/hb_server/utils/view.py b/hb_server/utils/view.py index 30bc9be..08aad2e 100644 --- a/hb_server/utils/view.py +++ b/hb_server/utils/view.py @@ -78,15 +78,15 @@ class UpdateDevelop(APIView): def post(self, request, *args, **kwargs): import os # 更新后端 - os.chdir('/home/hberp') + os.chdir('/home/lighthouse/hberp') ret = os.popen('git pull https://caoqianming%40foxmail.com:9093qqww@e.coding.net/ctcdevteam/hberp/hberp.git develop') # 奇怪的处理 - os.chdir('/home/hberp/hb_server/vuedist') - os.popen('cp index.html indexbak') - time.sleep(1000) - os.popen('rm -rf index.html') - time.sleep(1000) - os.popen('mv -f indexbak index.html') + # os.chdir('/home/hberp/hb_server/vuedist') + # os.popen('cp index.html indexbak') + # time.sleep(1000) + # os.popen('rm -rf index.html') + # time.sleep(1000) + # os.popen('mv -f indexbak index.html') # 打包前端 # os.chdir('/home/hberp/hb_client') # os.system('npm run build:prod')