def post(self, request): if hasAddPurchaseRecordAccess(request.user): data = json.loads(request.body) data['order_status'] = 'BOOKED' data['created_by'] = request.user.username data['last_updated_by'] = request.user.username if data['transaction_date']: data['transaction_date'] = data['transaction_date'].replace( ' ', 'T') for line in data['purchase_trx_lines']: line['line_status'] = 'BOOKED' line['created_by'] = request.user.username line['last_updated_by'] = request.user.username jsondata = json.dumps(data) r = requests.post(url=PURCHASE_TRANSACTION, json=jsondata) if r.status_code is 200: to_json = {'message': 'ok'} return HttpResponse(json.dumps(to_json)) else: template = jinja_template.get_template( 'internal_server_error.html') return HttpResponse(template.render(request)) else: template = jinja_template.get_template('access_denied.html') return HttpResponse(template.render(request))
def post(self, request): if hasAddPurchaseRecordAccess(request.user): data = json.loads(request.body) data['order_status'] = 'OPEN' #data['purchase_trx_number'] = 'PO_'+ str(random.randint(0, 1000)) data['created_by'] = request.user.username data['last_updated_by'] = request.user.username # if data['transaction_date']: # data['transaction_date'] = data['transaction_date'].replace('/', '-') for line in data['purchase_trx_lines']: line['created_by'] = request.user.username line['last_updated_by'] = request.user.username if line['booking_unit_price'] == '': line.pop('booking_unit_price') if line['booking_quantity'] == '': line.pop('booking_quantity') jsondata = json.dumps(data) r = requests.post(url=PURCHASE_TRANSACTION, json=jsondata) if r.status_code is 200: to_json = {'message': 'ok'} return HttpResponse(json.dumps(to_json)) elif r.status_code == 422: to_json = json.loads(r.content)['errors'] return HttpResponse(json.dumps(to_json), status=422) else: template = jinja_template.get_template( 'internal_server_error.html') return HttpResponse(template.render(request)) else: template = jinja_template.get_template('access_denied.html') return HttpResponse(template.render(request))
def get(self, request, transaction_number, challan_number): if hasAddPurchaseRecordAccess(request.user): receipt_details = json.loads( requests.get(RECEIPT_SEARCH + 'challan_number=' + challan_number).text) receipt_details['receipt_details'][0][ 'receipt_header_status'] = 'CANCEL' receipt_details['receipt_details'][0].pop('created_by') receipt_details['receipt_details'][0].pop('creation_date') receipt_details['receipt_details'][0][ 'last_updated_by'] = request.user.username if 'receipt_lines' in receipt_details['receipt_details'][0].keys(): receipt_details['receipt_details'][0].pop('receipt_lines') if 'receipt_date' in receipt_details['receipt_details'][0].keys(): receipt_details['receipt_details'][0].pop('receipt_date') if 'receipt_number' in receipt_details['receipt_details'][0].keys( ): receipt_details['receipt_details'][0].pop('receipt_number') if 'challan_date' in receipt_details['receipt_details'][0].keys(): receipt_details['receipt_details'][0].pop('challan_date') if 'last_update_date' in receipt_details['receipt_details'][ 0].keys(): receipt_details['receipt_details'][0].pop('last_update_date') if 'bata' in receipt_details['receipt_details'][0].keys(): receipt_details['receipt_details'][0].pop('bata') if 'net_weight' in receipt_details['receipt_details'][0].keys(): receipt_details['receipt_details'][0].pop('net_weight') if 'average_weight' in receipt_details['receipt_details'][0].keys( ): receipt_details['receipt_details'][0].pop('average_weight') if 'total_bags' in receipt_details['receipt_details'][0].keys(): receipt_details['receipt_details'][0].pop('total_bags') jsondata = json.dumps(receipt_details['receipt_details'][0]) r = requests.put(url=RECEIPT, json=jsondata) if r.status_code is 200: to_json = {'message': 'ok'} return redirect('/purchase/' + transaction_number) elif r.status_code == 422: to_json = json.loads(r.content)['errors'] return HttpResponse(json.dumps(to_json), status=422) else: template = jinja_template.get_template( 'internal_server_error.html') return HttpResponse(template.render(request))
def get(self, request, transaction_number, challan_number): if hasAddPurchaseRecordAccess(request.user): item_list = json.loads(requests.get(PURCHASE_ITEM_LIST).text) uom = json.loads(requests.get(UNIT_OF_MEASURE).text) po_receipt_statuses = json.loads( requests.get(RECEIPT_LINE_STATUS).text) receipt_details = json.loads( requests.get(RECEIPT_SEARCH + 'challan_number=' + challan_number).text) if receipt_details['receipt_details'][0]['challan_date']: receipt_details['receipt_details'][0][ 'challan_date'] = receipt_details['receipt_details'][0][ 'challan_date'].split(' ')[0] if 'receipt_date' in receipt_details['receipt_details'][0].keys(): if receipt_details['receipt_details'][0]['receipt_date']: receipt_details['receipt_details'][0][ 'receipt_date'] = receipt_details['receipt_details'][ 0]['receipt_date'].split(' ')[0] receipt = clearDictionary(receipt_details['receipt_details'][0]) data = { 'transaction_number': transaction_number, 'item_list': item_list['itemDetailsList'], 'uom': uom['UnitOfMeasure'], 'po_receipt_statuses': po_receipt_statuses['lookup_details'], 'details': receipt } if receipt_details['receipt_details'][0][ 'receipt_header_status'] == 'OPEN': template = jinja_template.get_template( 'purchase/purchase-receipt-update.html') else: template = jinja_template.get_template( 'purchase/purchase-receipt-view-only.html') return HttpResponse(template.render(request, data=data)) else: template = jinja_template.get_template('access_denied.html') return HttpResponse(template.render(request))
def get(self, request, transaction_number): if hasAddPurchaseRecordAccess(request.user): item_list = json.loads(requests.get(PURCHASE_ITEM_LIST).text) uom = json.loads(requests.get(UNIT_OF_MEASURE).text) # po_line_statuses = requests.get(PURCHASE_ORDER_LINES_STATUS) po_receipt_statuses = json.loads( requests.get(RECEIPT_LINE_STATUS).text) # po_type = json.loads(requests.get(PURCHASE_ORDER_TYPE).text) # supplier_list = json.loads(requests.get(SUPPLIER_LIST).text) # # data= {'user' : request.user.username, # 'po_type' : po_type['purchaseOrderType'], # 'supplier_list' : supplier_list['supplierLists'], # 'item_list' : item_list['itemDetailsList'], # 'uom' : uom['UnitOfMeasure'] # } data = {} data['created_by'] = request.user.username data['last_updated_by'] = request.user.username data['source_transaction_header_id'] = transaction_number data['source_transaction_type'] = 'PURCHASE' challan_data = json.loads(requests.post(RECEIPT, json=data).text) if challan_data['challan_date']: challan_data['challan_date'] = challan_data[ 'challan_date'].split(' ')[0] if 'receipt_date' in challan_data.keys(): if challan_data['receipt_date']: challan_data['receipt_date'] = challan_data[ 'receipt_date'].split(' ')[0] data = { 'transaction_number': transaction_number, 'item_list': item_list['itemDetailsList'], 'uom': uom['UnitOfMeasure'], 'po_receipt_statuses': po_receipt_statuses['lookup_details'], 'details': challan_data } template = jinja_template.get_template( 'purchase/purchase-receipt-update.html') return HttpResponse(template.render(request, data=data)) else: template = jinja_template.get_template('access_denied.html') return HttpResponse(template.render(request))
def get(self, request): if hasAddPurchaseRecordAccess(request.user): item_list = json.loads(requests.get(ITEM_LIST).text) uom = json.loads(requests.get(UNIT_OF_MEASURE).text) # po_line_statuses = requests.get(PURCHASE_ORDER_LINES_STATUS) # po_header_statuses = requests.get(PURCHASE_ORDER_HEADER_STATUS) po_type = json.loads(requests.get(PURCHASE_ORDER_TYPE).text) supplier_list = json.loads(requests.get(SUPPLIER_LIST).text) data = { 'user': request.user.username, 'po_type': po_type['purchaseOrderType'], 'supplier_list': supplier_list['supplierLists'], 'item_list': item_list['itemDetailsList'], 'uom': uom['UnitOfMeasure'] } template = jinja_template.get_template('sales/sales-line-add.html') return HttpResponse(template.render(request, data=data)) else: template = jinja_template.get_template('access_denied.html') return HttpResponse(template.render(request))
def put(self, request, transaction_number, challan_number): if hasAddPurchaseRecordAccess(request.user): data = json.loads(request.body) #data['source_transaction_header_id'] = transaction_number #data['source_transaction_type'] = 'PURCHASE' data['last_updated_by'] = request.user.username if data['bata'] == '': data.pop('bata') if data['net_weight'] == '': data.pop('net_weight') total_bags = 0 all_line_has_bags = False if 'receipt_lines' in data.keys(): all_line_has_bags = True for line in data['receipt_lines']: line['last_updated_by'] = request.user.username if 'number_of_bags' in line.keys(): if line['number_of_bags'] != '' and isFloat( line['number_of_bags']): total_bags += float(line['number_of_bags']) all_line_has_bags = all_line_has_bags & True else: line.pop('number_of_bags') all_line_has_bags = all_line_has_bags & False if line['unit_price'] == '': line.pop('unit_price') if line['item_id'] == '': line.pop('item_id') line['quantity'] = 0 if line['load_unload_area'] == '': line.pop('load_unload_area') if line['discount'] == '': line.pop('discount') if 'receipt_line_id' in line.keys(): if line['receipt_line_id'] == '': line.pop('receipt_line_id') if total_bags > 0 and 'bata' in data.keys( ) and 'net_weight' in data.keys() and all_line_has_bags: net_weight = float(data['net_weight']) weight = net_weight - float(data['bata']) average_weight = weight / total_bags for line in data['receipt_lines']: line['quantity'] = average_weight * float( line['number_of_bags']) data['average_weight'] = average_weight data['total_bags'] = total_bags else: data['average_weight'] = 0 data['total_bags'] = 0 jsondata = json.dumps(data) r = requests.put(url=RECEIPT, json=jsondata) if r.status_code is 200: to_json = {'message': 'ok'} return HttpResponse(json.dumps(to_json), status=200) elif r.status_code == 422: to_json = json.loads(r.content)['errors'] return HttpResponse(json.dumps(to_json), status=422) else: template = jinja_template.get_template( 'internal_server_error.html') return HttpResponse(template.render(request)) else: template = jinja_template.get_template('access_denied.html') return HttpResponse(template.render(request))