|
@@ -1041,12 +1041,56 @@ def purchase_order_payment(request):
|
|
transport_account = request.POST.get('transport_account')
|
|
transport_account = request.POST.get('transport_account')
|
|
transport_amount = request.POST.get('transport_amount')
|
|
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')
|
|
order_account = request.POST.get('order_account')
|
|
|
|
|
|
try:
|
|
try:
|
|
with transaction.atomic():
|
|
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:
|
|
except CustomError, e:
|
|
return JSONError(e.get_error_msg())
|
|
return JSONError(e.get_error_msg())
|
|
@@ -1096,11 +1140,11 @@ def purchase_payment_save(request):
|
|
|
|
|
|
try:
|
|
try:
|
|
with transaction.atomic():
|
|
with transaction.atomic():
|
|
- apply_amount = Formater.formatAmount(data['apply_amount'])
|
|
|
|
|
|
+ apply_amount = Formater.formatAmount(data['apply_amount']) # 申请金额
|
|
if apply_amount <= 0:
|
|
if apply_amount <= 0:
|
|
raise CustomError(u'本次申请金额必须大于0')
|
|
raise CustomError(u'本次申请金额必须大于0')
|
|
total_amount = apply_amount
|
|
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'))
|
|
sum_rows = PurchasePayment.objects.filter(order_id=data['order_id']).aggregate(sum_amount=Sum('apply_amount'))
|
|
if sum_rows:
|
|
if sum_rows:
|
|
total_amount += sum_rows['sum_amount'] or 0
|
|
total_amount += sum_rows['sum_amount'] or 0
|
|
@@ -1733,6 +1777,9 @@ def godownentry_save(request):
|
|
valid_permission(request.user, serializer.getPermission('add'))
|
|
valid_permission(request.user, serializer.getPermission('add'))
|
|
# 简易流程:添加入库单,同时生成合同,自动审核合同。
|
|
# 简易流程:添加入库单,同时生成合同,自动审核合同。
|
|
godownentry_process = Config.getValue('godownentry_process')
|
|
godownentry_process = Config.getValue('godownentry_process')
|
|
|
|
+ if main_data.has_key('purchase_order') and main_data['purchase_order']:
|
|
|
|
+ # 合同中点到货,会执行此接口。此时无论那种流程,都不应该在创建合同。
|
|
|
|
+ godownentry_process = ''
|
|
pb = None
|
|
pb = None
|
|
if godownentry_process == '1':
|
|
if godownentry_process == '1':
|
|
order_data = {
|
|
order_data = {
|
|
@@ -1761,18 +1808,20 @@ def godownentry_save(request):
|
|
dict = {
|
|
dict = {
|
|
'main':pb.id,
|
|
'main':pb.id,
|
|
'product':detail.product_base.id,
|
|
'product':detail.product_base.id,
|
|
- 'count':detail.count,
|
|
|
|
- 'price':detail.price,
|
|
|
|
|
|
+ 'count':item['count'],
|
|
|
|
+ 'price':item['price'],
|
|
'amount':detail.amount,
|
|
'amount':detail.amount,
|
|
- 'arrval_count':detail.count,
|
|
|
|
'is_arrval':True,
|
|
'is_arrval':True,
|
|
}
|
|
}
|
|
pbd = PurchaseOrderDetailSerializer.factory(request.user, dict)
|
|
pbd = PurchaseOrderDetailSerializer.factory(request.user, dict)
|
|
pbd.validSave()
|
|
pbd.validSave()
|
|
|
|
+ pbd.instance.arrval_count = detail.count
|
|
|
|
+ pbd.instance.save()
|
|
serializer.update_total()
|
|
serializer.update_total()
|
|
if pb:
|
|
if pb:
|
|
pb.count = serializer.total_count
|
|
pb.count = serializer.total_count
|
|
pb.amount = serializer.total_amount
|
|
pb.amount = serializer.total_amount
|
|
|
|
+ pb.apply_amount = serializer.total_amount
|
|
pb.save()
|
|
pb.save()
|
|
except CustomError, e:
|
|
except CustomError, e:
|
|
return JSONError(e.get_error_msg())
|
|
return JSONError(e.get_error_msg())
|