shuup.discounts package

Subpackages

Submodules

shuup.discounts.apps module

class shuup.discounts.apps.AppConfig(*args, **kwargs)[source]

Bases: AppConfig

name = 'shuup.discounts'
default_auto_field = 'django.db.models.BigAutoField'
provides = {'admin_module': ['shuup.discounts.admin.modules.DiscountModule', 'shuup.discounts.admin.modules.DiscountArchiveModule', 'shuup.discounts.admin.modules.HappyHourModule'], 'admin_object_selector': ['shuup.discounts.admin.object_selector.DiscountAdminObjectSelector'], 'discount_module': ['shuup.discounts.modules:ProductDiscountModule'], 'xtheme_plugin': ['shuup.discounts.plugins:DiscountedProductsPlugin']}

See /provides for details about the provides variable.

ready()[source]

Override this method in subclasses to run code when Django starts.

shuup.discounts.exceptions module

exception shuup.discounts.exceptions.DiscountM2MChangeError[source]

Bases: Exception

shuup.discounts.modules module

class shuup.discounts.modules.ProductDiscountModule[source]

Bases: DiscountModule

identifier = 'product_discounts'
name = 'Product Discounts'
discount_price(context, product, price_info)[source]

Discount given price of given product. :param context: Pricing context to operate in :param product: Product in question or its id :param price_info: Price to discount :return: A new instance of a discounted price

index_shop_product(shop_product: ShopProduct | int, **kwargs)[source]

Index the shop product discounts. This is a heavy procedure, use with precaution and through some background task.

shuup.discounts.plugins module

class shuup.discounts.plugins.ProductSelectionConfigForm(**kwargs)[source]

Bases: GenericPluginForm

A configuration form for the DiscountedProductsPlugin

populate()[source]

A custom populate method to display product choices

clean()[source]

A custom clean method to transform selected discounts into a list of ids

base_fields = {}
declared_fields = {}
property media

Return all media required to render the widgets on this form.

class shuup.discounts.plugins.DiscountedProductsPlugin(config)[source]

Bases: TemplatedPlugin

Instantiate a Plugin with the given config dictionary.

Parameters:

config (dict) – Dictionary of freeform configuration data

identifier = 'discount_product'
name = 'Discounted Products'
template_name = 'shuup/discounts/product_discount_plugin.jinja'
editor_form_class

alias of ProductSelectionConfigForm

fields = [('title', <shuup.xtheme.plugins.forms.TranslatableField object>), ('count', <django.forms.fields.IntegerField object>), ('orderable_only', <django.forms.fields.BooleanField object>)]
get_context_data(context)[source]

Get a context dictionary from a Jinja2 context.

Parameters:

context (jinja2.runtime.Context) – Jinja2 rendering context

Returns:

Dict of vars

Return type:

dict[str, object]

shuup.discounts.settings module

shuup.discounts.settings.SHUUP_DISCOUNTS_PER_PRODUCT_EXPIRATION_DATES = False

Whether the price expiration should be calculated per product instead of per shop

shuup.discounts.signal_handers module

shuup.discounts.utils module

shuup.discounts.utils.get_potential_discounts_for_product(context, product, available_only=True, groups_ids=None, all_contacts=False)[source]

Get a queryset of all possible discounts for a given context and product

If available_only is True, only the discounts which match

happy hours, start/end dates will be returned

If available_only is False, all discounts that match with the context and product,

that are active will be returned.

shuup.discounts.utils.get_active_discount_for_code(order_or_order_source, code)[source]
shuup.discounts.utils.get_next_dates_for_range(weekday, from_hour, to_hour)[source]

Get datetime ranges for the next weekday

Example

Give me the date ranges for the next Sunday from 1pm to 10pm It will return a tuple of datetimes.

If the requested weekday is the same of today, it will return both the ranges for today

and also for the next week.

:rtype list[datetime.datetime]

shuup.discounts.utils.bump_price_expiration(shop_ids: Iterable[int])[source]

Bump price expiration cache for shop ids

shuup.discounts.utils.get_price_expiration(context, product)[source]

Returns the price expiration for the product through a UNIX timestamp

This routine loads all dates that can possibly affect the price of the product in the future.

After fetching all the event dates, the expiration time will

be the minimum datetime that is greater than now:

expire_on = min(
event_date for event_dates in [

next_discount_start, next_discount_ends, next_happy_hour_start, next_happy_hour_end,

] if event_date > now

)

:rtype numbers.Number|None :returns the price expiration time timestamp

Index all shop products that are affected by the given discounts

shuup.discounts.utils.index_linked_shop_products(discount, discounts_groups_ids=None, ignore_shop_products_ids=None)[source]

Reindex all shop products previously linked this is required when a shop product shouldn’t be linked anymore

shuup.discounts.utils.index_shop_product_price(shop_product: ShopProduct, supplier: Supplier, contact_groups_ids: Iterable[int] = [])[source]

Index discounts for the shop product

Module contents