def get_order_details(order_id): order = Order.objects.get_or_none(id=order_id) dictionary = OrderedDict() if not order: pass else: dictionary["order_number"] = order.order_number dictionary["customer"] = { "username": order.customer.username, "full_name": order.customer.profile.full_name} dictionary["staff"] = { "username": order.attendant_staff.username } order_type_choice_dict = dict(order.ORDER_TYPE_CHOICE) dictionary["type"] = order_type_choice_dict[order.type] order_status_dict = dict(order.ORDER_STATUS_CHOICE) dictionary["status"] = order_status_dict[order.status] dictionary["number_of_items"] = order.number_of_items dictionary["date_received"] = GlobalOperations.get_date_as_text(order.date_initiated, True) dictionary["date_fulfillment_scheduled"] = GlobalOperations.get_date_as_text(order.date_fulfillment_scheduled, False) dictionary["date_fulfillment_actual"] = GlobalOperations.get_date_as_text(order.date_fulfillment_actual, False) dictionary["date_delivered"] = GlobalOperations.get_date_as_text(order.date_delivered, False) dictionary["payment_status"] = order.payment_status dictionary["amount_payable"] = order.amount_payable dictionary["amount_paid"] = order.amount_paid order_items = order.items items_output = [] for item in order_items: item_dict = OrderedDict() item_dict["name"] = item.item_name item_dict["product"] = item.order_product.product_name item_dict["colour"] = item.colour.name item_dict["alteration"] = item.alteration.name if item.alteration else "None" item_dict["tag"] = item.item_tag items_output.append(item_dict) dictionary["items"] = items_output #modify to pick out relevants fields from order_items to create a list of order_items order_payments = order.payments payments_output = [] for order_payment in order_payments: payment_dict = OrderedDict() payment_dict["amount"] = order_payment.payment.amount payment_dict["instrument"] = order_payment.payment.instrument_text payment_dict["reference"] = order_payment.payment.reference payment_dict["cashier"] = order_payment.payment.cashier.username payment_dict["date"] = GlobalOperations.get_date_as_text(order_payment.payment.date, True) payments_output.append(payment_dict) dictionary["payments"] = payments_output return dictionary
def post(self, request, *args, **kwargs): complete_json_order = request.body complete_order_dict = json.loads(complete_json_order) customer_username = complete_order_dict["customer"] order_type = complete_order_dict["type"] product_items = complete_order_dict["productItems"] products_id_quantity = complete_order_dict["products"] date_fulfillment_scheduled = complete_order_dict[ "dateFulfilmentScheduled"] #dateFulfilmentScheduled order = Order() order.customer = User.objects.get(username=customer_username) order.date_initiated = datetime.now() order.date_fulfillment_scheduled = datetime.strptime( date_fulfillment_scheduled, '%d/%m/%Y') order.attendant_staff = request.user order.type = order_type if order.type == 'B': order.bulk_plan = BulkPlan.objects.get( owner__username=customer_username) if order.type == 'N': #calculate order price total_price = Decimal(0.0) for product in products_id_quantity: price = Product.objects.get(id=product["id"]).price total_this_product = price * product["quantity"] total_price += total_this_product order.amount = total_price order.amount_discount = 0 order.amount_payable = order.amount - order.amount_discount order.order_number = OrderOperations.generate_order_number(order) order.save() action = OrderAction( order=order, action='C', actor=request.user, ) action.save() # create order products for product in product_items: product_id = product["id"] product_serial = product["serialNumber"] product_items = product["items"] order_product = OrderProduct(order=order) order_product.product = Product.objects.get(id=product_id) order_product.serial_number = product_serial order_product.product_name = order_product.product.name order_product.product_price = order_product.product.price order_product.save() # create and add orderitems to order product for item in product_items: item_serial = item["serialNumber"] item_id = item["id"] item_colour_id = item["colourId"] item_alteration_id = item["alterationId"] item_model = ProductItem.objects.get(id=item_id).item order_item = OrderItem( order_product=order_product, serial_number=item_serial, item=item_model, ) if item_colour_id: order_item.colour = Colour.objects.get(id=item_colour_id) if item_alteration_id: order_item.alteration = Alteration.objects.get( id=item_alteration_id) order_item.item_name = item_model.name order_item.item_tag = OrderOperations.generate_item_tag( order.order_number, product_serial, item_serial) order_item.save() # send order email to_email = order.customer.email logging.error(to_email, ) if to_email: context_dictionary = dict() context_dictionary['company'] = General.get_company_information() context_dictionary['order'] = order invoice_email = Notifications.generate_email( 'invoice.htm', context_dictionary) response = Notifications.send_email( invoice_email, "New Fullers Haven Order", to_email, ) # send order SMS to_phone = order.customer.profile.phone if order.customer.profile else None logging.error(to_phone, ) if to_phone: context_data = { 'order_number': order.order_number, 'number_of_items': order.number_of_items, 'collection_date': GlobalOperations.get_date_as_text( order.date_fulfillment_scheduled, False) } response = Notifications.send_smssolutions_sms( 'sms/new_order.txt', context_data, "234{0}".format(to_phone[1:]), ) logging.debug("Good boy", ) return Response({'order_id': order.id}, status=status.HTTP_201_CREATED)
def get_order_details(order_id): order = Order.objects.get_or_none(id=order_id) dictionary = OrderedDict() if not order: pass else: dictionary["order_number"] = order.order_number dictionary["customer"] = { "username": order.customer.username, "full_name": order.customer.profile.full_name } dictionary["staff"] = {"username": order.attendant_staff.username} order_type_choice_dict = dict(order.ORDER_TYPE_CHOICE) dictionary["type"] = order_type_choice_dict[order.type] order_status_dict = dict(order.ORDER_STATUS_CHOICE) dictionary["status"] = order_status_dict[order.status] dictionary["number_of_items"] = order.number_of_items dictionary["date_received"] = GlobalOperations.get_date_as_text( order.date_initiated, True) dictionary[ "date_fulfillment_scheduled"] = GlobalOperations.get_date_as_text( order.date_fulfillment_scheduled, False) dictionary[ "date_fulfillment_actual"] = GlobalOperations.get_date_as_text( order.date_fulfillment_actual, False) dictionary["date_delivered"] = GlobalOperations.get_date_as_text( order.date_delivered, False) dictionary["payment_status"] = order.payment_status dictionary["amount_payable"] = order.amount_payable dictionary["amount_paid"] = order.amount_paid order_items = order.items items_output = [] for item in order_items: item_dict = OrderedDict() item_dict["name"] = item.item_name item_dict["product"] = item.order_product.product_name item_dict["colour"] = item.colour.name item_dict[ "alteration"] = item.alteration.name if item.alteration else "None" item_dict["tag"] = item.item_tag items_output.append(item_dict) dictionary[ "items"] = items_output #modify to pick out relevants fields from order_items to create a list of order_items order_payments = order.payments payments_output = [] for order_payment in order_payments: payment_dict = OrderedDict() payment_dict["amount"] = order_payment.payment.amount payment_dict[ "instrument"] = order_payment.payment.instrument_text payment_dict["reference"] = order_payment.payment.reference payment_dict[ "cashier"] = order_payment.payment.cashier.username payment_dict["date"] = GlobalOperations.get_date_as_text( order_payment.payment.date, True) payments_output.append(payment_dict) dictionary["payments"] = payments_output return dictionary
def _get_latest_expiration_date_text(self): if self.latest_expiration_date == date.min: return "N/A" else: return GlobalOperations.get_date_as_text(self.latest_expiration_date, False)
def post(self, request, *args, **kwargs): complete_json_order = request.body complete_order_dict = json.loads(complete_json_order) customer_username = complete_order_dict["customer"] order_type = complete_order_dict["type"] product_items = complete_order_dict["productItems"] products_id_quantity = complete_order_dict["products"] date_fulfillment_scheduled = complete_order_dict["dateFulfilmentScheduled"] #dateFulfilmentScheduled order = Order() order.customer = User.objects.get(username=customer_username) order.date_initiated = datetime.now() order.date_fulfillment_scheduled = datetime.strptime(date_fulfillment_scheduled, '%d/%m/%Y') order.attendant_staff = request.user order.type = order_type if order.type == 'B': order.bulk_plan = BulkPlan.objects.get(owner__username=customer_username) if order.type == 'N': #calculate order price total_price = Decimal(0.0) for product in products_id_quantity: price = Product.objects.get(id=product["id"]).price total_this_product = price * product["quantity"] total_price += total_this_product order.amount = total_price order.amount_discount = 0 order.amount_payable = order.amount - order.amount_discount order.order_number = OrderOperations.generate_order_number(order) order.save() action = OrderAction(order=order, action='C', actor=request.user,) action.save() # create order products for product in product_items: product_id = product["id"] product_serial = product["serialNumber"] product_items = product["items"] order_product = OrderProduct(order=order) order_product.product = Product.objects.get(id=product_id) order_product.serial_number = product_serial order_product.product_name = order_product.product.name order_product.product_price = order_product.product.price order_product.save() # create and add orderitems to order product for item in product_items: item_serial = item["serialNumber"] item_id = item["id"] item_colour_id = item["colourId"] item_alteration_id = item["alterationId"] item_model = ProductItem.objects.get(id=item_id).item order_item = OrderItem(order_product=order_product, serial_number=item_serial, item=item_model,) if item_colour_id: order_item.colour = Colour.objects.get(id=item_colour_id) if item_alteration_id: order_item.alteration = Alteration.objects.get(id=item_alteration_id) order_item.item_name = item_model.name order_item.item_tag = OrderOperations.generate_item_tag(order.order_number, product_serial, item_serial) order_item.save() # send order email to_email = order.customer.email logging.error(to_email,) if to_email: context_dictionary = dict() context_dictionary['company'] = General.get_company_information() context_dictionary['order'] = order invoice_email = Notifications.generate_email('invoice.htm', context_dictionary) response = Notifications.send_email(invoice_email, "New Fullers Haven Order", to_email,) # send order SMS to_phone = order.customer.profile.phone if order.customer.profile else None logging.error(to_phone,) if to_phone: context_data = {'order_number': order.order_number, 'number_of_items': order.number_of_items, 'collection_date': GlobalOperations.get_date_as_text(order.date_fulfillment_scheduled, False) } response = Notifications.send_smssolutions_sms('sms/new_order.txt', context_data, "234{0}".format(to_phone[1:]),) logging.debug("Good boy",) return Response({'order_id' : order.id}, status=status.HTTP_201_CREATED)