def get_price_display_options(self): if self.pk: options = self.price_display_options.for_group_and_shop( self, shop=self.shop) if options: return options.to_price_display() return PriceDisplayOptions()
def get_price_display_options(self): """ Get price display options of the contact. If the default group (`get_default_group`) defines price display options and the contact is member of it, return it. If contact is not (anymore) member of the default group or the default group does not define options, return one of the groups which defines options. If there is more than one such groups, it is undefined which options will be used. If contact is not a member of any group that defines price display options, return default constructed `PriceDisplayOptions`. Subclasses may still override this default behavior. :rtype: PriceDisplayOptions """ groups_with_options = self.groups.with_price_display_options() if groups_with_options: default_group = self.get_default_group() if groups_with_options.filter(pk=default_group.pk).exists(): group_with_options = default_group else: # Contact was removed from the default group. group_with_options = groups_with_options.first() return group_with_options.get_price_display_options() return PriceDisplayOptions()
def _get_template_engine_and_context(): engine = django.template.engines['jinja2'] assert isinstance(engine, django_jinja.backend.Jinja2) shop = get_default_shop() shop.currency = 'USD' shop.prices_include_tax = False shop.save() request = RequestFactory().get('/') request.shop = shop request.customer = AnonymousContact() request.person = request.customer PriceDisplayOptions(include_taxes=False).set_for_request(request) tax = get_default_tax() create_default_tax_rule(tax) tax_class = get_default_tax_class() order, order_line = _get_order_and_order_line(request) product = create_product(sku='6.0745', shop=shop, tax_class=tax_class) context = { 'request': request, 'prod': product, # TODO: Test also with variant products 'sline': _get_source_line(request), 'bline': _get_basket_line(request), 'oline': order_line, 'order': order } return (engine, context)
def _get_template_engine_and_context(product_sku="6.0745", create_var_product=False): engine = django.template.engines["jinja2"] assert isinstance(engine, django_jinja.backend.Jinja2) shop = get_default_shop() shop.currency = "USD" shop.prices_include_tax = False shop.save() request = RequestFactory().get("/") request.shop = shop request.customer = AnonymousContact() request.person = request.customer PriceDisplayOptions(include_taxes=False).set_for_request(request) tax = get_default_tax() create_default_tax_rule(tax) tax_class = get_default_tax_class() order, order_line = _get_order_and_order_line(request) product = create_product(sku=product_sku, shop=shop, tax_class=tax_class) supplier = get_default_supplier(shop) if create_var_product: var_product = create_product(sku="32.9", shop=shop, tax_class=tax_class) child_product_1 = create_product(sku="4.50", shop=shop, tax_class=tax_class, supplier=supplier, default_price="4.5") child_product_2 = create_product(sku="12.00", shop=shop, tax_class=tax_class, supplier=supplier, default_price="12") child_product_1.link_to_parent(var_product, variables={"color": "red"}) child_product_2.link_to_parent(var_product, variables={"color": "blue"}) context = { "request": request, "prod": product, "var_prod": var_product if create_var_product else None, # TODO: Test also with variant products "sline": _get_source_line(request), "bline": _get_basket_line(request), "oline": order_line, "order": order, } return (engine, context)
def to_price_display(self): return PriceDisplayOptions( include_taxes=self.show_prices_including_taxes, show_prices=(not self.hide_prices), )
def get_price_display_options(group): options = group.price_display_options.for_group_and_shop(group, shop=group.shop) return options.to_price_display() or PriceDisplayOptions()
def get_price_display_options(self): return get_price_display_options( self) if self.pk else PriceDisplayOptions()
def test_price_display_options_default(): options = PriceDisplayOptions() assert options.show_prices is True assert options.hide_prices is False assert options.include_taxes is None