def complete_check(self,checkbill): list_change=checkbill.GenerateChangeDetail() if len(list_change)>0: check_stockin_bill = StockBill(BillType='in', BillState='applied', StaffName=checkbill.StaffName, Creator=checkbill.Creator,RelatedBill=checkbill, BillReason='inventory_profit') check_stockout_bill = StockBill(BillType='out', BillState='applied',RelatedBill=checkbill, StaffName=checkbill.StaffName, Creator=checkbill.Creator, BillReason='inventory_loss') check_stockin_bill.save() check_stockout_bill.save() for change in list_change: #import pdb;pdb.set_trace() #update productstock ps=get_object_or_404(ProductStock,stocklocation=change.location, product=change.product) ps.quantity+=change.quantity ps.save() change.save() if change.quantity>0: change.billbase=check_stockin_bill else: change.quantity*=-1 change.billbase=check_stockout_bill change.save()
def stockbill_edit(request,type,bill_id,action): #import pdb; pdb.set_trace() if bill_id: bill=StockBill.objects.get(pk=bill_id) else: bill=StockBill(BillType=type,Creator=request.user) #bill.BillNo=bill.BillType.upper()+bill.BillNo detaillist_formated_text= bill.generat_detail_to_formatedtext() if request.method=="GET": billform=StockBillForm(instance=bill) bill_no=datetime.now().strftime('%Y%m%d%H%M%S%f') #import pdb;pdb.set_trace() #detaillist_formated_text= bill.generat_detail_to_formatedtext() return render(request,'stockmanage/stockbill_edit.html', {'form':billform, #'inline_detain_formset':detail_inlineformset, 'detaillist_formated_text':'\n'.join(detaillist_formated_text), 'bill':bill,'action':action, 'bill_no':bill_no}) elif request.method=='POST': p=request.POST.copy() if 'savedraft' in p: #import pdb;pdb.set_trace() stockbill_update_detail(request,bill) print('detailcount after return') print(bill.billdetailbase_set.count()) pass elif 'apply' in p: bill.BillState='applied' #bill.apply_stock_change() pass elif 'pass' in p: p["BillReason"]=bill.BillReason bill.BillState='checked' elif 'refused' in p: p["BillReason"]=bill.BillReason bill.BillState='draft' elif 'tt_billdetail' in p: return stockbill_update_detail(request,bill) else: raise Exception('No Such Action') #form=StockBillForm(request.POST,instance=bill) billform=StockBillForm(p,instance=bill) #detail_inlineformset=billdetail_formset_factory(request.POST,request.FILES, instance=bill) if billform.is_valid(): billform.save() if 'savedraft' in p: pass import pdb;pdb.set_trace() stockbill_update_detail(request,bill) #saved_bill.save() else: return render(request,'stockmanage/stockbill_edit.html',{"form":billform}) #if detail_inlineformset.is_valid(): #detail_inlineformset.save() if not bill_id: return HttpResponseRedirect(reverse('stockmanage:stockbill_stockin_edit',args=[bill.id])) return render(request,'stockmanage/stockbill_edit.html', {'form':billform, 'detaillist_formated_text':'\n'.join(detaillist_formated_text), 'bill':bill,'action':action})