Browse Source

简易流程:添付款时,自动生成付款单,并自动审核

wushaodong 3 years ago
parent
commit
f0210ec885
3 changed files with 64 additions and 13 deletions
  1. 2 2
      apps/purchase/serializers.py
  2. 56 7
      apps/purchase/views.py
  3. 6 4
      uis/views/purchase/material_pay.html

+ 2 - 2
apps/purchase/serializers.py

@@ -640,7 +640,7 @@ class PurchasePaymentSerializer(serializers.ModelSerializer):
     order_no = serializers.CharField(source='order.no', read_only=True)
     payment = BooleanCharField(source='is_pay', read_only=True)
     amount = AmountShowCharFieldWithTwoDecimalPlaces()
-    actual_amount = AmountShowCharFieldWithTwoDecimalPlaces(read_only=True)
+    actual_amount = AmountShowCharFieldWithTwoDecimalPlaces()
     apply_amount = AmountShowCharFieldWithTwoDecimalPlaces()
     amount_CNY = serializers.SerializerMethodField()
     actual_amount_CNY = serializers.SerializerMethodField()
@@ -673,7 +673,7 @@ class PurchasePaymentSerializer(serializers.ModelSerializer):
             instance = PurchasePayment.getById(id)
         else:
             instance = None
-        serializer = PurchasePaymentSerializer(instance, data=data)
+        serializer = PurchasePaymentSerializer(instance, data=data, partial=True)
         serializer.user = user
         return serializer
 

+ 56 - 7
apps/purchase/views.py

@@ -1041,12 +1041,56 @@ def purchase_order_payment(request):
     transport_account = request.POST.get('transport_account')
     transport_amount = request.POST.get('transport_amount')
 
-    order_amount = request.POST.get('order_amount')
+    order_amount = Formater.formatAmount(request.POST.get('order_amount') or 0)
     order_account = request.POST.get('order_account')
 
     try:
         with transaction.atomic():
-            order = PurchaseOrder.getById(id)
+            godownentry_process = Config.getValue('godownentry_process')
+            if godownentry_process != '1':
+                raise CustomError('当前入库模式非简易模式,禁止付款!')
+            godownEntry = GodownEntry.getById(id)
+            if godownEntry.status != settings.PASS:
+                raise CustomError('当前入库单未审核,禁止付款!')
+            if order_amount:
+                # 订单费用
+                purchase_order = godownEntry.purchase_order
+                payment = PurchasePayment.objects.filter(order=purchase_order).first()
+                if payment:
+                    # 再次付款
+                    if payment.is_clear:
+                        raise CustomError('当前入库单已结清,禁止付款!')
+                    actual_amount = order_amount + payment.actual_amount
+                    order_data = {
+                                  'actual_amount': actual_amount,
+                                  'is_clear': True if actual_amount >= payment.amount else False,
+                                  }
+                    pb = PurchasePaymentSerializer.factory(request.user, order_data, payment.id)
+                else:
+                    # 首次付款
+                    order_data = {'order': purchase_order.id,
+                                  'status': settings.PASS,
+                                  'amount': purchase_order.amount,
+                                  'apply_amount': purchase_order.apply_amount,
+                                  'actual_amount': order_amount,
+                                  'is_pay': True,
+                                  'check_time': timezone.now(),
+                                  'check_user': request.user.id,
+                                  'is_clear': True if order_amount >= purchase_order.amount else False,
+                                  }
+                    pb = PurchasePaymentSerializer.factory(request.user, order_data)
+                pb.validSave()
+                payment = pb.instance
+                purchase_order.updateApplyAmount()  # 更新合同单的申请金额
+                # 创建付款明细
+                data={
+                    'main':payment.id,
+                    'payment_type':order_account,
+                    'actual_amount':order_amount,
+                }
+                pb = PurchasePaySerializer.factory(request.user, data)
+                pb.validSave()
+            # todo 自动创建收支单
 
     except CustomError, e:
         return JSONError(e.get_error_msg())
@@ -1096,11 +1140,11 @@ def purchase_payment_save(request):
 
     try:
         with transaction.atomic():
-            apply_amount = Formater.formatAmount(data['apply_amount'])
+            apply_amount = Formater.formatAmount(data['apply_amount']) # 申请金额
             if apply_amount <= 0:
                 raise CustomError(u'本次申请金额必须大于0')
             total_amount = apply_amount
-            amount = Formater.formatAmount(data['amount'])
+            amount = Formater.formatAmount(data['amount']) # 合同金额
             sum_rows = PurchasePayment.objects.filter(order_id=data['order_id']).aggregate(sum_amount=Sum('apply_amount'))
             if sum_rows:
                 total_amount += sum_rows['sum_amount'] or 0
@@ -1733,6 +1777,9 @@ def godownentry_save(request):
             valid_permission(request.user, serializer.getPermission('add'))
             # 简易流程:添加入库单,同时生成合同,自动审核合同。
             godownentry_process = Config.getValue('godownentry_process')
+            if main_data.has_key('purchase_order') and main_data['purchase_order']:
+                # 合同中点到货,会执行此接口。此时无论那种流程,都不应该在创建合同。
+                godownentry_process = ''
             pb = None
             if godownentry_process == '1':
                 order_data = {
@@ -1761,18 +1808,20 @@ def godownentry_save(request):
                     dict = {
                         'main':pb.id,
                         'product':detail.product_base.id,
-                        'count':detail.count,
-                        'price':detail.price,
+                        'count':item['count'],
+                        'price':item['price'],
                         'amount':detail.amount,
-                        'arrval_count':detail.count,
                         'is_arrval':True,
                     }
                     pbd = PurchaseOrderDetailSerializer.factory(request.user, dict)
                     pbd.validSave()
+                    pbd.instance.arrval_count = detail.count
+                    pbd.instance.save()
             serializer.update_total()
             if pb:
                 pb.count = serializer.total_count
                 pb.amount = serializer.total_amount
+                pb.apply_amount = serializer.total_amount
                 pb.save()
     except CustomError, e:
         return JSONError(e.get_error_msg())

+ 6 - 4
uis/views/purchase/material_pay.html

@@ -123,19 +123,21 @@
         });
 
         form.on('submit(component-form-element)', function (data) {
-            console.log(111111111, data.field)
+            var order_amount = parseFloat(data.field.order_amount)
+            var handing_amount = parseFloat(data.field.handing_amount)
+            var transport_amount = parseFloat(data.field.transport_amount)
 
-            if (parseFloat(data.field.order_amount) > 0 && !data.field.order_account) {
+            if (order_amount > 0 && !data.field.order_account) {
                 layer.msg('请选择订单费用付款账户!', {icon: 5});
                 return false;
             }
 
-            if (parseFloat(data.field.handing_amount) > 0 && !data.field.handing_account) {
+            if (handing_amount > 0 && !data.field.handing_account) {
                 layer.msg('请选择装卸费用付款账户!', {icon: 5});
                 return false;
             }
 
-            if (parseFloat(data.field.transport_amount) > 0 && !data.field.transport_account) {
+            if (transport_amount > 0 && !data.field.transport_account) {
                 layer.msg('请选择运输费用付款账户!', {icon: 5});
                 return false;
             }