def put(self, request): if hasUpdatePurchaseRecordAccess(request.user): data = json.loads(request.body) data['last_updated_by'] = request.user.username data['transaction_date'] = data['transaction_date'].replace( ' ', 'T') for line in data['purchase_trx_lines']: if line['booking_unit_price'] == '': line.pop('booking_unit_price') if line['booking_quantity'] == '': line.pop('booking_quantity') if line['discount'] == '': line.pop('discount') if line['receipt_unit_price'] == '': line.pop('receipt_unit_price') if line['receipt_quantity'] == '': line.pop('receipt_quantity') line['last_updated_by'] = request.user.username if 'transaction_line_id' not in line.keys(): line['line_status'] = 'BOOKED' line['created_by'] = request.user.username jsondata = json.dumps(data) r = requests.put('{}'.format(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 get(self, request, transaction_number, challan_number): r = requests.get(url=SALES_TRANSACTION, params={'transaction_number': transaction_number}) if r.status_code is 200: json_data = r.json() if hasUpdatePurchaseRecordAccess(request.user): item_list = json.loads(requests.get(SALES_ITEM_LIST).text) uom = json.loads(requests.get(UNIT_OF_MEASURE).text) po_line_statuses = json.loads( requests.get(PURCHASE_ORDER_LINES_STATUS).text) po_header_statuses = json.loads( requests.get(PURCHASE_ORDER_HEADER_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'], 'header_status': po_header_statuses['purchaseOrderHeaderStatus'], 'line_status': po_line_statuses['purchaseOrderLineStatus'], 'details': json_data['sales_trx_details'][0] } template = jinja_template.get_template( 'pdf-templates/sales-challan.html') html = template.render(request, data=data) response = BytesIO() pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), response) if not pdf.err: resp = HttpResponse(response.getvalue(), content_type='application/pdf') resp[ 'Content-Disposition'] = 'attachment; filename="SalesChallan.pdf"' return resp else: return HttpResponse("Error Rendering PDF", status=400) else: template = jinja_template.get_template( 'sales/sales-line-view.html') return HttpResponse( template.render(request, data=json_data['purchase_trx_details'][0])) else: template = jinja_template.get_template( 'internal_server_error.html') return HttpResponse(template.render(request))
def get(self, request, transaction_number): r = requests.get(url=PURCHASE_TRANSACTION, params={'transaction_number': transaction_number}) if r.status_code is 200: json_data = r.json() if hasUpdatePurchaseRecordAccess(request.user): item_list = json.loads(requests.get(ITEM_LIST).text) uom = json.loads(requests.get(UNIT_OF_MEASURE).text) po_line_statuses = json.loads( requests.get(PURCHASE_ORDER_LINES_STATUS).text) po_header_statuses = json.loads( requests.get(PURCHASE_ORDER_HEADER_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'], 'header_status': po_header_statuses['purchaseOrderHeaderStatus'], 'line_status': po_line_statuses['purchaseOrderLineStatus'], 'details': json_data['purchase_trx_details'][0] } template = jinja_template.get_template( 'sales/sales-line-update.html') return HttpResponse(template.render(request, data=data)) else: template = jinja_template.get_template( 'sales/sales-line-view.html') return HttpResponse( template.render(request, data=json_data['purchase_trx_details'][0])) else: template = jinja_template.get_template( 'internal_server_error.html') return HttpResponse(template.render(request))
def put(self, request): if hasUpdatePurchaseRecordAccess(request.user): data = json.loads(request.body) data['last_updated_by'] = request.user.username data['transaction_date'] = data['transaction_date'].replace(' ','T') for line in data['purchase_trx_lines']: line['last_updated_by'] = request.user.username jsondata = json.dumps(data) r = requests.put('{}'.format(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 get(self, request, transaction_number): r = requests.get(url=PURCHASE_TRANSACTION, params={'transaction_number': transaction_number}) if r.status_code is 200: json_data = r.json() if hasUpdatePurchaseRecordAccess(request.user): data = json_data['purchase_trx_details'][0] data['last_updated_by'] = request.user.username if 'receipt_details' in data.keys(): data['order_status'] = 'CANCELLED' for line in data['receipt_details']: if line['receipt_header_status'] == 'COMPLETE': data['order_status'] = 'COMPLETE' break else: data['order_status'] = 'CANCELLED' if 'transaction_header_id' in data.keys(): data.pop('transaction_header_id') if 'transaction_date' in data.keys(): data.pop('transaction_date') if 'buyer_id' in data.keys(): data.pop('buyer_id') if 'buyer_name' in data.keys(): data.pop('buyer_name') if 'supplier_id' in data.keys(): data.pop('supplier_id') if 'purchase_trx_lines' in data.keys(): data.pop('purchase_trx_lines') if 'amount' in data.keys(): data.pop('amount') if 'created_by' in data.keys(): data.pop('created_by') if 'creation_date' in data.keys(): data.pop('creation_date') if 'last_update_date' in data.keys(): data.pop('last_update_date') if 'receipt_details' in data.keys(): data.pop('receipt_details') jsondata = json.dumps(data) r = requests.put('{}'.format(PURCHASE_TRANSACTION), json=jsondata) if r.status_code is 200: return redirect('/purchase/') 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)) else: template = jinja_template.get_template( 'internal_server_error.html') return HttpResponse(template.render(request))
def get(self, request, transaction_number): r = requests.get(url=PURCHASE_TRANSACTION, params={'transaction_number': transaction_number}) if r.status_code is 200: json_data = r.json() if hasUpdatePurchaseRecordAccess(request.user): item_list = json.loads(requests.get(PURCHASE_ITEM_LIST).text) uom = json.loads(requests.get(UNIT_OF_MEASURE).text) po_header_statuses = json.loads( requests.get(PURCHASE_ORDER_HEADER_STATUS).text) po_type = json.loads(requests.get(PURCHASE_ORDER_TYPE).text) supplier_list = json.loads(requests.get(SUPPLIER_LIST).text) if 'transaction_date' in json_data['purchase_trx_details'][0]: #json_data['purchase_trx_details'][0]['transaction_date'] = json_data['purchase_trx_details'][0]['transaction_date'].replace('/', '-') json_data['purchase_trx_details'][0][ 'transaction_date'] = json_data[ 'purchase_trx_details'][0][ 'transaction_date'].split(' ')[0] if 'receipt_details' in json_data['purchase_trx_details'][0]: for row in json_data['purchase_trx_details'][0][ 'receipt_details']: if row['challan_date']: row['challan_date'] = row['challan_date'].split( ' ')[0] if row['receipt_date']: row['receipt_date'] = row['receipt_date'].split( ' ')[0] data = { 'user': request.user.username, 'po_type': po_type['purchaseOrderType'], 'supplier_list': supplier_list['supplierLists'], 'item_list': item_list['itemDetailsList'], 'uom': uom['UnitOfMeasure'], 'header_status': po_header_statuses['purchaseOrderHeaderStatus'], 'details': json_data['purchase_trx_details'][0] } if json_data['purchase_trx_details'][0][ 'order_status'] == 'OPEN': template = jinja_template.get_template( 'purchase/purchase-line-update.html') else: template = jinja_template.get_template( 'purchase/purchase-line-view.html') #data=json_data['purchase_trx_details'][0] return HttpResponse(template.render(request, data=data)) else: if 'transaction_date' in json_data['purchase_trx_details'][0]: #json_data['purchase_trx_details'][0]['transaction_date'] = json_data['purchase_trx_details'][0]['transaction_date'].replace('/', '-') json_data['purchase_trx_details'][0][ 'transaction_date'] = json_data[ 'purchase_trx_details'][0][ 'transaction_date'].split(' ')[0] if 'receipt_details' in json_data['purchase_trx_details'][0]: for row in json_data['purchase_trx_details'][0][ 'receipt_details']: row['receipt_date'] = row['receipt_date'].split(' ')[0] row['challan_date'] = row['challan_date'].split(' ')[0] template = jinja_template.get_template( 'purchase/purchase-line-view.html') return HttpResponse( template.render(request, data=json_data['purchase_trx_details'][0])) else: template = jinja_template.get_template( 'internal_server_error.html') return HttpResponse(template.render(request))