def initStock(new_product_instance): if new_product_instance.stockable: s = Stock(sn = generate_sn(prefix = 'SK'), product = new_product_instance, qty = 0) s.save() sl = StockLog(sn = generate_sn(prefix='SKL'), \ datetime = datetime.utcnow(), \ transction_date = datetime.utcnow().date(), \ stock = s, \ changeType = 'INIT', \ increment = 0, \ qty = 0, \ notes = 'Stock initiated after new product [' + unicode(new_product_instance) + '] is added.', \ ) sl.save()
def manual_adjust(self, adjust_form): print adjust_form mode = adjust_form.get('mode') value = adjust_form.get('value') notes = adjust_form.get('notes') sl = StockLog(sn = generate_sn(prefix='SKL'), \ datetime = datetime.utcnow(), \ stock = self, \ ) sl.transction_date = datetime.today().date() sl.changeType = 'MANUAL' sl.qty = self.qty if mode == 'INC': sl.increment = value sl.notes = ', '.join([ 'Manual adjust, Type: ' + mode, \ 'Increment: ' + str(value), \ 'Notes: ' + notes, \ ]) else: sl.increment = value - self.qty sl.notes = ', '.join([ 'Manual adjust, Type: ' + mode, \ 'Target: ' + str(value), \ 'Notes: ' + notes, \ ]) sl.save() self.qty = self.qty + sl.increment print sl self.save()
def updateStock(transction_type, new_transction_instance, old_transction_instance): if new_transction_instance.product.stockable and new_transction_instance.qty != old_transction_instance.qty: if transction_type == 'PURCHASE': delta_qty = new_transction_instance.qty - old_transction_instance.qty elif transction_type == 'SALE': delta_qty = old_transction_instance.qty - new_transction_instance.qty else: delta_qty = new_transction_instance.qty - old_transction_instance.qty s = Stock.objects.get(product=new_transction_instance.product) sl = StockLog(sn = generate_sn(prefix='SKL'), \ datetime = datetime.utcnow(), \ stock = s, \ ) sl.transction_date = new_transction_instance.order.date sl.changeType = transction_type sl.increment = delta_qty sl.qty = s.qty sl.notes = ', '.join(['Type: UPDATE', \ transction_type + ': ' + new_transction_instance.order.sn, \ 'sn: ' + str(new_transction_instance.sn), \ 'old qty: ' + str(old_transction_instance.qty), \ 'new qty: ' + str(new_transction_instance.qty), \ ]) sl.save() s.qty = F('qty') + delta_qty s.save()
def vendor_add(request): if request.method == 'POST': form = VendorForm(request.POST) if form.is_valid(): p = form.save(commit=False) p.sn = generate_sn(prefix = 'VDR') p = form.save() serializer = JSONSimpleSerializer() return HttpResponse(serializer.serialize([p,], use_natural_foreign_keys=True)) else: form = VendorForm() return render_to_response('modal/main_form.html',{'action':'Add', 'module':module, 'form': form},context_instance=RequestContext(request))
def customer_add(request): if request.method == 'POST': form = CustomerForm(request.POST) if form.is_valid(): c = form.save(commit=False) c.sn = generate_sn(prefix = 'CTM') c.save() serializer = JSONSimpleSerializer() return HttpResponse(serializer.serialize([c,])) else: form = CustomerForm() return render_to_response('modal/main_form.html',{'action':'Add', 'module':module, 'form': form},context_instance=RequestContext(request))
def increaseStock(transction_type, change_type, transction_instance): if transction_instance.product.stockable: s = Stock.objects.get(product=transction_instance.product) sl = StockLog(sn = generate_sn(prefix='SKL'), \ datetime = datetime.utcnow(), \ stock = s, \ ) sl.transction_date = transction_instance.order.date sl.changeType = transction_type sl.increment = transction_instance.qty sl.qty = s.qty sl.notes = ', '.join([ 'Type: ' + change_type, \ transction_type + ': ' + transction_instance.order.sn, \ 'sn: ' + str(transction_instance.sn), \ ]) sl.save() s.qty = F('qty') + transction_instance.qty s.save()