Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
 def get_context_data(self, **kwargs):
     # Call the base implementation first to get a context
     context = super(OrderInvoiceView, self).get_context_data(**kwargs)
     # Add in a QuerySet of all the books
     context['company'] = General.get_company_information()
     return context
Exemple #4
0
 def get_context_data(self, **kwargs):
     # Call the base implementation first to get a context
     context = super(OrderInvoiceView, self).get_context_data(**kwargs)
     # Add in a QuerySet of all the books
     context['company'] = General.get_company_information()
     return context