Exemple #1
0
    def get_namespace(self, resource):
        context = self.context
        abspath = resource.get_abspath()
        # products namespace
        products_ns = []
        total_with_tax = decimal(0)
        total_pre_tax = decimal(0)
        for product_cart in self.products:
            # Get product
            product = context.root.get_resource(product_cart['name'], soft=True)
            # Check product is buyable
            if not product or not product.is_buyable(context):
                continue
            quantity = product_cart['quantity']
            id_declination = product_cart['declination']
            unit_price_with_tax = product.get_price_with_tax(id_declination)
            unit_price_with_tax = decimal(unit_price_with_tax)
            total_with_tax += unit_price_with_tax * quantity
            unit_price_pre_tax = product.get_price_without_tax(id_declination)
            unit_price_pre_tax = decimal(unit_price_pre_tax)
            total_pre_tax += unit_price_pre_tax * quantity

            product_ns = {'id': product_cart['id'],
                          'name': product.name,
                          'title': product.get_title(),
                          'href': context.get_link(product),
                          'price': unit_price_with_tax * quantity,
                          'quantity': quantity}
            products_ns.append(product_ns)
        # Build namespace
        return {'nb_products': self.get_nb_products(),
                'total_with_tax': format_price(total_with_tax),
                'total_pre_tax': format_price(total_pre_tax),
                'products': products_ns}
Exemple #2
0
 def get_namespace(self, resource, context):
     shop = get_shop(resource)
     order = shop.get_resource('orders/%s' % context.query['id'], soft=True)
     # ACL
     ac = resource.get_access_control()
     if not order or (order.get_property('customer_id') != context.user.name
             and not ac.is_admin(context.user, resource)):
         msg = ERROR(u'Your are not authorized to view this ressource')
         return context.come_back(msg, goto='/')
     # Build namespace
     namespace = order.get_namespace(context)
     # States
     namespace['state'] = {'title': states[order.workflow_state],
                           'color': states_color[order.workflow_state]}
     # Other
     namespace['order_name'] = order.name
     namespace['is_payed'] = order.get_property('is_payed')
     namespace['is_sent'] = order.get_property('is_sent')
     # Bill
     has_bill = order.get_resource('bill', soft=True) is not None
     namespace['has_bill'] = has_bill
     # Payments
     payments = shop.get_resource('payments')
     # Shipping
     shippings = shop.get_resource('shippings')
     # Prices
     for key in ['shipping_price', 'total_price']:
         namespace[key] = format_price(order.get_property(key))
     # Messages
     messages = order.get_resource('messages')
     namespace['messages'] = messages.get_namespace_messages(context)
     # Payment view
     payments = shop.get_resource('payments')
     payments_records = payments.get_payments_records(context, order.name)
     namespace['payments_view'] = []
     for payment_way, payment_record in payments_records:
         record_view = payment_way.order_view
         if record_view:
             payment_table = payment_way.get_resource('payments').handler
             record_view = record_view(
                     payment_way=payment_way,
                     payment_table=payment_table,
                     record=payment_record,
                     id_payment=payment_record.id)
             view = record_view.GET(order, context)
             namespace['payments_view'].append(view)
     # Shipping view
     shippings = shop.get_resource('shippings')
     shipping_way = order.get_property('shipping')
     shipping_way_resource = shop.get_resource('shippings/%s/' % shipping_way)
     shippings_records = shippings.get_shippings_records(context, order.name)
     if shippings_records:
         last_delivery = shippings_records[0]
         record_view = shipping_way_resource.order_view
         view = record_view.GET(order, shipping_way_resource,
                       last_delivery, context)
         namespace['shipping_view'] = view
     else:
         namespace['shipping_view'] = None
     return namespace
Exemple #3
0
 def get_price_with_tax(self, with_devise=False):
     price = self.get_property('pre_tax_price')
     tax = self.get_tax_value() / decimal(100) + 1
     price = get_arrondi(price * tax)
     if with_devise is False:
         return price
     return format_price(price)
Exemple #4
0
def show(message, user_id):
    print(message.chat.first_name)
    chat_by_user[user_id] = message.chat.id

    bot.send_message(message.chat.id,
                     menu_descr.format(message.chat.first_name))
    for row in db.get_all():
        bot.send_photo(message.chat.id, row['full_id'])

        if user_id in menu_items:
            basket = menu_items[user_id]
        else:
            basket = menu_items[user_id] = dict()

        path = row['path']
        if path in basket:
            markup = __create_menu_item_markup(basket[path].amount)
        else:
            markup = __create_menu_item_markup(0)
            basket[path] = MenuItem(0, row['price'], row['name'])

        msg = bot.send_message(message.chat.id,
                               menu_item_descr.format(
                                   row['name'], row['descr'],
                                   format_price(row['price'])),
                               parse_mode='Markdown',
                               reply_markup=markup)

        path_by_message_id[msg.message_id] = path
Exemple #5
0
def store_to_database(result):
    values = []
    search_terms = [(i, ) for i in result.keys()]
    db.store_data('search_term', search_terms)
    for key, contents in result.items():
        for x in contents.keys():
            for data_ in contents[x]:
                data = utils.format_price(data_)
                values.append(utils.build_db_format(data))
    db.store_data('contents', values)
Exemple #6
0
def get_order_list_and_cost(items):
    text = ''
    cost = 0

    for _, item in items.items():
        if item.amount > 0:
            text += '\n{}: {} шт'.format(item.name, item.amount)
            cost += item.price * item.amount
    text += '\nСтоимость заказа: {} руб'.format(format_price(cost))
    return text, cost
Exemple #7
0
 def get_total_price(self, shop, with_delivery=True, pretty=True):
     context = self.context
     total_price_with_tax = decimal(0)
     total_price_without_tax = decimal(0)
     total_weight = decimal(0)
     for cart_elt in self.products:
         product = context.root.get_resource(cart_elt['name'])
         quantity = cart_elt['quantity']
         declination = cart_elt['declination']
         unit_price_with_tax = product.get_price_with_tax(declination)
         unit_price_without_tax = product.get_price_without_tax(declination)
         total_price_with_tax += unit_price_with_tax * quantity
         total_price_without_tax += unit_price_without_tax * quantity
         total_weight += product.get_weight(declination) * quantity
     # XXX GEt Shipping price (Hardcoded, fix it)
     if with_delivery is True:
         shipping_price = self.get_shipping_ns(shop, context)['price']
         total_price_with_tax += shipping_price
         total_price_without_tax += shipping_price
     if pretty is True:
         return {'with_tax': format_price(total_price_with_tax),
                 'without_tax': format_price(total_price_without_tax)}
     return {'with_tax': total_price_with_tax,
             'without_tax': total_price_without_tax}
Exemple #8
0
 def render(cls, value, context):
     if value is None:
         return None
     # Get informations
     accept = context.accept_language
     site_root = context.resource.get_site_root()
     ws_languages = site_root.get_property('website_languages')
     lang = accept.select_language(ws_languages)
     # Render
     mesure = u'cm'
     if lang == 'en':
         inch = decimal('2.54')
         mesure = u'inch'
         value = format_price(value / inch)
     return u'%s %s' % (value, mesure)
Exemple #9
0
 def render(cls, value, context):
     if value is None:
         return None
     # Get informations
     accept = context.accept_language
     site_root = context.resource.get_site_root()
     ws_languages = site_root.get_property('website_languages')
     lang = accept.select_language(ws_languages)
     # Render
     mesure = u'cm'
     if lang == 'en':
         inch = decimal('2.54')
         mesure = u'inch'
         value = format_price(value/inch)
     return u'%s %s' % (value, mesure)
Exemple #10
0
def store_in_sqlite():
    try:
        with get_connection() as connection:
            cursor = connection.cursor()
            cursor.execute(DROP_PRODUCTS_TABLE)
            cursor.execute(CREATE_PRODUCTS_TABLE)
            with open(FILEPATH, 'r') as reader:
                values = []
                contents = csv.DictReader(reader)
                for i in contents:
                    data = format_price(i)
                    values.append(build_db_format(data))
            cursor.executemany(INSERT_INTO_PRODUCTS_STATEMENT, values)
    except Exception as error:
        connection.rollback()
        print('Error: Connection Cursor"%s"', error)
        raise
Exemple #11
0
 def get_item_value(self, resource, context, item, column):
     if column == 'numero':
         state = item.workflow_state
         href = './;order_view?id=%s' % item.name
         name = item.get_reference()
         return XMLParser(numero_template % (states_color[state], href, name))
     elif column == 'state':
         state = item.workflow_state
         state_title = states[state].gettext().encode('utf-8')
         href = './;order_view?id=%s' % item.name
         return XMLParser(numero_template % (states_color[state], href, state_title))
     elif column == 'total_price':
         price = item.get_property(column)
         return format_price(price)
     elif column == 'creation_datetime':
         value = item.get_property(column)
         accept = context.accept_language
         return format_datetime(value, accept=accept)
     return BrowseForm.get_item_value(self, resource, context, item, column)
Exemple #12
0
 def get_price_without_tax(self, with_devise=False):
     price = get_arrondi(self.get_property('pre_tax_price'))
     if with_devise is False:
         return price
     return format_price(price)
Exemple #13
0
 def format_price(self, price):
     devise = self.get_property('devise')
     symbol = Devises.symbols[devise]
     return format_price(price, symbol)
Exemple #14
0
 def get_namespace(self, resource, context):
     namespace = {
         'products': [],
         'show_ht_price': resource.show_ht_price(context),
         'see_actions': self.see_actions
     }
     abspath = resource.get_abspath()
     # Get cart
     cart = ProductCart(context)
     # Get products informations
     total_weight = decimal(0)
     total = {'with_tax': decimal(0), 'without_tax': decimal(0)}
     for product_cart in cart.products:
         # Get product
         product = context.root.get_resource(product_cart['name'],
                                             soft=True)
         # Check product is buyable
         if not product or not product.is_buyable(context):
             continue
         quantity = product_cart['quantity']
         declination = product_cart['declination']
         # Weight
         total_weight += product.get_weight(declination) * quantity
         # Prices
         unit_price_with_tax = product.get_price_with_tax(declination)
         unit_price_without_tax = product.get_price_without_tax(declination)
         total_price_with_tax = unit_price_with_tax * quantity
         total_price_without_tax = unit_price_without_tax * quantity
         price = {
             'unit': {
                 'with_tax': format_price(unit_price_with_tax),
                 'without_tax': format_price(unit_price_without_tax)
             },
             'total': {
                 'with_tax': format_price(total_price_with_tax),
                 'without_tax': format_price(total_price_without_tax)
             }
         }
         total['without_tax'] += total_price_without_tax
         total['with_tax'] += total_price_with_tax
         # All
         declination_name = product_cart['declination']
         if declination_name:
             declination_ns = product.get_declination_namespace(
                 declination_name)
         else:
             declination_ns = None
         can_add_quantity = product.is_in_stock_or_ignore_stock(
             quantity + 1, declination_name)
         namespace['products'].append({
             'id':
             product_cart['id'],
             'name':
             product.name,
             'img':
             product.get_cover_namespace(context),
             'title':
             product.get_title(),
             'href':
             context.get_link(product),
             'can_add_quantity':
             can_add_quantity,
             'quantity':
             quantity,
             'declination':
             declination_ns,
             'price':
             price
         })
     namespace['total'] = total
     # Get shippings
     namespace['ship'] = None
     if cart.shipping:
         namespace['ship'] = cart.get_shipping_ns(resource, context)
         namespace['total']['with_tax'] += namespace['ship']['price']
         namespace['total']['without_tax'] += namespace['ship']['price']
     # Format total prices
     for key in ['with_tax', 'without_tax']:
         namespace['total'][key] = format_price(namespace['total'][key])
     return namespace
Exemple #15
0
 def get_namespace(self, resource, context):
     namespace = {'products': [],
                  'show_ht_price': resource.show_ht_price(context),
                  'see_actions': self.see_actions}
     abspath = resource.get_abspath()
     # Get cart
     cart = ProductCart(context)
     # Get products informations
     total_weight = decimal(0)
     total = {'with_tax': decimal(0),
              'without_tax': decimal(0)}
     for product_cart in cart.products:
         # Get product
         product = context.root.get_resource(product_cart['name'], soft=True)
         # Check product is buyable
         if not product or not product.is_buyable(context):
             continue
         quantity = product_cart['quantity']
         declination = product_cart['declination']
         # Weight
         total_weight += product.get_weight(declination) * quantity
         # Prices
         unit_price_with_tax = product.get_price_with_tax(declination)
         unit_price_without_tax = product.get_price_without_tax(declination)
         total_price_with_tax = unit_price_with_tax * quantity
         total_price_without_tax = unit_price_without_tax * quantity
         price = {
           'unit': {'with_tax': format_price(unit_price_with_tax),
                    'without_tax': format_price(unit_price_without_tax)},
           'total': {'with_tax': format_price(total_price_with_tax),
                     'without_tax': format_price(total_price_without_tax)}}
         total['without_tax'] += total_price_without_tax
         total['with_tax'] += total_price_with_tax
         # All
         declination_name = product_cart['declination']
         if declination_name:
             declination_ns = product.get_declination_namespace(declination_name)
         else:
             declination_ns = None
         can_add_quantity = product.is_in_stock_or_ignore_stock(quantity+1,
             declination_name)
         namespace['products'].append(
           {'id': product_cart['id'],
            'name': product.name,
            'img': product.get_cover_namespace(context),
            'title': product.get_title(),
            'href': context.get_link(product),
            'can_add_quantity': can_add_quantity,
            'quantity': quantity,
            'declination': declination_ns,
            'price': price})
     namespace['total'] = total
     # Get shippings
     namespace['ship'] = None
     if cart.shipping:
         namespace['ship'] = cart.get_shipping_ns(resource, context)
         namespace['total']['with_tax'] += namespace['ship']['price']
         namespace['total']['without_tax'] += namespace['ship']['price']
     # Format total prices
     for key in ['with_tax', 'without_tax']:
         namespace['total'][key] = format_price(namespace['total'][key])
     return namespace