|
@@ -1,8 +1,7 @@
|
|
|
-from rest_framework.views import APIView
|
|
|
-from rest_framework.parsers import JSONParser
|
|
|
-from rest_framework.decorators import api_view, parser_classes
|
|
|
|
|
|
-from rest_framework.response import Response
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+from rest_framework.views import APIView
|
|
|
from rest_framework.permissions import AllowAny
|
|
|
from rest_framework import status
|
|
|
from rest_framework import viewsets
|
|
@@ -11,8 +10,6 @@ from rest_framework.filters import OrderingFilter
|
|
|
from django.utils import timezone
|
|
|
from django.db.models import Q, F, Case, When
|
|
|
from django.core.cache import cache
|
|
|
-
|
|
|
-from datetime import datetime
|
|
|
import requests
|
|
|
from collections import defaultdict
|
|
|
from utils.page import MyPageNumberPagination
|
|
@@ -21,13 +18,14 @@ from .serializers import *
|
|
|
from .filter import *
|
|
|
from .parsers import TextJSONParser
|
|
|
from .parsers import TextJSONRenderer
|
|
|
-
|
|
|
import logging
|
|
|
import time
|
|
|
from django.db import transaction
|
|
|
-
|
|
|
from bound.models import BoundListModel, BoundBatchModel, OutBatchModel,BoundDetailModel,OutBoundDetailModel,BatchLogModel
|
|
|
-from warehouse.models import ProductListModel
|
|
|
+from warehouse.models import ProductListModel
|
|
|
+from rest_framework.response import Response
|
|
|
+
|
|
|
+
|
|
|
logger = logging.getLogger('wms.boundBill')
|
|
|
|
|
|
class WMSResponse:
|
|
@@ -218,6 +216,9 @@ class InboundApplyCreate(APIView):
|
|
|
bound_bill.creater = serializer.validated_data['creater']
|
|
|
bound_bill.note = (serializer.validated_data['note'] if 'note' in serializer.validated_data else '')
|
|
|
bound_bill.totalCount = serializer.validated_data['totalCount']
|
|
|
+ if bound_bill.type != 1:
|
|
|
+ bound_bill.erp_audit_id = bound_bill.number
|
|
|
+ bound_bill.erp_save_id = bound_bill.billId
|
|
|
bound_bill.update_time = timezone.now()
|
|
|
bound_bill.save()
|
|
|
except InboundBill.DoesNotExist:
|
|
@@ -231,9 +232,14 @@ class InboundApplyCreate(APIView):
|
|
|
creater=serializer.validated_data['creater'],
|
|
|
note=(serializer.validated_data['note'] if 'note' in serializer.validated_data else ''),
|
|
|
totalCount=serializer.validated_data['totalCount'],
|
|
|
+
|
|
|
+ erp_save_id = serializer.validated_data['billId'],
|
|
|
create_time=timezone.now(),
|
|
|
update_time=timezone.now()
|
|
|
)
|
|
|
+ if bound_bill.type != 1:
|
|
|
+ bound_bill.erp_audit_id = bound_bill.number
|
|
|
+ bound_bill.save()
|
|
|
return bound_bill
|
|
|
|
|
|
def save_or_update_material_detail(self, bound_bill, serializer):
|
|
@@ -246,7 +252,7 @@ class InboundApplyCreate(APIView):
|
|
|
|
|
|
material_detail.goods_code = item['goods_code']
|
|
|
material_detail.goods_name = item['goods_name']
|
|
|
- material_detail.goods_std = item['goods_std']
|
|
|
+ material_detail.goods_std = (item['goods_std'] if 'goods_std' in item else '')
|
|
|
|
|
|
material_detail.plan_qty = item['plan_qty']
|
|
|
material_detail.goods_total_weight = item['plan_qty']
|
|
@@ -261,7 +267,7 @@ class InboundApplyCreate(APIView):
|
|
|
production_batch=item['production_batch'],
|
|
|
goods_code=item['goods_code'],
|
|
|
goods_name=item['goods_name'],
|
|
|
- goods_std=item['goods_std'],
|
|
|
+ goods_std=(item['goods_std'] if 'goods_std' in item else ''),
|
|
|
goods_weight=1,
|
|
|
plan_qty=item['plan_qty'],
|
|
|
goods_total_weight=item['plan_qty'],
|
|
@@ -395,7 +401,7 @@ class GenerateInbound(APIView):
|
|
|
warehouse_name='立体仓',
|
|
|
goods_code=material.goods_code,
|
|
|
goods_desc=material.goods_name,
|
|
|
- goods_std=material.goods_std,
|
|
|
+ goods_std=(material.goods_std if material.goods_std else ''),
|
|
|
goods_unit=material.goods_unit,
|
|
|
goods_qty=material.plan_qty,
|
|
|
goods_weight=float(material.goods_weight),
|
|
@@ -801,6 +807,10 @@ class OutboundApplyCreate(APIView):
|
|
|
bound_bill.creater = serializer.validated_data['creater']
|
|
|
bound_bill.note = (serializer.validated_data['note'] if 'note' in serializer.validated_data else '')
|
|
|
bound_bill.totalCount = serializer.validated_data['totalCount']
|
|
|
+
|
|
|
+ bound_bill.erp_audit_id = bound_bill.number
|
|
|
+ bound_bill.erp_save_id = bound_bill.billId
|
|
|
+
|
|
|
bound_bill.update_time = timezone.now()
|
|
|
bound_bill.save()
|
|
|
except OutboundBill.DoesNotExist:
|
|
@@ -814,6 +824,8 @@ class OutboundApplyCreate(APIView):
|
|
|
creater=serializer.validated_data['creater'],
|
|
|
note=(serializer.validated_data['note'] if 'note' in serializer.validated_data else ''),
|
|
|
totalCount=serializer.validated_data['totalCount'],
|
|
|
+ erp_audit_id = serializer.validated_data['number'],
|
|
|
+ erp_save_id = serializer.validated_data['billId'],
|
|
|
create_time=timezone.now(),
|
|
|
update_time=timezone.now()
|
|
|
)
|
|
@@ -907,7 +919,7 @@ class ProductInfo(APIView):
|
|
|
instance.id = material_id
|
|
|
instance.product_code = material.get('product_code', instance.product_code)
|
|
|
instance.product_name = material.get('product_name', instance.product_name)
|
|
|
- instance.product_std = material.get('product_std', instance.product_std)
|
|
|
+ instance.product_std = material.get('product_std', instance.product_std or 'on std')
|
|
|
instance.product_unit = material.get('product_unit', instance.product_unit or 'KG')
|
|
|
|
|
|
# 必填字段校验[7](@ref)
|
|
@@ -930,7 +942,7 @@ class ProductInfo(APIView):
|
|
|
})
|
|
|
|
|
|
# 检查总数一致性[7](@ref)
|
|
|
- if len(materials) != total_count:
|
|
|
+ if success_count != total_count:
|
|
|
return WMSResponse.error(
|
|
|
message="物料数量不匹配",
|
|
|
total=total_count,
|
|
@@ -963,6 +975,7 @@ class BatchUpdate(APIView):
|
|
|
def post(self, request):
|
|
|
data = request.data
|
|
|
total_count = data.get('totalCount', 0)
|
|
|
+ material_audit_id = data.get('billnos')
|
|
|
materials = data.get('materials', [])
|
|
|
|
|
|
success_count = 0
|
|
@@ -981,6 +994,7 @@ class BatchUpdate(APIView):
|
|
|
material_billId = material.get('billId')
|
|
|
material_entryId = material.get('entryIds')
|
|
|
material_status = material.get('status')
|
|
|
+
|
|
|
if material_status == 'passing':
|
|
|
try:
|
|
|
instance = MaterialDetail.objects.get(bound_billId_id=material_billId,entryIds=material_entryId)
|
|
@@ -993,7 +1007,21 @@ class BatchUpdate(APIView):
|
|
|
fail_count += 1
|
|
|
continue
|
|
|
instance.status = 1
|
|
|
+
|
|
|
+ bill_obj = InboundBill.objects.get(billId=material_billId)
|
|
|
+ if not bill_obj:
|
|
|
+ logger.info("入库单不存在")
|
|
|
+ fail_materials.append({
|
|
|
+ **material,
|
|
|
+ "error": "入库单不存在"
|
|
|
+ })
|
|
|
+ fail_count += 1
|
|
|
+ continue
|
|
|
+ bill_obj.erp_audit_id = material_audit_id
|
|
|
+ logger.info("[1]入库单号%s,物料明细%s,更新状态,审核通过%s",bill_obj.number,material_entryId,material_audit_id)
|
|
|
+ logger.info("[2]入库单号%s,物料明细%s,更新状态,审核通过%s",bill_obj.number,material_entryId,bill_obj.erp_audit_id)
|
|
|
instance.save()
|
|
|
+ bill_obj.save()
|
|
|
success_count += 1
|
|
|
except Exception as e:
|
|
|
fail_count += 1
|
|
@@ -1130,8 +1158,11 @@ class ERPSyncBase:
|
|
|
|
|
|
def execute_sync(self):
|
|
|
"""执行同步操作"""
|
|
|
+ # 测试环境 @ todo
|
|
|
+
|
|
|
headers = {
|
|
|
- 'accessToken': f'{AccessToken.get_current_token()}'
|
|
|
+ 'accessToken': f'{AccessToken.get_current_token()}',
|
|
|
+ 'x-acgw-identity': 'djF8MTk2M2QzMWEzMjUwMTZlMzA3MDF8NDg5ODM4MzM4NjE3OHwYjYJyvo-DbkhOliEpFtiFOsCgKKo6braaiQGE9qdNx3w='
|
|
|
}
|
|
|
|
|
|
for attempt in range(self.max_retries):
|
|
@@ -1172,7 +1203,7 @@ class ProductionInboundAuditSync(ERPSyncBase):
|
|
|
erp_id_field = 'erp_audit_id'
|
|
|
# 请求地址
|
|
|
def get_erp_endpoint(self):
|
|
|
- return "https://okyy.test.kdgalaxy.com/kapi/v2/l772/im/im_productinbill/audit"
|
|
|
+ return "https://okyy.test.kdgalaxy.com/kapi/v2/l772/im/im_mdc_mftmanuinbill/audit"
|
|
|
# 请求参数
|
|
|
# {
|
|
|
# "data":{
|
|
@@ -1186,7 +1217,7 @@ class ProductionInboundAuditSync(ERPSyncBase):
|
|
|
return {
|
|
|
"data": {
|
|
|
"billnos": [
|
|
|
- self.wms_bill.number,
|
|
|
+ self.wms_bill.erp_audit_id,
|
|
|
]
|
|
|
}
|
|
|
}
|
|
@@ -1194,9 +1225,9 @@ class ProductionInboundAuditSync(ERPSyncBase):
|
|
|
|
|
|
def process_erp_response(self, response):
|
|
|
print("ERP审核响应:",response)
|
|
|
- if response['code'] != '200':
|
|
|
- raise ValueError(f"ERP审核失败: {response['msg']}")
|
|
|
- return response['data']['erp_audit_id']
|
|
|
+ if response['status'] != True:
|
|
|
+ raise ValueError(f"ERP审核失败: {response['message']}")
|
|
|
+ return response['data']
|
|
|
"""采购收料入库审核"""
|
|
|
class PurchaseInboundAuditSync(ERPSyncBase):
|
|
|
|
|
@@ -1217,7 +1248,7 @@ class PurchaseInboundAuditSync(ERPSyncBase):
|
|
|
return {
|
|
|
"data": {
|
|
|
"billnos": [
|
|
|
- self.wms_bill.number,
|
|
|
+ self.wms_bill.erp_audit_id,
|
|
|
]
|
|
|
}
|
|
|
}
|
|
@@ -1225,9 +1256,9 @@ class PurchaseInboundAuditSync(ERPSyncBase):
|
|
|
|
|
|
def process_erp_response(self, response):
|
|
|
print("ERP审核响应:",response)
|
|
|
- if response['code'] != '200':
|
|
|
- raise ValueError(f"ERP审核失败: {response['msg']}")
|
|
|
- return response['data']['erp_audit_id']
|
|
|
+ if response['status'] != True:
|
|
|
+ raise ValueError(f"ERP审核失败: {response['message']}")
|
|
|
+ return response['data']
|
|
|
"""其他入库审核"""
|
|
|
class OtherInboundAuditSync(ERPSyncBase):
|
|
|
|
|
@@ -1248,7 +1279,7 @@ class OtherInboundAuditSync(ERPSyncBase):
|
|
|
return {
|
|
|
"data": {
|
|
|
"billnos": [
|
|
|
- self.wms_bill.number,
|
|
|
+ self.wms_bill.erp_audit_id,
|
|
|
]
|
|
|
}
|
|
|
}
|
|
@@ -1256,9 +1287,41 @@ class OtherInboundAuditSync(ERPSyncBase):
|
|
|
|
|
|
def process_erp_response(self, response):
|
|
|
print("ERP审核响应:",response)
|
|
|
- if response['code'] != '200':
|
|
|
- raise ValueError(f"ERP审核失败: {response['msg']}")
|
|
|
- return response['data']['erp_audit_id']
|
|
|
+ if response['status'] != True:
|
|
|
+ raise ValueError(f"ERP审核失败: {response['message']}")
|
|
|
+ return response['data']
|
|
|
+"""调拨入库审核"""
|
|
|
+class TransferInboundAuditSync(ERPSyncBase):
|
|
|
+
|
|
|
+ erp_id_field = 'erp_audit_id'
|
|
|
+ # 请求地址
|
|
|
+ def get_erp_endpoint(self):
|
|
|
+ return "https://okyy.test.kdgalaxy.com/kapi/v2/l772/im/im_transdirbill/audit"
|
|
|
+
|
|
|
+ # 请求参数
|
|
|
+ # {
|
|
|
+ # "data":{
|
|
|
+ # "billnos":[
|
|
|
+ # "AgTSC",
|
|
|
+ # "fgBAH"
|
|
|
+ # ]
|
|
|
+ # }
|
|
|
+ # }
|
|
|
+ def build_erp_payload(self):
|
|
|
+ return {
|
|
|
+ "data": {
|
|
|
+ "billnos": [
|
|
|
+ self.wms_bill.erp_audit_id,
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ # 处理响应
|
|
|
+
|
|
|
+ def process_erp_response(self, response):
|
|
|
+ print("ERP审核响应:",response)
|
|
|
+ if response['status'] != True:
|
|
|
+ raise ValueError(f"ERP审核失败: {response['message']}")
|
|
|
+ return response['data']
|
|
|
"""其他出库审核同步"""
|
|
|
class OtherOutboundAuditSync(ERPSyncBase):
|
|
|
|
|
@@ -1279,7 +1342,7 @@ class OtherOutboundAuditSync(ERPSyncBase):
|
|
|
return {
|
|
|
"data": {
|
|
|
"billnos": [
|
|
|
- self.wms_bill.number,
|
|
|
+ self.wms_bill.erp_audit_id,
|
|
|
]
|
|
|
}
|
|
|
}
|
|
@@ -1287,9 +1350,9 @@ class OtherOutboundAuditSync(ERPSyncBase):
|
|
|
|
|
|
def process_erp_response(self, response):
|
|
|
print("ERP审核响应:",response)
|
|
|
- if response['code'] != '200':
|
|
|
- raise ValueError(f"ERP审核失败: {response['msg']}")
|
|
|
- return response['data']['erp_audit_id']
|
|
|
+ if response['status'] != True:
|
|
|
+ raise ValueError(f"ERP审核失败: {response['message']}")
|
|
|
+ return response['data']
|
|
|
"""生产领料出库审核"""
|
|
|
class ProductionOutboundAuditSync(ERPSyncBase):
|
|
|
|
|
@@ -1310,7 +1373,7 @@ class ProductionOutboundAuditSync(ERPSyncBase):
|
|
|
return {
|
|
|
"data": {
|
|
|
"billnos": [
|
|
|
- self.wms_bill.number,
|
|
|
+ self.wms_bill.erp_audit_id,
|
|
|
]
|
|
|
}
|
|
|
}
|
|
@@ -1318,9 +1381,9 @@ class ProductionOutboundAuditSync(ERPSyncBase):
|
|
|
|
|
|
def process_erp_response(self, response):
|
|
|
print("ERP审核响应:",response)
|
|
|
- if response['code'] != '200':
|
|
|
- raise ValueError(f"ERP审核失败: {response['msg']}")
|
|
|
- return response['data']['erp_audit_id']
|
|
|
+ if response['status'] != True:
|
|
|
+ raise ValueError(f"ERP审核失败: {response['message']}")
|
|
|
+ return response['data']
|
|
|
"""采购入库保存"""
|
|
|
class PurchaseInboundSaveSync(ERPSyncBase):
|
|
|
|
|
@@ -1341,7 +1404,7 @@ class PurchaseInboundSaveSync(ERPSyncBase):
|
|
|
# }
|
|
|
return {
|
|
|
"purinbill": {
|
|
|
- "billId":self.wms_bill.number,
|
|
|
+ "billId":self.wms_bill.erp_audit_id,
|
|
|
"entryIds": [
|
|
|
self.wms_bill.number,
|
|
|
]
|
|
@@ -1371,7 +1434,7 @@ class SaleOutboundSaveSync(ERPSyncBase):
|
|
|
# }
|
|
|
return {
|
|
|
"purinbill": {
|
|
|
- "billId":self.wms_bill.number,
|
|
|
+ "billId":self.wms_bill.erp_audit_id,
|
|
|
"entryIds": [
|
|
|
self.wms_bill.number,
|
|
|
]
|
|
@@ -1538,6 +1601,6 @@ class OutMaterials(viewsets.ModelViewSet):
|
|
|
if self.action in ['retrieve', 'list']:
|
|
|
return OutMaterialDetailSerializer
|
|
|
else:
|
|
|
- return self.http_method_not_allowed(request=self.request)
|
|
|
+ return self.http_method_not_allowed(request=self.request)
|
|
|
|
|
|
|