Beispiel #1
0
def from_dish(dish: Dish, language: str) -> str:
    dish_content = ""
    if language == 'uz':
        if dish.description_uz:
            dish_content += dish.get_full_name_uz()
            dish_content += '\n\n'
            dish_content += dish.description_uz
            dish_content += '\n\n'
    else:
        if dish.description:
            dish_content += dish.get_full_name()
            dish_content += '\n\n'
            dish_content += dish.description
            dish_content += '\n\n'
    price = dish.price * settings.get_currency_value()
    price_currency = 'sum'
    if dish.show_usd:
        price = dish.price
        price_currency = 'usd'
    if dish.is_sale:
        sale_price = dish.sale_price * settings.get_currency_value()
        if dish.show_usd:
            sale_price = dish.sale_price
        dish_content += "{}: <s>{}</s> {} {}".format(get_string('dish.price', language),
                                       _format_number(price), _format_number(sale_price), get_string(price_currency, language))
    else:
        dish_content += "{}: {} {}".format(get_string('dish.price', language),
                                       _format_number(price), get_string(price_currency, language))
    return dish_content
Beispiel #2
0
def from_cart_items(cart_items, language, total) -> str:
    cart_contains = ''
    cart_contains += '<b>{}</b>:'.format(get_string('catalog.cart', language))
    cart_contains += '\n\n'
    cart_str_item = "<b>{counter}. {name}</b>\n{count} x {price} = {sum}"
    currency_value = settings.get_currency_value()
    counter = 0
    for cart_item in cart_items:
        counter += 1
        if language == 'uz':
            dish_item = cart_str_item.format(
                counter=counter,
                name=cart_item.dish.description_uz,
                count=cart_item.count,
                price=_format_number(cart_item.dish.price * currency_value),
                sum=_format_number(cart_item.count * cart_item.dish.price *
                                   currency_value))
        else:
            dish_item = cart_str_item.format(
                counter=counter,
                name=cart_item.dish.description,
                count=cart_item.count,
                price=_format_number(cart_item.dish.price * currency_value),
                sum=_format_number(cart_item.count * cart_item.dish.price *
                                   currency_value))
        dish_item += " {}\n\n".format(get_string('sum', language))
        cart_contains += dish_item
    cart_contains += "\n<b>{}</b>: {} {}".format(
        get_string('cart.summary', language),
        _format_number(total * currency_value), get_string('sum', language))

    return cart_contains
Beispiel #3
0
 def fill_from_settings(self):
     delivery_cost = settings.get_delivery_cost()
     self.first_3_km.data = delivery_cost[0]
     self.others_km.data = delivery_cost[1]
     self.limit_price.data = settings.get_limit_delivery_price()
     self.limit_km.data = settings.get_limit_delivery_km()
     self.currency_value.data = settings.get_currency_value()
Beispiel #4
0
def from_order(order: Order, language: str, total: int) -> str:
    currency_value = settings.get_currency_value()
    order_content = "<b>{}:</b>".format(get_string('your_order', language))
    order_content += '\n\n'
    order_content += '<b>{phone}:</b> {phone_value}\n'.format(
        phone=get_string('phone', language), phone_value=order.phone_number)
    order_content += '<b>{payment_type}:</b> {payment_type_value}\n' \
        .format(payment_type=get_string('payment', language),
                payment_type_value=from_order_payment_method(order.payment_method, language))
    order_content += '<b>{shipping_method}:</b> {shipping_method_value}\n'.format(
        shipping_method=get_string('shipping_method', language),
        shipping_method_value=from_order_shipping_method(
            order.shipping_method, language))
    if order.address_txt:
        order_content += '<b>{address}:</b> {address_value}\n'.format(
            address=get_string('address', language),
            address_value=order.address_txt)
    elif order.location:
        order_content += '<b>{address}:</b> {address_value}\n'.format(
            address=get_string('address', language),
            address_value=order.location.address)
        order_content += '<b>Дистанция:</b> {}\n'.format(order.distance)
    order_content += '\n\n'
    order_item_tmpl = '<b>{counter}. {name}</b>\n{count} x {price} = {sum} {sum_str}\n'
    counter = 0
    for order_item in order.order_items.all():
        counter += 1
        dish = order_item.dish
        if language == 'uz':
            dish_name = dish.name
        else:
            dish_name = dish.name
        order_item_str = order_item_tmpl.format(
            counter=counter,
            name=dish_name,
            count=order_item.count,
            price=_format_number(dish.price * currency_value),
            sum=_format_number(order_item.count * dish.price * currency_value),
            sum_str=get_string('sum', language))
        order_content += order_item_str + '\n'
    if order.delivery_price:
        order_content += "<b>{}</b> {} {}".format(
            get_string('cart.summary', language),
            _format_number(total * currency_value + order.delivery_price),
            get_string('sum', language))
    else:
        order_content += "<b>{}</b> {} {}".format(
            get_string('cart.summary', language),
            _format_number(total * currency_value),
            get_string('sum', language))
    if not order.delivery_price and order.address_txt:
        order_content += '\n\n'
        order_content += '<i>{}</i>'.format(
            get_string('delivery_price_without_location', language))
    if order.delivery_price:
        order_content += '\n\n'
        order_content += '<i>{}</i>: {} {}'.format(
            get_string('delivery_price', language),
            _format_number(order.delivery_price), get_string('sum', language))
    return order_content
Beispiel #5
0
def from_order_items_to_labeled_prices(order_items: List[OrderItem],
                                       language) -> List[LabeledPrice]:
    currency_value = settings.get_currency_value()
    return [
        LabeledPrice(
            from_dish_name(oi.dish, language) + ' x ' + str(oi.count),
            int(oi.count * oi.dish.price * currency_value * 100))
        for oi in order_items
    ]
Beispiel #6
0
def from_order_items_to_labeled_prices(order, language) -> List[LabeledPrice]:
    order_items = order.order_items.all()
    currency_value = settings.get_currency_value()
    prices = []
    for oi in order_items:
        if oi.dish.is_sale:
            prices.append(LabeledPrice(from_dish_full_name(oi.dish, language) + ' x ' + str(oi.count), int(oi.count * oi.dish.sale_price * currency_value * 100)))
        else:
            prices.append(LabeledPrice(from_dish_full_name(oi.dish, language) + ' x ' + str(oi.count), int(oi.count * oi.dish.price * currency_value * 100)))
    if order.delivery_price:
        prices.append(LabeledPrice(get_string('delivery_price'), int(order.delivery_price * currency_value * 100)))
    return prices
Beispiel #7
0
def from_order(order: Order, language: str, total: int) -> str:
    currency_value = settings.get_currency_value()
    order_content = "<b>{}:</b>".format(get_string('your_order', language))
    order_content += '\n\n'
    order_content += '<b>{phone}:</b> {phone_value}\n'.format(
        phone=get_string('phone', language), phone_value=order.phone_number)
    order_content += '<b>{payment_type}:</b> {payment_type_value}\n' \
        .format(payment_type=get_string('payment', language),
                payment_type_value=from_order_payment_method(order.payment_method, language))
    order_content += '<b>{shipping_method}:</b> {shipping_method_value}\n'.format(
        shipping_method=get_string('shipping_method', language),
        shipping_method_value=from_order_shipping_method(
            order.shipping_method, language))
    order_content += '<b>Количество</b>: {count_value}'.format(
        count_value=order.order_items.all()[0].count)
    return order_content
Beispiel #8
0
def from_order_notification(order: Order, total_sum):
    currency_value = settings.get_currency_value()
    order_content = "<b>Новый заказ! #{}</b>".format(order.id)
    order_content += '\n\n'
    order_content += '<b>Номер телефона:</b> {}\n'.format(order.phone_number)
    order_content += '<b>Имя покупателя:</b> {}\n'.format(order.user_name)
    order_content += '<b>Способ оплаты:</b> {}\n'.format(from_order_payment_method(order.payment_method, 'ru'))
    if order.address_txt:
        order_content += '<b>Адрес:</b> {}\n'.format(order.address_txt)
    elif order.location:
        order_content += '<b>Адрес:</b> {}\n'.format(order.location.address)
        order_content += '<b>Дистанция: </b> {}\n'.format(order.distance)
    order_content += '\n\n\U0001F6D2 Корзина:\n'
    order_item_tmpl = '<b>{counter}. {name}</b>\n    {count} x {price} = {sum} сум\n'
    order_items = order.order_items.all()
    grouped_order_items = {}
    categories_list = [oi.dish.category for oi in order_items]
    categories_list = list(set(categories_list))
    for category in categories_list:
        order_items_by_category = list(filter(lambda oi: oi.dish.category_id == category.id, order_items))
        grouped_order_items[category.name] = order_items_by_category
    counter = 0
    for oi in order_items:
        counter += 1
        group_content = '\n'
        if oi.dish.is_sale:
            dish_price = oi.dish.sale_price * currency_value
        else:
            dish_price = oi.dish.price * currency_value
        group_content += order_item_tmpl.format(counter=counter,
                                               name=oi.dish.get_full_name(),
                                               count=oi.count,
                                               price=_format_number(dish_price),
                                               sum=_format_number(dish_price * oi.count))
        order_content += group_content
    order_content += "\n<b>Итого: </b>: {} сум".format(_format_number(order.total_amount))
    if order.delivery_price:
        order_content += '\n\n'
        order_content += '<b>Стоимость доставки</b>: {} сум'.format(_format_number(order.delivery_price))
    return order_content
Beispiel #9
0
def from_dish(dish: Dish, language: str) -> str:
    dish_content = ""
    if language == 'uz':
        if dish.description_uz:
            dish_content += '<b>{}</b>'.format(dish.name)
            dish_content += '\n\n'
            dish_content += dish.description
            dish_content += '\n'
    else:
        if dish.description:
            dish_content += '<b>{}</b>'.format(dish.name)
            dish_content += '\n\n'
            dish_content += dish.description
            dish_content += '\n'
    price = dish.price * settings.get_currency_value()
    price_currency = 'sum'
    if dish.show_usd:
        price = dish.price
        price_currency = 'usd'
    dish_content += "{}: {} {}".format(get_string('dish.price', language),
                                       _format_number(price),
                                       get_string(price_currency, language))
    return dish_content