コード例 #1
0
ファイル: views.py プロジェクト: alvaromlg/django-lfs
def calculate_price(request, id):
    """Calculates the price of the product on base of choosen properties after
    a customer has selected a property on product view.
    """
    product = Product.objects.get(pk=id)
    property_price = _calculate_property_price(request)

    if product.for_sale:
        for_sale_standard_price = product.get_standard_price(request, with_properties=False)
        for_sale_standard_price += property_price

        for_sale_price = product.get_for_sale_price(request, with_properties=False)
        for_sale_price += property_price
    else:
        for_sale_standard_price = 0
        for_sale_price = 0

    price = product.get_price(request, with_properties=False)
    price += property_price

    if product.get_active_packing_unit():
        packing_result = calculate_packing(request, id, with_properties=True, as_string=True)
    else:
        packing_result = ""

    result = simplejson.dumps({
        "price": lfs_tags.currency(price, request),
        "for-sale-standard-price": lfs_tags.currency(for_sale_standard_price),
        "for-sale-price": lfs_tags.currency(for_sale_price),
        "packing-result": packing_result,
        "message": _("Price has been changed according to your selection."),
    }, cls=LazyEncoder)

    return HttpResponse(result)
コード例 #2
0
ファイル: views.py プロジェクト: amritpati14/django-lfs
def calculate_price(request, id):
    """Calculates the price of the product on base of choosen properties after
    a customer has selected a property on product view.
    """
    product = Product.objects.get(pk=id)
    property_price = _calculate_property_price(request)

    if product.for_sale:
        for_sale_standard_price = product.get_standard_price(request, with_properties=False)
        for_sale_standard_price += property_price

        for_sale_price = product.get_for_sale_price(request, with_properties=False)
        for_sale_price += property_price
    else:
        for_sale_standard_price = 0
        for_sale_price = 0

    price = product.get_price(request, with_properties=False)
    price += property_price

    if product.get_active_packing_unit():
        packing_result = calculate_packing(request, id, with_properties=True, as_string=True)
    else:
        packing_result = ""

    result = simplejson.dumps({
        "price": lfs_tags.currency(price, request),
        "for-sale-standard-price": lfs_tags.currency(for_sale_standard_price),
        "for-sale-price": lfs_tags.currency(for_sale_price),
        "packing-result": packing_result,
        "message": _("Price has been changed according to your selection."),
    }, cls=LazyEncoder)

    return HttpResponse(result, mimetype='application/json')
コード例 #3
0
ファイル: pdfs.py プロジェクト: diefenbach-fz/flowzone-mails
    def create_pdf(self):
        pdf = StringIO.StringIO()

        doc = SimpleDocTemplate(pdf)
        doc.leftMargin = 31
        doc.rightMargin = 31
        doc.topMargin = 390
        doc.bottomMargin = 110

        story = []
        order_items = [["Artikelnr.", "Name", "Menge", "Preis", "Summe"]]
        for item in self.order.items.all():
            amount = str(item.amount) + " " + item.product.unit
            price = currency(item.product_price_gross)
            total = currency(item.price_gross)
            order_items.append(
                [item.product.sku, item.product_name, amount, price, total])

        order_items_table = Table(order_items, (80, 238, 60, 70, 70))
        order_items_table.setStyle(dn_order_items_style)

        story.append(order_items_table)
        story.append(Spacer(1, 40))

        # END
        story.append(Paragraph(getattr(settings, "DN_END"), styleN))

        doc.build(story, onFirstPage=self.page, onLaterPages=self.page)
        pdf.seek(0)
        return pdf
コード例 #4
0
ファイル: views.py プロジェクト: cloudappsetup/django-lfs
def calculate_price(request, id):
    """Calculates the price of the product on base of choosen properties after
    a customer has selected a property on product view.
    """
    product = Product.objects.get(pk=id)

    property_price = 0
    for key, option_id in request.POST.items():
        if key.startswith("property"):
            try:
                po = PropertyOption.objects.get(pk=option_id)
            except (ValueError, PropertyOption.DoesNotExist):
                pass
            else:
                if po.property.add_price:
                    property_price += po.price

    if product.for_sale:
        for_sale_standard_price = product.get_standard_price(with_properties=False)
        for_sale_standard_price += property_price
    else:
        for_sale_standard_price = 0
        price = product.get_price(request, with_properties=False)
        price += property_price

    result = simplejson.dumps({
        "price": lfs_tags.currency(price, request),
        "for-sale-standard-price": lfs_tags.currency(for_sale_standard_price),
        "message": _("Price has been changed according to your selection."),
    }, cls=LazyEncoder)

    return HttpResponse(result)
コード例 #5
0
ファイル: pdfs.py プロジェクト: diefenbach-fz/flowzone-mails
    def create_pdf(self):
        pdf = StringIO.StringIO()

        doc = SimpleDocTemplate(pdf)
        doc.leftMargin=31
        doc.rightMargin=31
        doc.topMargin=390
        doc.bottomMargin=110

        story = []
        order_items = [["Artikelnr.", "Name", "Menge", "Preis", "Summe"]]
        for item in self.order.items.all():
            amount = str(item.amount) + " " + item.product.unit
            price = currency(item.product_price_gross)
            total = currency(item.price_gross)
            order_items.append([item.product.sku, item.product_name, amount, price, total])

        order_items_table = Table(order_items, (80, 238, 60, 70, 70))
        order_items_table.setStyle(dn_order_items_style)

        story.append(order_items_table)
        story.append(Spacer(1, 40))

        # END
        story.append(Paragraph(getattr(settings, "DN_END"), styleN))

        doc.build(story, onFirstPage=self.page, onLaterPages=self.page)
        pdf.seek(0)
        return pdf
コード例 #6
0
ファイル: pdfs.py プロジェクト: diefenbach-fz/flowzone-mails
    def create_pdf(self):
        pdf = StringIO.StringIO()

        doc = SimpleDocTemplate(pdf)
        doc.leftMargin=31
        doc.rightMargin=31
        doc.topMargin=390
        doc.bottomMargin=110

        story = []
        order_items = [["Artikelnr.", "Name", "Menge", "Preis", "Summe"]]
        for item in self.order.items.all():
            # Amount
            amount = str(item.amount)
            if item.product.unit:
                amount += " " + item.product.unit
            if item.product.active_packing_unit:
                amount += "\n(" + str(packages(item)) + " " + item.product.packing_unit_unit + ")"
            # Name
            item_name = item.product_name
            for property in item.product.get_displayed_properties():
                item_name += "\n" + property["title"] + ": " + property["value"] + " " + property["unit"]
            for property in item.product.get_variant_properties():
                item_name += "\n" + property["title"] + ": " + property["value"] + " " + property["unit"]
            if item.product.is_configurable_product():
                for property in item.get_properties():
                    item_name += "\n" + property["title"] + ": " + property["value"] + property["unit"] + " " + property["price"]
            price = currency(item.product_price_gross)
            if item.product.price_unit:
                price += " / " + item.product.price_unit
            total = currency(item.price_gross)
            order_items.append([item.product.sku, item_name, amount, price, total])

        if self.order.voucher_number:
            order_items.append(["", "Voucher", "1", currency(self.order.voucher_price), currency(self.order.voucher_price)])

        order_items.append(["", "Versandart (" + self.order.shipping_method.name + ")", "1", currency(self.order.shipping_price), currency(self.order.shipping_price)])
        order_items.append(["", "Zahlungsweise (" + self.order.payment_method.name + ")", "1", currency(self.order.payment_price), currency(self.order.payment_price)])

        order_items.append(["", "", "", "Summe", currency(self.order.price)])
        order_items.append(["", "", "", "Inkl. MwSt", currency(self.order.tax)])

        order_items_table = Table(order_items, (80, 238, 60, 70, 70))
        order_items_table.setStyle(in_order_items_style)

        story.append(order_items_table)
        story.append(Spacer(1, 40))

        # END
        story.append(Paragraph(getattr(settings, "IN_END"), styleN))

        doc.build(story, onFirstPage=self.page, onLaterPages=self.page)
        pdf.seek(0)
        return pdf
コード例 #7
0
ファイル: tests.py プロジェクト: AlexanderAA/django-lfs
    def test_currency(self):
        """
        """
        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
        self.assertEqual(currency(0.0), "$0.00")
        self.assertEqual(currency(1.0), "$1.00")

        shop = lfs.core.utils.get_default_shop()
        shop.use_international_currency_code = True
        shop.save()

        self.assertEqual(currency(0.0, None, False), "USD 0.00")
        self.assertEqual(currency(1.0, None, False), "USD 1.00")
コード例 #8
0
ファイル: tests.py プロジェクト: catyshka/lfs-cutomized
    def test_currency(self):
        """
        """
        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
        self.assertEqual(currency(0.0), "$0.00")
        self.assertEqual(currency(1.0), "$1.00")

        shop = lfs.core.utils.get_default_shop()
        shop.use_international_currency_code = True
        shop.save()

        self.assertEqual(currency(0.0, None, False), "USD 0.00")
        self.assertEqual(currency(1.0, None, False), "USD 1.00")
コード例 #9
0
ファイル: views.py プロジェクト: diefenbach/lfs-bulk-prices
def update_prices(request, product_id):
    product = Product.objects.get(pk=product_id)
    try:
        amount = int(request.GET.get("amount", 1))
    except (TypeError, ValueError):
        amount = 1

    price = product.get_price_gross(request, amount=amount)
    base_price = product.get_base_price_gross(request, amount=amount)

    result = json.dumps({
        "standard_price": currency(price, request),
        "base_price": currency(base_price, request),
    })
    return HttpResponse(result, content_type='application/json')
コード例 #10
0
ファイル: tests.py プロジェクト: DanielChu/django-lfs
    def test_currency(self):
        """
        """
        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
        self.assertEqual(currency(0.0), '<span class="money">$0.00</span>')
        self.assertEqual(currency(1.0), '<span class="money">$1.00</span>')

        shop = lfs.core.utils.get_default_shop()
        shop.use_international_currency_code = True
        shop.save()

        self.assertEqual(currency(0.0, None, False), '<span class="money">USD 0.00</span>')
        self.assertEqual(currency(1.0, None, False), '<span class="money">USD 1.00</span>')

        self.assertEqual(currency(-1.0, None, False), '<span class="money negative">-USD 1.00</span>')
コード例 #11
0
ファイル: tests.py プロジェクト: parsadevloper/django-lfs
    def test_currency(self):
        """
        """
        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
        self.assertEqual(currency(0.0), '<span class="money">$0.00</span>')
        self.assertEqual(currency(1.0), '<span class="money">$1.00</span>')

        shop = lfs.core.utils.get_default_shop()
        shop.use_international_currency_code = True
        shop.save()

        self.assertEqual(currency(0.0, None, False), '<span class="money">USD 0.00</span>')
        self.assertEqual(currency(1.0, None, False), '<span class="money">USD 1.00</span>')

        self.assertEqual(currency(-1.0, None, False), '<span class="money negative">-USD 1.00</span>')
コード例 #12
0
ファイル: views.py プロジェクト: cloudappsetup/django-lfs
def calculate_price(request, id):
    """Calculates the price of the product on base of choosen properties after
    a customer has selected a property on product view.
    """
    product = Product.objects.get(pk=id)

    property_price = 0
    for key, option_id in request.POST.items():
        if key.startswith("property"):
            try:
                po = PropertyOption.objects.get(pk=option_id)
            except (ValueError, PropertyOption.DoesNotExist):
                pass
            else:
                if po.property.add_price:
                    property_price += po.price

    if product.for_sale:
        for_sale_standard_price = product.get_standard_price(
            with_properties=False)
        for_sale_standard_price += property_price
    else:
        for_sale_standard_price = 0
        price = product.get_price(request, with_properties=False)
        price += property_price

    result = simplejson.dumps(
        {
            "price": lfs_tags.currency(price, request),
            "for-sale-standard-price":
            lfs_tags.currency(for_sale_standard_price),
            "message":
            _("Price has been changed according to your selection."),
        },
        cls=LazyEncoder)

    return HttpResponse(result)
コード例 #13
0
ファイル: pdfs.py プロジェクト: diefenbach-fz/flowzone-mails
    def create_pdf(self):
        pdf = StringIO.StringIO()

        doc = SimpleDocTemplate(pdf)
        doc.leftMargin = 31
        doc.rightMargin = 31
        doc.topMargin = 390
        doc.bottomMargin = 110

        story = []
        order_items = [["Artikelnr.", "Name", "Menge", "Preis", "Summe"]]
        for item in self.order.items.all():
            # Amount
            amount = str(item.amount)
            if item.product.unit:
                amount += " " + item.product.unit
            if item.product.active_packing_unit:
                amount += "\n(" + str(packages(
                    item)) + " " + item.product.packing_unit_unit + ")"
            # Name
            item_name = item.product_name
            for property in item.product.get_displayed_properties():
                item_name += "\n" + property["title"] + ": " + property[
                    "value"] + " " + property["unit"]
            for property in item.product.get_variant_properties():
                item_name += "\n" + property["title"] + ": " + property[
                    "value"] + " " + property["unit"]
            if item.product.is_configurable_product():
                for property in item.get_properties():
                    item_name += "\n" + property["title"] + ": " + property[
                        "value"] + property["unit"] + " " + property["price"]
            price = currency(item.product_price_gross)
            if item.product.price_unit:
                price += " / " + item.product.price_unit
            total = currency(item.price_gross)
            order_items.append(
                [item.product.sku, item_name, amount, price, total])

        if self.order.voucher_number:
            order_items.append([
                "", "Voucher", "1",
                currency(self.order.voucher_price),
                currency(self.order.voucher_price)
            ])

        order_items.append([
            "", "Versandart (" + self.order.shipping_method.name + ")", "1",
            currency(self.order.shipping_price),
            currency(self.order.shipping_price)
        ])
        order_items.append([
            "", "Zahlungsweise (" + self.order.payment_method.name + ")", "1",
            currency(self.order.payment_price),
            currency(self.order.payment_price)
        ])

        order_items.append(["", "", "", "Summe", currency(self.order.price)])
        order_items.append(
            ["", "", "", "Inkl. MwSt",
             currency(self.order.tax)])

        order_items_table = Table(order_items, (80, 238, 60, 70, 70))
        order_items_table.setStyle(in_order_items_style)

        story.append(order_items_table)
        story.append(Spacer(1, 40))

        # END
        story.append(Paragraph(getattr(settings, "IN_END"), styleN))

        doc.build(story, onFirstPage=self.page, onLaterPages=self.page)
        pdf.seek(0)
        return pdf