def put_data(request): response = BaseResponse() try: post_dict = QueryDict(request.body, encoding='utf-8') obj_id = post_dict.get('obj_id', None) add_business_parent_id = post_dict.get('add_business_parent_id', None) add_business_name = post_dict.get('add_business_name') add_business_admin_list = post_dict.getlist('add_business_admin_list', []) add_business_contact_list = post_dict.getlist('add_business_contact_list', []) add_business_memo = post_dict.get('add_business_memo') edit_data_to_db = models.BusinessUnit.objects.get(id=obj_id) # 如果业务线包含子类,不允许更换至其他父级分组 if not edit_data_to_db.parent_level.all(): edit_data_to_db.parent_unit_id = add_business_parent_id else: response.message = "this is text." edit_data_to_db.name = add_business_name edit_data_to_db.memo = add_business_memo edit_data_to_db.save() edit_data_to_db.manager.clear() edit_data_to_db.contact.clear() for obj_id in add_business_admin_list: edit_data_to_db.manager.add(user_center_models.UserGroup.objects.get(id=obj_id)) for obj_id in add_business_contact_list: edit_data_to_db.contact.add(user_center_models.UserGroup.objects.get(id=obj_id)) except Exception as e: response.status = False response.message = str(e) return response
def add_data(self, request): response = BaseResponse() try: post_dict = QueryDict(request.body, encoding='utf-8') add_business_parent_id = post_dict.get('add_business_parent_id', None) add_business_name = post_dict.get('add_business_name') add_business_admin_list = post_dict.getlist('add_business_admin_list', []) add_business_contact_list = post_dict.getlist('add_business_contact_list', []) add_business_memo = post_dict.get('add_business_memo') add_data_to_db = models.BusinessUnit( parent_unit_id=add_business_parent_id, name=add_business_name, memo=add_business_memo ) add_data_to_db.save() for obj_id in add_business_admin_list: add_data_to_db.manager.add(user_center_models.UserGroup.objects.get(id=obj_id)) for obj_id in add_business_contact_list: add_data_to_db.contact.add(user_center_models.UserGroup.objects.get(id=obj_id)) except Exception as e: response.status = False response.message = str(e) return response
def update_urlmaps_groups(request): response = BaseResponse() try: response.error = {} post_dict = QueryDict(request.body, encoding='utf-8') urlmaps_id = post_dict.get('urlmaps_id') instance_list = post_dict.getlist('instance_list') group_type = post_dict.get('group_type') urlmaps_obj = repository_models.UrlConfigHandler.objects.get(id=urlmaps_id) if group_type == 'cloud': urlmaps_obj.cloud.clear() for instance_id in instance_list: urlmaps_obj.cloud.add(CMDB_MODELS.Asset.objects.get(id=instance_id)) elif group_type == 'forward': urlmaps_obj.forward.clear() for instance_id in instance_list: urlmaps_obj.forward.add(CMDB_MODELS.Asset.objects.get(id=instance_id)) elif group_type == 'docker': urlmaps_obj.docker.clear() for instance_id in instance_list: urlmaps_obj.docker.add(CMDB_MODELS.DockerInstance.objects.get(id=instance_id)) except Exception as e: print(Exception, e) response.status = False response.message = str(e) return response
def data_create(request): response = BaseResponse() try: post_data = QueryDict(request.body, encoding='utf-8') role_name = post_data.get('role_name') role_memo = post_data.get('role_memo') permission_list = post_data.getlist('permission_list') # 创建role data_obj = USER_CENTER_MODELS.Roles( name=role_name, memo=role_memo, ) data_obj.save() # 关联permission for obj_id in permission_list: data_obj.permissions.add(obj_id) except Exception as e: print(Exception, e) response.status = False response.message = str(e) return response
def delete_assets(request): response = BaseResponse() try: delete_dict = QueryDict(request.body, encoding='utf-8') id_list = delete_dict.getlist('id_list') models.Asset.objects.filter(id__in=id_list).delete() response.message = '删除成功' except Exception as e: response.status = False response.message = str(e) return response
def add_mission(request): response = BaseResponse() post_dict = QueryDict(request.body, encoding='utf-8') mission_name = post_dict.get('mission_name') mission_type = post_dict.get('mission_type') project_name = post_dict.get('project_name') app_list = post_dict.getlist('app_list') print(post_dict) try: # create mission project. mission_project = repository_models.MissionProject( name = project_name ) mission_project.save() # create mission app for app_id in app_list: mission_app = repository_models.MissionApp( name=repository_models.Applications.objects.get(id=app_id).name ) mission_app.save() # create app ip first. get_app_instances = repository_models.AppInstances.objects.filter(group_id__name='production', group_id__app_id__id=app_id, group_id__app_id__project_id__name=project_name).values() for instance_obj in get_app_instances: mission_appinstance = repository_models.MissionAppInstance( ip = instance_obj.get('ip') ) mission_appinstance.save() mission_app.ip.add(mission_appinstance) mission_project.app.add(mission_app) # create mission mission_create = repository_models.Mission( name = mission_name, mission_type = mission_type, ) mission_create.save() mission_create.project.add(mission_project) response.data = {'mission_id': mission_create.id} except Exception as e: print(Exception, e) response.status = False response.message = str(e) return response
def put_data(request): response = BaseResponse() try: response.error = [] put_dict = QueryDict(request.body, encoding='utf-8') user_id = put_dict.get('user_id') user_name = put_dict.get('user_name') user_phone = put_dict.get('user_phone') user_email = put_dict.get('user_email') user_department = put_dict.get('user_department') user_group_list = put_dict.getlist('user_group') user_roles_list = put_dict.getlist('user_roles') update_data = user_models.UserProfile.objects.get(id=user_id) try: groups_list = user_models.UserGroup.objects.filter(id__in=user_group_list) except: groups_list = [] try: roles_list = user_models.Roles.objects.filter(id__in=user_roles_list) except: roles_list = [] update_data.username = user_name update_data.phone = user_phone update_data.email = user_email update_data.department = user_department update_data.user_groups.clear() update_data.roles.clear() update_data.user_groups.add(*groups_list) update_data.roles.add(*roles_list) update_data.save() except Exception as e: print(Exception,e) response.status = False response.message = str(e) return response
def data_update(request): response = BaseResponse() try: put_data = QueryDict(request.body, encoding='utf-8') obj_id = put_data.get('role_id') role_name = put_data.get('role_name') role_memo = put_data.get('role_memo') permission_list = put_data.getlist('permission_list') update_data = USER_CENTER_MODELS.Roles.objects.get(id=obj_id) update_data.name = role_name update_data.memo = role_memo update_data.save() update_data.permissions.clear() for obj_id in permission_list: update_data.permissions.add(obj_id) except Exception as e: print(Exception, e) response.status = False response.message = str(e) return response
class UrlHelper(object): def __init__(self, full_path): # If full_path is an UrlHelper instance, extract the full path from it if type(full_path) is UrlHelper: full_path = full_path.get_full_path() # parse the path r = urlparse.urlparse(full_path) self.path = r.path self.fragment = r.fragment self.query_dict = QueryDict(smart_bytes(r.query), mutable=True) def get_query_string(self, **kwargs): return self.query_dict.urlencode(**kwargs) def get_query_data(self): return self.query_dict def update_query_data(self, **kwargs): for key, val in kwargs.iteritems(): if hasattr(val, '__iter__'): self.query_dict.setlist(key, val) else: self.query_dict[key] = val def get_path(self): return self.path def get_full_path(self, **kwargs): query_string = self.get_query_string(**kwargs) if query_string: query_string = '?%s' % query_string fragment = self.fragment and '#%s' % iri_to_uri(self.fragment) or '' return '%s%s%s' % ( iri_to_uri(self.get_path()), query_string, fragment ) def get_full_quoted_path(self, **kwargs): return urllib.quote_plus(self.get_full_path(**kwargs), safe='/') def overload_params(self, **kwargs): for key, val in kwargs.iteritems(): uniques = set(self.query_dict.getlist(key)) uniques.add(val) self.query_dict.setlist(key, list(uniques)) def del_param(self, param): try: del self.query_dict[param] except KeyError: pass # Fail silently def del_params(self, *params, **kwargs): if not params and not kwargs: self.query = {} return if params: for param in params: self.del_param(param) if kwargs: for key, val in kwargs.iteritems(): to_keep = [x for x in self.query_dict.getlist(key) if not x.startswith(val)] self.query_dict.setlist(key, to_keep) def toggle_params(self, **params): for param, value in params.items(): value = unicode(value) if value in self.query_dict.getlist(param): self.del_params(**{param: value}) else: self.overload_params(**{param: value}) @property def hash(self): md5 = hashlib.md5() md5.update(self.get_full_path()) return md5.hexdigest() @property def query(self): return self.get_query_data() @query.setter def query(self, value): if type(value) is dict: self.query_dict = QueryDict(b'', mutable=True) self.update_query_data(**value) else: self.query_dict = QueryDict(smart_bytes(value), mutable=True) @property def query_string(self): return self.get_query_string() @query_string.setter def query_string(self, value): self.query_dict = QueryDict(smart_bytes(value), mutable=True) def __str__(self): return self.get_full_path()
def requestforquotationconfirmation(request): context = {} rfq_id = request.POST['request_for_quotation_id'] purchase_requisition_id = request.POST['purchase_requisition_id'] staff_id = request.user.id vendor_id = request.POST['vendor_id'] description = request.POST['description'] staff_info = Person.objects.get(user_id=staff_id) responses = request.read() print(responses) q = QueryDict(responses) items_id = q.getlist('item_id') print(items_id) items_name = q.getlist('item_name') print(items_name) items_quantity = q.getlist('quantity') print(items_quantity) items_unit_price = q.getlist('unit_price') print(items_unit_price) items_total_price = q.getlist('total_price') print(items_total_price) items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: total = Decimal(items_quantity[i]) * Decimal(items_unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'quantity': items_quantity[i], 'unit_price': items_unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total print(items) try: vendor_info = Vendor.objects.get(vendor_id=vendor_id) context = { 'title': 'Request For Quotation Confirmation', 'purchase_requisition_id': purchase_requisition_id, 'request_for_quotation_id': rfq_id, 'staff_id': staff_id, 'vendor_id': vendor_id, 'grand_total': grand_total, 'rows': items, 'staff_info': staff_info, 'vendor_info': vendor_info, 'description': description } return render( request, 'RequestForQuotation/requestforquotationconfirmation.html', context) except Vendor.DoesNotExist: context = { 'error': 'Please insert valid vendor ID!', 'title': 'Request Of Quotation Form', 'purchase_requisition_id': purchase_requisition_id, 'request_for_quotation_id': rfq_id, 'staff_id': staff_id, 'grand_total': grand_total, 'rows': items, 'staff_info': staff_info, 'description': description } return render(request, 'RequestForQuotation/requestforquotationform.html', context)
def requestforquotationdetails(request): context = {} rfq_id = request.POST['request_for_quotation_id'] purchase_requisition_id = request.POST['purchase_requisition_id'] staff_id = request.user.id vendor_id = request.POST['vendor_id'] description = request.POST['description'] purchase_requisition = PurchaseRequisition.objects.get( pr_id=purchase_requisition_id) staff_info = Person.objects.get(user_id=staff_id) vendor_info = Vendor.objects.get(vendor_id=vendor_id) responses = request.read() print(responses) q = QueryDict(responses) items_id = q.getlist('item_id') print(items_id) items_name = q.getlist('item_name') print(items_name) items_quantity = q.getlist('quantity') print(items_quantity) items_unit_price = q.getlist('unit_price') print(items_unit_price) items_total_price = q.getlist('total_price') print(items_total_price) items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: total = Decimal(items_quantity[i]) * Decimal(items_unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'quantity': items_quantity[i], 'unit_price': items_unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total print(items) # push the data to the database current_time = datetime.datetime.now() print(current_time) rfq_info = RequestForQuotation( request_for_quotation_id=rfq_id, time_created=current_time, total_price=grand_total, person_id=staff_info, description=description, vendor_id=vendor_info, purchase_requisition_id=purchase_requisition) rfq_info.save() request_for_quotation = RequestForQuotation.objects.get( request_for_quotation_id=rfq_id) for item in items: item_info = Item.objects.get(item_id=item['item_id']) rfq_item_info = RequestForQuotationItem( request_for_quotation_id=request_for_quotation, item_id=item_info, quantity=item['quantity'], unit_price=item['unit_price'], total_price=item['total_price']) rfq_item_info.save() # update status purchase requisition pr = PurchaseRequisition.objects.get(pr_id=purchase_requisition_id) pr.status = 'APPROVED' pr.save() print(pr) from prettytable import PrettyTable #send email to vendor x = PrettyTable() x.field_names = [ "Item ID", "Item Name", "Quantity", "Unit Price", "Total Price" ] for item in items: x.add_row([ item['item_id'], item['item_name'], item['quantity'], item['unit_price'], item['total_price'] ]) subject = 'REQUEST FOR QUOTATION INFORMATION: ' + rfq_id message = 'This is the Request of Quotation Order Information: \n' + 'Person In Charge: ' + staff_info.person_name + '\n' + staff_info.person_address + '\n' + 'Request of Quotation Number: ' + rfq_id + '\n' + '\n' + 'Time Issued: ' + str( current_time ) + '\n' + 'Vendor ID: ' + vendor_id + '\n' + 'Description: ' + description + '\n' + str( x) + '\n' email_from = settings.EMAIL_HOST_USER recipient_list = [ vendor_info.vendor_email, ] send_mail(subject, message, email_from, recipient_list) # info pass to html context = { 'title': 'Request For Quotation Details', 'purchase_requisition_id': purchase_requisition_id, 'request_for_quotation_id': rfq_id, 'vendor_id': vendor_id, 'rows': items, 'staff_info': staff_info, 'vendor_info': vendor_info, 'grand_total': grand_total, 'time_created': current_time, 'description': description } return render(request, 'RequestForQuotation/requestforquotationdetails.html', context)
def deliveryorderconfirmation(request): context = {} do_id = request.POST['delivery_order_id'] po_id = request.POST['purchase_order_id'] user_id = request.user.id staff = Person.objects.get(user_id=user_id) vendor_id = request.POST['vendor_id'] shipping_inst = request.POST['shipping_inst'] description = request.POST['description'] vendor_info = Vendor.objects.get(vendor_id=vendor_id) responses = request.read() print(responses) q = QueryDict(responses) items_id = q.getlist('item_id') print(items_id) items_name = q.getlist('item_name') print(items_name) items_quantity = q.getlist('quantity') print(items_quantity) items_unit_price = q.getlist('unit_price') print(items_unit_price) items_total_price = q.getlist('total_price') print(items_total_price) items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: total = Decimal(items_quantity[i]) * Decimal(items_unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'quantity': items_quantity[i], 'unit_price': items_unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total print(items) context = { 'title': 'Delivery Order Confirmation', 'purchase_order_id': po_id, 'delivery_order_id': do_id, 'staff_id': staff.person_id, 'vendor_id': vendor_id, 'shipping_inst': shipping_inst, 'grand_total': grand_total, 'rows': items, 'staff_info': staff, 'vendor_info': vendor_info, 'description': description, 'year': '2019/2020' } return render(request, 'DeliveryOrder/deliveryorderconfirmation.html', context)
def deliveryorderdetails(request): context = {} do_id = request.POST['delivery_order_id'] po_id = request.POST['purchase_order_id'] shipping_inst = request.POST['shipping_inst'] staff_id = request.POST['staff_id'] vendor_id = request.POST['vendor_id'] description = request.POST['description'] po = PurchaseOrder.objects.get(purchase_order_id=po_id) staff_info = Person.objects.get(person_id=staff_id) vendor_info = Vendor.objects.get(vendor_id=vendor_id) responses = request.read() print(responses) q = QueryDict(responses) items_id = q.getlist('item_id') print(items_id) items_name = q.getlist('item_name') print(items_name) items_quantity = q.getlist('quantity') print(items_quantity) items_unit_price = q.getlist('unit_price') print(items_unit_price) items_total_price = q.getlist('total_price') print(items_total_price) items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: total = Decimal(items_quantity[i]) * Decimal(items_unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'quantity': items_quantity[i], 'unit_price': items_unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total print(items) try: # push the data to the database current_time = datetime.datetime.now() print(current_time) do_info = DeliveryOrder(delivery_order_id=do_id, shipping_instructions=shipping_inst, time_created=current_time, total_price=grand_total, person_id=staff_info, description=description, vendor_id=vendor_info, purchase_order_id=po) do_info.save() delivery_order = DeliveryOrder.objects.get(delivery_order_id=do_id) for item in items: item_info = Item.objects.get(item_id=item['item_id']) do_item_info = DeliveryOrderItem(delivery_order_id=delivery_order, item_id=item_info, quantity=item['quantity'], unit_price=item['unit_price'], total_price=item['total_price']) do_item_info.save() # info pass to html context = { 'title': 'Delivery Order Details', 'purchase_order_id': po_id, 'delivery_order_id': do_id, 'staff_id': staff_id, 'vendor_id': vendor_id, 'shipping_inst': shipping_inst, 'rows': items, 'staff_info': staff_info, 'vendor_info': vendor_info, 'grand_total': grand_total, 'time_created': current_time, 'description': description } return render(request, 'DeliveryOrder/deliveryorderdetails.html', context) except IntegrityError: return render(request, 'DeliveryOrder/deliveryorderdetails.html', context)
def quotationconfirmation(request): context = {} quo_id = request.POST['quotation_id'] request_for_quotation_id = request.POST['request_for_quotation_id'] user_id = request.user.id staff = Person.objects.get(user_id = user_id) vendor_id = request.POST['vendor_id'] description = request.POST['description'] vendor_info = Vendor.objects.get(vendor_id = vendor_id) responses = request.read() print(responses) q= QueryDict(responses) items_id = q.getlist('item_id') items_name = q.getlist('item_name') items_quantity = q.getlist('quantity') items_unit_price = q.getlist('unit_price') items_total_price = q.getlist('total_price') items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: total= Decimal(items_quantity[i]) * Decimal(items_unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'quantity' : items_quantity[i], 'unit_price': items_unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total print(items) context = { 'title': 'Quotation Confirmation', 'request_for_quotation_id' : request_for_quotation_id, 'quotation_id' : quo_id, 'staff_id' : staff.person_id, 'vendor_id' : vendor_id, 'grand_total': grand_total, 'rows' : items, 'staff_info' : staff, 'vendor_info' : vendor_info, 'description' : description } return render(request,'Quotation/quotationconfirmation.html',context)
def init_from_get_params(self, get_params: QueryDict) -> bool: tags = {tag.lower() for tag in get_params.getlist(self.GET_TAG_SEARCH)} self.tags = Tag.objects.annotate(name_lower=Lower('name')).filter( name_lower__in=tags) return bool(self.tags)
def invoicedetails(request): context = {} inv_id = request.POST['invoice_id'] purchase_order_id = request.POST['purchase_order_id'] staff_id = request.POST['staff_id'] vendor_id = request.POST['vendor_id'] description = request.POST['description'] purchaseorder = PurchaseOrder.objects.get( purchase_order_id=purchase_order_id) staff_info = Person.objects.get(person_id=staff_id) vendor_info = Vendor.objects.get(vendor_id=vendor_id) responses = request.read() print(responses) q = QueryDict(responses) items_id = q.getlist('item_id') print(items_id) items_name = q.getlist('item_name') print(items_name) items_quantity = q.getlist('quantity') print(items_quantity) items_unit_price = q.getlist('unit_price') print(items_unit_price) items_total_price = q.getlist('total_price') print(items_total_price) items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: total = Decimal(items_quantity[i]) * Decimal(items_unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'quantity': items_quantity[i], 'unit_price': items_unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total print(items) # push the data to the database current_time = datetime.datetime.now() print(current_time) inv_info = Invoice( invoice_id=inv_id, time_created=current_time, total_price=grand_total, person_id=staff_info, description=description, vendor_id=vendor_info, purchase_order_id=purchaseorder, ) inv_info.save() invoice = Invoice.objects.get(invoice_id=inv_id) for item in items: item_info = Item.objects.get(item_id=item['item_id']) inv_item_info = InvoiceItem(invoice_id=invoice, item_id=item_info, quantity=item['quantity'], unit_price=item['unit_price'], total_price=item['total_price']) inv_item_info.save() # info pass to html context = { 'title': 'Invoice Details', 'purchase_order_id': purchase_order_id, 'invoice_id': inv_id, 'staff_id': staff_id, 'vendor_id': vendor_id, 'rows': items, 'staff_info': staff_info, 'vendor_info': vendor_info, 'grand_total': grand_total, 'time_created': current_time, 'description': description } return render(request, 'Invoice/invoicedetails.html', context)
def purchaserequisitionconfirmation(request): context = {} pr_id = request.POST['purchase_requisition_id'] person_id = request.POST['person_id'] responses = request.read() print(responses) q = QueryDict(responses) items_id = q.getlist('item_id') print(items_id) items_name = q.getlist('item_name') print(items_name) description = q.getlist('description') print(items_name) quantity = q.getlist('quantity') print(quantity) unit_price = q.getlist('unit_price') print(unit_price) total_price = q.getlist('total_price') print(total_price) items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) try: while (True): if (i == items_length): break total = Decimal(quantity[i]) * Decimal(unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'quantity': quantity[i], 'description': description[i], 'unit_price': unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total except: messages.error(request, 'Invalid data type') return redirect('/purchaserequisitionform') print(items) context = { 'title': 'Purchase Requisition Confirmation', 'purchase_requisition_id': pr_id, 'person_id': person_id, 'grand_total': grand_total, 'rows': items } return render(request, 'PurchaseRequisition/purchaserequisitionconfirmation.html', context)
def purchaseorderdetails(request): context = {} po_id = request.POST['purchase_order_id'] quotation_id = request.POST['quotation_id'] shipping_inst = request.POST['shipping_inst'] vendor_id = request.POST['vendor_id'] description = request.POST['description'] staff_id = request.user.id staff = Person.objects.get(user_id=staff_id) quotation = Quotation.objects.get(quotation_id=quotation_id) vendor_info = Vendor.objects.get(vendor_id=vendor_id) responses = request.read() print(responses) q = QueryDict(responses) items_id = q.getlist('item_id') print(items_id) items_name = q.getlist('item_name') print(items_name) items_quantity = q.getlist('quantity') print(items_quantity) items_unit_price = q.getlist('unit_price') print(items_unit_price) items_total_price = q.getlist('total_price') print(items_total_price) items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: total = Decimal(items_quantity[i]) * Decimal(items_unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'quantity': items_quantity[i], 'unit_price': items_unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total print(items) # push the Purchase Order data to the database current_time = datetime.datetime.now() print(current_time) po_info = PurchaseOrder(purchase_order_id=po_id, shipping_instructions=shipping_inst, time_created=current_time, total_price=grand_total, person_id=staff, description=description, vendor_id=vendor_info, quotation_id=quotation) po_info.save() # push the Purchase Order item data to the database purchase_order = PurchaseOrder.objects.get(purchase_order_id=po_id) for item in items: item_info = Item.objects.get(item_id=item['item_id']) po_item_info = PurchaseOrderItem(purchase_order_id=purchase_order, item_id=item_info, quantity=item['quantity'], unit_price=item['unit_price'], total_price=item['total_price']) po_item_info.save() #sending email to vendor x = PrettyTable() x.field_names = [ "Item ID", "Item Name", "Quantity", "Unit Price", "Total Price" ] for item in items: x.add_row([ item['item_id'], item['item_name'], item['quantity'], item['unit_price'], item['total_price'] ]) subject = 'PURCHASE ORDER INFORMATION: ' + po_id message = 'This is the Purchase Order Information: \n' + 'Person In Charge: ' + staff.person_name + '\n' + 'Ship to:' + staff.person_address + '\n' + 'Purchase Order Number: ' + po_id + '\n' + 'Quotation ID: ' + quotation.quotation_id + '\n' + 'Time Issued: ' + str( current_time ) + '\n' + 'Vendor ID: ' + vendor_id + '\n' + 'Description: ' + description + '\n' + 'Shipping Instructions: ' + shipping_inst + '\n' + str( x) + '\n' email_from = settings.EMAIL_HOST_USER recipient_list = [ vendor_info.vendor_email, ] send_mail(subject, message, email_from, recipient_list) # info pass to html context = { 'title': 'Purchase Order Details', 'quotation_id': quotation_id, 'purchase_order_id': po_id, 'vendor_id': vendor_id, 'shipping_inst': shipping_inst, 'rows': items, 'staff': staff, 'vendor_info': vendor_info, 'grand_total': grand_total, 'time_created': current_time, 'description': description } return render(request, 'PurchaseOrder/purchaseorderdetails.html', context)
def quotationdetails(request): context = {} quo_id = request.POST['quotation_id'] request_for_quotation_id = request.POST['request_for_quotation_id'] staff_id = request.POST['staff_id'] vendor_id = request.POST['vendor_id'] description = request.POST['description'] request_for_quotation = RequestForQuotation.objects.get( request_for_quotation_id=request_for_quotation_id) staff_info = Person.objects.get(person_id=staff_id) vendor_info = Vendor.objects.get(vendor_id=vendor_id) responses = request.read() print(responses) q = QueryDict(responses) items_id = q.getlist('item_id') items_name = q.getlist('item_name') items_quantity = q.getlist('quantity') items_unit_price = q.getlist('unit_price') items_total_price = q.getlist('total_price') items_reference_id = q.getlist('ref_id') items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: total = Decimal(items_quantity[i]) * Decimal(items_unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'ref_id': items_reference_id[i], 'quantity': items_quantity[i], 'unit_price': items_unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total print(items) # push the data to the database current_time = datetime.datetime.now() print(current_time) quo_info = Quotation(quotation_id=quo_id, time_created=current_time, total_price=grand_total, person_id=staff_info, description=description, vendor_id=vendor_info, request_for_quotation_id=request_for_quotation) quo_info.save() quotation = Quotation.objects.get(quotation_id=quo_id) for item in items: item_info = Item.objects.get(item_id=item['item_id']) quo_item_info = QuotationItem(quotation_id=quotation, item_id=item_info, total_price=item['total_price'], quantity=item['quantity'], ref_id=item['ref_id'], unit_price=item['unit_price']) quo_item_info.save() # info pass to html context = { 'title': 'Quotation Details', 'request_for_quotation_id': request_for_quotation_id, 'quotation_id': quo_id, 'staff_id': staff_id, 'vendor_id': vendor_id, 'rows': items, 'staff_info': staff_info, 'vendor_info': vendor_info, 'grand_total': grand_total, 'time_created': current_time, 'description': description } return render(request, 'Quotation/quotationdetails.html', context)
def purchaseorderconfirmation(request): context = {} po_id = request.POST['purchase_order_id'] quotation_id = request.POST['quotation_id'] staff_id = request.user.id staff = Person.objects.get(user_id = staff_id) ven_id = request.POST['vendor_id'] shipping_inst = request.POST['shipping_inst'] description = request.POST['description'] #vendor_info = Vendor.objects.get(vendor_id = vendor_id) #extract information from item table responses = request.read() print(responses) q= QueryDict(responses) items_id = q.getlist('item_id') print(items_id) items_name = q.getlist('item_name') print(items_name) items_quantity = q.getlist('quantity') print(items_quantity) items_unit_price = q.getlist('unit_price') print(items_unit_price) items_total_price = q.getlist('total_price') print(items_total_price) items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: total= Decimal(items_quantity[i]) * Decimal(items_unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'quantity' : items_quantity[i], 'unit_price': items_unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total print(items) try: vendor_info = Vendor.objects.get(vendor_id = ven_id) context = { 'title': 'Purchase Order Confirmation', 'quotation_id' : quotation_id, 'purchase_order_id' : po_id, 'vendor_id' : ven_id, 'shipping_inst' : shipping_inst, 'grand_total': grand_total, 'rows' : items, 'staff' : staff, 'vendor_info' : vendor_info, 'description' : description } return render(request,'PurchaseOrder/purchaseorderconfirmation.html',context) except: context = { 'error': 'Please insert valid Vendor ID', 'quotation_id' : quotation_id, 'purchase_order_id' : po_id, 'shipping_inst' : shipping_inst, 'grand_total': grand_total, 'rows' : items, 'staff' : staff, 'description' : description } return render(request,'PurchaseOrder/purchaseorderform.html',context)
def validate_list_not_empty(fieldname, querydict: QueryDict): if not querydict.getlist(fieldname): raise ValidationError(f'must pass some option on filter: {fieldname}')
def purchaserequisitionconfirmation(request): pr_id = random.randint(10000000, 99999999) user_id = request.user.id person = Person.objects.get(user_id=user_id) context = {} context2 = { 'title': 'Purchase Requisition Form', 'person_id': person.person_id, 'purchase_requisition_id': 'PR' + str(pr_id), } context2['user'] = request.user pr_id = request.POST['purchase_requisition_id'] person_id = request.POST['person_id'] responses = request.read() print(responses) q = QueryDict(responses) #Changed to check if the input is empty if q.getlist('item_id')[0] == '': print("Item name is empty") messages.warning(request, 'please fill in the blanks.') return render(request, 'PurchaseRequisition/purchaserequisitionform.html', context2) else: items_id = q.getlist('item_id') print(items_id) print(q.getlist('item_id')) if q.getlist('item_name')[0] == '': print("Item name is empty") messages.warning(request, 'please fill in the blanks.') return render(request, 'PurchaseRequisition/purchaserequisitionform.html', context2) else: items_name = q.getlist('item_name') print(items_name) print("Item name is not empty") if q.getlist('description')[0] == '': print("Item name is empty") messages.warning(request, 'please fill in the blanks.') return render(request, 'PurchaseRequisition/purchaserequisitionform.html', context2) else: description = q.getlist('description') if q.getlist('quantity')[0] == '': print("Item name is empty") messages.warning(request, 'please fill in the blanks.') return render(request, 'PurchaseRequisition/purchaserequisitionform.html', context2) else: quantity = q.getlist('quantity') print(quantity) if q.getlist('unit_price')[0] == '': print("Item name is empty") messages.warning(request, 'please fill in the blanks.') return render(request, 'PurchaseRequisition/purchaserequisitionform.html', context2) else: unit_price = q.getlist('unit_price') print(unit_price) total_price = q.getlist('total_price') print(total_price) items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: total = Decimal(quantity[i]) * Decimal(unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'quantity': quantity[i], 'description': description[i], 'unit_price': unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total print(items) context = { 'title': 'Purchase Requisition Confirmation', 'purchase_requisition_id': pr_id, 'person_id': person_id, 'grand_total': grand_total, 'rows': items, } return render(request, 'PurchaseRequisition/purchaserequisitionconfirmation.html', context)
def invoiceconfirmation(request): context = {} inv_id = request.POST['invoice_id'] pur_id = request.POST['purchase_order_id'] staff_id = request.POST['staff_id'] vendor_id = request.POST['vendor_id'] description = request.POST['description'] inv_stat = request.POST.get('invoice_status', False) staff_info = Person.objects.get(person_id=staff_id) vendor_info = Vendor.objects.get(vendor_id=vendor_id) responses = request.read() print(responses) q = QueryDict(responses) items_id = q.getlist('item_id') print(items_id) items_name = q.getlist('item_name') print(items_name) items_quantity = q.getlist('quantity') print(items_quantity) items_unit_price = q.getlist('unit_price') print(items_unit_price) items_total_price = q.getlist('total_price') print(items_total_price) items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: total = Decimal(items_quantity[i]) * Decimal(items_unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'quantity': items_quantity[i], 'unit_price': items_unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total print(items) context = { 'title': 'Invoice Confirmation', 'purchase_order_id': pur_id, 'invoice_id': inv_id, 'staff_id': staff_id, 'vendor_id': vendor_id, 'grand_total': grand_total, 'rows': items, 'staff_info': staff_info, 'vendor_info': vendor_info, 'description': description } return render(request, 'Invoice/invoiceconfirmation.html', context)
def test_querydict_single(self): post = QueryDict('field=val1') self.assertEqual(post['field'], 'val1') self.assertEqual(post.getlist('field'), ['val1']) self.assertDictEqual(post, {'field': ['val1']})
def purchaserequisitiondetails(request): context = {} pr_id = request.POST['purchase_requisition_id'] staff_id = request.POST['person_id'] print(staff_id) staff = Person.objects.get(person_id=staff_id) responses = request.read() print(responses) q = QueryDict(responses) items_id = q.getlist('item_id') print(items_id) items_name = q.getlist('item_name') print(items_name) description = q.getlist('description') print(description) quantity = q.getlist('quantity') print(quantity) unit_price = q.getlist('unit_price') print(unit_price) total_price = q.getlist('total_price') print(total_price) items = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: total = Decimal(quantity[i]) * Decimal(unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'description': description[i], 'quantity': quantity[i], 'unit_price': unit_price[i], 'total_price': total } items.append(item_table) i = i + 1 grand_total = grand_total + total print(items) # push the data to the database current_time = datetime.datetime.now() print(current_time) pr_info = PurchaseRequisition( pr_id=pr_id, person_id=staff, time_created=current_time, total_price=grand_total, description=description, ) pr_info.save() purchase_requisition = PurchaseRequisition.objects.get(pr_id=pr_id) for item in items: itemitem = Item(item_id=item['item_id'], item_name=item['item_name']) itemitem.save() pr_item_info = PurchaseRequisitionItem(pr_id=purchase_requisition, item_id=itemitem, quantity=item['quantity'], unit_price=item['unit_price']) pr_item_info.save() # info pass to html context = { 'title': 'Purchase Requisition Details', 'purchase_requisition_id': pr_id, 'staff': staff, 'rows': items, 'grand_total': grand_total, 'time_created': current_time, } return render(request, 'PurchaseRequisition/purchaserequisitiondetails.html', context)
def deliveryorderconfirmation(request): context = {} do_id = request.POST['delivery_order_id'] po_id = request.POST['purchase_order_id'] vendor_id = request.POST['vendor_id'] shipping_inst = request.POST['shipping_inst'] description = request.POST['description'] user_id = request.user.id staff = Person.objects.get(user_id=user_id) try: vendor_info = Vendor.objects.get(vendor_id=vendor_id) except Vendor.DoesNotExist: context = { 'error': 'Vendor ID: ' + vendor_id + ' is invalid', 'title': 'Delivery Order Form', 'delivery_order_id': do_id, 'purchase_order_id': po_id, 'staff_id': staff.person_id, 'vendor_id': vendor_id, } return render(request, 'DeliveryOrder/deliveryorderform.html', context) doCount = DeliveryOrder.objects.filter(delivery_order_id=do_id) if doCount.count() == 0: try: po = PurchaseOrder.objects.get(purchase_order_id=po_id) responses = request.read() #print(responses) q = QueryDict(responses) items_id = q.getlist('item_id') #print(items_id) items_name = q.getlist('item_name') #print(items_name) items_quantity = q.getlist('quantity') #print(items_quantity) items_unit_price = q.getlist('unit_price') #print(items_unit_price) items_total_price = q.getlist('total_price') #print(items_total_price) items = list() itemCheckList = list() i = 0 items_length = len(items_id) grand_total = Decimal(0) while i < items_length: itemComplete = False quantityCheckRequired = False tempTotalQuantity = 0 tempOriginalItempQuantity = 0 try: tempOriginalItempQuantity = PurchaseOrderItem.objects.filter( purchase_order_id=po.purchase_order_id).get( item_id=items_id[i]).quantity except PurchaseOrderItem.DoesNotExist: context = { 'error': 'Error in finding Item: ' + items_id[i] + ' for PO: ' + po.purchase_order_id + '. Try Again', 'title': 'Delivery Order Form', 'delivery_order_id': do_id, 'purchase_order_id': po_id, 'staff_id': staff.person_id, 'vendor_id': vendor_id, } return render(request, 'DeliveryOrder/deliveryorderform.html', context) for eachItem in DeliveryOrderItem.objects.filter( purchase_order_id=po.purchase_order_id).filter( item_id=items_id[i]): tempTotalQuantity = tempTotalQuantity + eachItem.quantity if tempTotalQuantity + Decimal( items_quantity[i] ) > tempOriginalItempQuantity or tempTotalQuantity + Decimal( items_quantity[i]) <= 0: items_quantity[ i] = tempOriginalItempQuantity - tempTotalQuantity quantityCheckRequired = True if tempTotalQuantity == tempOriginalItempQuantity: itemComplete = True if quantityCheckRequired is True or Decimal( items_quantity[i]) <= 0 or Decimal( items_quantity[i] ) > PurchaseOrderItem.objects.filter( purchase_order_id=po.purchase_order_id).get( item_id=items_id[i]).quantity: itemCheckList.append(items_id[i]) if itemComplete is False: total = Decimal(items_quantity[i]) * Decimal( items_unit_price[i]) item_table = { 'item_name': items_name[i], 'item_id': items_id[i], 'quantity': items_quantity[i], 'unit_price': items_unit_price[i], 'total_price': total } items.append(item_table) grand_total = grand_total + total i = i + 1 #print(items) if items_length <= 0: item_list = PurchaseOrderItem.objects.filter( purchase_order_id=po_id) listOfItem = list() for perItem in item_list: quantityCheckRequired = False itemComplete = False tempTotalQuantity = 0 tempOriginalItempQuantity = 0 for eachItem in DeliveryOrderItem.objects.filter( purchase_order_id=po.purchase_order_id).filter( item_id=perItem.item_id): tempTotalQuantity = tempTotalQuantity + eachItem.quantity tempOriginalItempQuantity = PurchaseOrderItem.objects.filter( purchase_order_id=po.purchase_order_id).get( item_id=perItem.item_id).quantity if tempTotalQuantity + perItem.quantity > tempOriginalItempQuantity or tempTotalQuantity + perItem.quantity <= 0: perItem.quantity = tempOriginalItempQuantity - tempTotalQuantity quantityCheckRequired = True if tempTotalQuantity == tempOriginalItempQuantity: itemComplete = True if itemComplete is False: total = perItem.quantity * perItem.unit_price item_table = { 'item_name': perItem.item_id.item_name, 'item_id': perItem.item_id, 'quantity': perItem.quantity, 'unit_price': perItem.unit_price, 'total_price': total } listOfItem.append(item_table) if len(listOfItem) <= 0: context = { 'error': 'Delivery Order Completed for ' + po_id, 'title': 'Delivery Order Form', 'delivery_order_id': do_id, 'purchase_order_id': po_id, 'staff_id': staff.person_id, 'vendor_id': vendor_id, } return render(request, 'DeliveryOrder/deliveryorderform.html', context) else: context = { 'title': 'Delivery Order Form', 'delivery_order_id': do_id, 'purchase_order_id': po_id, 'staff_id': staff.person_id, 'vendor_id': vendor_id, 'rows': listOfItem, } return render(request, 'DeliveryOrder/deliveryorderform.html', context) else: if len(items) < items_length: if len(items) <= 0: context = { 'error': 'All Items are already delivered for Purchase Order: ' + po_id, 'title': 'Delivery Order Form', 'delivery_order_id': do_id, 'purchase_order_id': po_id, 'staff_id': staff.person_id, 'vendor_id': vendor_id, 'rows': items } return render(request, 'DeliveryOrder/deliveryorderform.html', context) else: if len(itemCheckList) > 0: context = { 'error': 'Quantity for ' + ",".join(itemCheckList) + ' cannot be higher then the purchase order\'s item quantity or less then 0 ', 'title': 'Delivery Order Form', 'delivery_order_id': do_id, 'purchase_order_id': po_id, 'staff_id': staff.person_id, 'vendor_id': vendor_id, 'rows': items } return render( request, 'DeliveryOrder/deliveryorderform.html', context) else: print(itemCheckList) if len(itemCheckList) > 0: context = { 'error': 'Quantity for ' + ",".join(itemCheckList) + ' cannot be higher then the purchase order\'s item quantity or less then 0', 'title': 'Delivery Order Form', 'delivery_order_id': do_id, 'purchase_order_id': po_id, 'staff_id': staff.person_id, 'vendor_id': vendor_id, 'rows': items } return render(request, 'DeliveryOrder/deliveryorderform.html', context) else: context = { 'title': 'Delivery Order Confirmation', 'purchase_order_id': po_id, 'delivery_order_id': do_id, 'staff_id': staff.person_id, 'vendor_id': vendor_id, 'shipping_inst': shipping_inst, 'grand_total': grand_total, 'rows': items, 'staff_info': staff, 'vendor_info': vendor_info, 'description': description, 'year': '2019/2020' } return render( request, 'DeliveryOrder/deliveryorderconfirmation.html', context) except PurchaseOrder.DoesNotExist: context = { 'error': 'The Purchase Order ID ' + po_id + ' is invalid !', 'title': 'Delivery Order Form', 'delivery_order_id': do_id, 'purchase_order_id': po_id, 'staff_id': staff.person_id, 'vendor_id': vendor_id, } return render(request, 'DeliveryOrder/deliveryorderform.html', context) else: context = { 'error': 'The Delivery Order ID ' + do_id + ' already exist!', 'title': 'Delivery Order Form', 'delivery_order_id': do_id, 'purchase_order_id': po_id, 'staff_id': staff.person_id, 'vendor_id': vendor_id, } return render(request, 'DeliveryOrder/deliveryorderform.html', context)