develop reload backup
This commit is contained in:
parent
2fbbe74564
commit
b3f14a8f6f
|
@ -10,14 +10,15 @@ def backup_database():
|
||||||
"""
|
"""
|
||||||
备份数据库
|
备份数据库
|
||||||
"""
|
"""
|
||||||
ret = os.popen('sudo pg_dump -U postgres -d hberp -f /home/lighthouse/hberp_backup.sql')
|
completed = subprocess.run('sudo pg_dump "user=postgres password=zcDsj2021 dbname=hberp" > /home/lighthouse/hberp_backup.sql',
|
||||||
return Response()
|
shell=True, capture_output=True, text=True)
|
||||||
|
return completed
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def reload_server():
|
def reload_server():
|
||||||
os.chdir('/home/lighthouse/hberp')
|
os.chdir('/home/lighthouse/hberp')
|
||||||
ret = subprocess.run('sudo git pull && sudo service supervisor reload')
|
completed = subprocess.run('sudo git pull && sudo service supervisor reload', shell=True, capture_output=True, text=True)
|
||||||
return Response(ret.read())
|
return completed
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ from apps.wf.models import Ticket
|
||||||
from apps.wpm.models import Operation, OperationMaterial, WProduct, WproductFlow
|
from apps.wpm.models import Operation, OperationMaterial, WProduct, WproductFlow
|
||||||
from apps.wpm.services import WpmService
|
from apps.wpm.services import WpmService
|
||||||
from apps.em.tasks import update_equip_state_by_next_check_date
|
from apps.em.tasks import update_equip_state_by_next_check_date
|
||||||
|
from rest_framework.exceptions import APIException
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
class CleanDataView(APIView):
|
class CleanDataView(APIView):
|
||||||
|
@ -123,10 +124,18 @@ class UpdateFIFONumber(APIView):
|
||||||
class ReloadServer(APIView):
|
class ReloadServer(APIView):
|
||||||
permission_classes = [IsAdminUser]
|
permission_classes = [IsAdminUser]
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
reload_server()
|
completed = reload_server()
|
||||||
|
if completed.returncode == 0:
|
||||||
|
return Response()
|
||||||
|
else:
|
||||||
|
raise APIException(completed.stdout)
|
||||||
|
|
||||||
|
|
||||||
class BackupDatabase(APIView):
|
class BackupDatabase(APIView):
|
||||||
permission_classes = [IsAdminUser]
|
permission_classes = [IsAdminUser]
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
backup_database()
|
completed = backup_database()
|
||||||
|
if completed.returncode == 0:
|
||||||
|
return Response()
|
||||||
|
else:
|
||||||
|
raise APIException(completed.stdout)
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 3.2.9 on 2022-02-26 00:35
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('inm', '0032_auto_20220222_0941'),
|
||||||
|
('sam', '0015_sale_ship_pic'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='sale',
|
||||||
|
name='iproducts',
|
||||||
|
field=models.ManyToManyField(through='sam.SaleProduct', to='inm.IProduct'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -94,6 +94,7 @@ class Sale(CommonADModel):
|
||||||
receiver_address = models.CharField('收获地址', null=True, blank=True, max_length=200)
|
receiver_address = models.CharField('收获地址', null=True, blank=True, max_length=200)
|
||||||
remark = 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)
|
ship_pic = models.CharField('物流图片', max_length=200, null=True, blank=True)
|
||||||
|
iproducts = models.ManyToManyField('inm.iproduct', through='sam.saleproduct')
|
||||||
|
|
||||||
class SaleProduct(BaseModel):
|
class SaleProduct(BaseModel):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -37,6 +37,7 @@ class SaleViewSet(CreateUpdateModelAMixin, ListModelMixin, RetrieveModelMixin, C
|
||||||
return SaleListSerializer
|
return SaleListSerializer
|
||||||
return super().get_serializer_class()
|
return super().get_serializer_class()
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
def destroy(self, request, *args, **kwargs):
|
def destroy(self, request, *args, **kwargs):
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
if obj.is_audited:
|
if obj.is_audited:
|
||||||
|
@ -161,6 +162,8 @@ class SaleProductViewSet(ListModelMixin, DestroyModelMixin, CreateModelMixin, Ge
|
||||||
})
|
})
|
||||||
return Response(SaleProductPackDetailSerializer(instance=obj).data)
|
return Response(SaleProductPackDetailSerializer(instance=obj).data)
|
||||||
elif request.method == 'POST':
|
elif request.method == 'POST':
|
||||||
|
if obj.sale.is_audited:
|
||||||
|
raise exceptions.APIException('该销售记录已审核,不可装箱')
|
||||||
serializer = SaleProductPackSerializer(data=request.data)
|
serializer = SaleProductPackSerializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
vdata = serializer.validated_data
|
vdata = serializer.validated_data
|
||||||
|
@ -180,6 +183,8 @@ class SaleProductViewSet(ListModelMixin, DestroyModelMixin, CreateModelMixin, Ge
|
||||||
不装箱备注
|
不装箱备注
|
||||||
"""
|
"""
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
|
if obj.sale.is_audited:
|
||||||
|
raise exceptions.APIException('该销售记录已审核,不可填写备注')
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
vdata = serializer.validated_data
|
vdata = serializer.validated_data
|
||||||
|
|
Loading…
Reference in New Issue