Exemplo n.º 1
0
def product_url(product, category=None):

    if not category and product.categories.count():
        category = product.categories.all()[0]

    product_slug = localize(product, 'slug')

    if not category:
        if product_slug != '':
            return reverse('product_by_slug', kwargs={'slug': product_slug})
        else:
            return reverse('product', kwargs={'pk': product.pk})

    else:
        category_slug = localize(category, 'slug')

        if category_slug != '' and product_slug != '':
            return reverse('product_with_cat_both_by_slug',
                kwargs={'slug': product_slug, 'category_slug': category_slug})

        elif category_slug != '':
            return reverse('product_with_cat_cat_by_slug_prod_by_id',
                kwargs={'pk': product.pk, 'category_slug': category_slug})

        elif product_slug != '':
            return reverse('product_with_cat_cat_by_id_prod_by_slug',
                kwargs={'slug': product_slug, 'category_id': category.pk})

        else:
            return reverse('product_with_cat',
                kwargs={'pk': product.pk, 'category_id': category.pk})
Exemplo n.º 2
0
    def info(self):
        items = self.cart.items.all()

        total = 0
        sum = Decimal(0)
        for item in items:
            total += item.quantity
            sum += item.total_price

        return {
            'items': [
                {
                    'id': item.product.id,
                    'title': localize(item.product, 'title'),
                    'qty': item.quantity,
                    'delivery_method': item.delivery_method,
                    'price_total': "%01.2f" % item.total_price,
                    'price_unit': "%01.2f" % item.unit_price
                } for item in items],
            'size': len(items),
            'total_elements': total,
            'without_tax': self.cart.without_tax,
            'tax': self.cart.tax,
            'tax_formated': "%01.2f" % (float(sum) * 0.25),
            'total_price_raw': sum,
            'total_price': "%01.2f" % sum
        }
Exemplo n.º 3
0
def add_invoice_delivery_task(order):

    translation.activate(MAIN_LANGUAGE)

    address_post_index = ", " + order.address.post_index if order.address.post_index else ''
    delivery_address = order.address.firstname + ' ' + order.address.lastname + "\n" +\
                       order.address.street_address + "\n" + \
                       order.address.city + address_post_index + ", " + order.address.country + "\n" + \
        "Tel: " + order.address.phone + "\n" + \
        "Email: " + order.email

    rows = []

    for item in order.cart.items.all():
        rows.append({
            'id': item.pk,
            'title': localize(item.product, 'title'),
            'qty': item.quantity,
            'unitPrice': str(item.unit_price),
            'totalPrice': str(item.total_price),
            'deliveryPrice': str(item.delivery_method.delivery_price if item.delivery_method else 0)
        })

    invoice = {
        'id': order.pk,
        'date': str(order.date_created.date()),
        'email': order.email,
        'adminEmail': APP_SETTINGS['invoice']['email'],
        'fromEmail': APP_SETTINGS['invoice']['email'],
        'companyName': _('Inter24 Inc.'),

        'infoHeader':   "",

        'shippingReturnAddress':   _("InterCom Group LTD.\n" +
                        "Inter24\n" +
                        "Parnu mnt 238, 11622\n" +
                        "Tallinn, Harjumaa\n" +
                        "Estonia"),

        'infoFooterCol1': _("Logistikcenter\n" +
                          "InterCom Group AB:\n" +
                          "Parnu mnt. 238\n" +
                          "11622 Tallinn, Estonia\n" +
                          "Reg. 10113432\n" +
                          "Momsnummer SE502071470401"),

        'infoFooterCol2': _("Telefon: (+46) 812 410 605\n" +
                          "E-post: [email protected]\n" +
                          "Webbplats: www.inter24.se"),

        'infoFooterCol3': _("Bank: SEB Banken\n" +
                        "Adress: Kungstradgardsg 8,\n" +
                        "10640 Stockholm, Sweden\n" +
                        "Bankkonto: 52771027720\n" +
                        "BankGiro: 737-3459\n" +
                        "IBAN: SE8750000000052771027720\n" +
                        "SWIFT: ESSESESS"),

        'logo': APP_SETTINGS['invoice']['logo'],
	    'billAddress': delivery_address,
        'shippingAddress': delivery_address,
        'subtotal': str(order.cart.without_tax),
        'tax': APP_SETTINGS['tax'],
        'taxTotal': str(order.cart.tax),
        'total': str(order.cart.total_price),

        'rows': rows,

        'texts': {
           'sh_invoice_no': _("INVOICE No. "),
            'sh_invoice_from': _("From:"),
            'sh_invoice_to': _("To:"),
            'invoice_col_id': _("Product ID"),
            'invoice_col_description': _("Description"),
            'invoice_col_delivery': _("Delivery"),
            'invoice_col_quantity': _("Qty"),
            'invoice_col_total': _("Total"),
            'invoice_label': _("INVOICE"),
            'invoice_date_label': _("Date: "),
            'invoice_no_label': _("INVOICE No. "),
            'invoice_bill_to': _("Bill to:"),
            'invoice_ship_to': _("Ship to:"),
            'invoice_row_no_label': _("No."),
            'invoice_notes_label': _("Notes:"),
            'invoice_subtotal': _("Subtotal: "),
            'invoice_tax': _("Tax: "),
            'invoice_tax_total': _("Tax total: "),
            'invoice_total': _("Total: "),
            '$': _("SEK"),
        }
    }

    json_data = json.dumps(invoice, indent=4)
    order.invoiceData = base64.b64encode(json_data)

    order.save()

    jid = cloud.shell.execute('mvn exec:java -Dexec.args="{data}"', {'data': order.invoiceData}, return_file='report.txt', _env='maxe', cwd='/home/picloud/reporter')
Exemplo n.º 4
0
def category_url(category):
    category_slug = localize(category, 'slug')
    if category_slug != '':
        return reverse('products_in_category_by_slug', kwargs={'category_slug': category_slug})
    else:
        return reverse('products_in_category', kwargs={'category_id': category.pk})
Exemplo n.º 5
0
    def prepare_filters(self, context, query):
        all_attributes = self.get_filter_attributes(context)

        query = query.facet('attributes')

        price_ranges = self.calculate_price_ranges()
        if len(price_ranges):
            query = query.query_facet('price_range', {
                "range": {
                    "field": "price",
                    "ranges": price_ranges
                }
            })

        facets = {}
        query_facet_counts = query.facet_counts()

        for idx, value in context['selection'].items():
            if idx == 'price':
                query = query.narrow(
                    u'price:%s' % self.range_to_query(price_ranges[int(context['selection']['price'])]))
            else:
                query = query.narrow(u'attributes:"%s"' % (idx + '_' + value))

        filters = []

        if 'fields' in query_facet_counts:
            for facet in query_facet_counts['fields']['attributes']:
                (value, cnt) = facet
                match = re.match('^(\d+)_(.+)$', value)
                if match:
                    i = int(match.group(1))
                    if not i in facets:
                        facets[i] = {}
                    facets[i][match.group(2)] = cnt

            for attribute in all_attributes:
                if facets.has_key(attribute.pk):
                    filters.append({
                        'attribute': localize(attribute, "name"),
                        'id': attribute.pk,
                        'values': sorted([
                            {
                                'id': val,
                                'selected': True if context['selection'].has_key(u'%s' % attribute.pk) and
                                                    context['selection'][u'%s' % attribute.pk] == val else False,
                                'title': val,
                                'cnt': cnt
                            } for val, cnt in facets[attribute.pk].items()
                        ], key=lambda item: item['title'])
                    })

            if 'price_range' in query_facet_counts['queries']:
            #                for range in query_facet_counts['queries']['price_range']['ranges']:


                for range in query_facet_counts['queries']['price_range']['ranges']:
                    self.update_ranges(price_ranges, range)

                for idx, range in enumerate(price_ranges):
                    range['id'] = idx
                    end, start = self.transform_range(range, '...')
                    range['title'] = '%s - %s' % (start, end)
                    range['selected'] = False

                if context['selection'].has_key('price'):
                    selected_price = int(context['selection']['price'])
                    price_ranges[selected_price]['selected'] = True

                filters.append({
                    'attribute': _('Price'),
                    'id': 'price',
                    'values': price_ranges
                })
        context['filters'] = filters
        return query