Exemple #1
0
def get_default_setting(key, user, shop=None):
    if user.is_superuser: return
    if key not in dict(BRAND_SETTING_KEY_CHOICES): return

    value = None
    if shop and shop.owner:
        value = get_ba_settings(shop.owner).get(key)
    if not value:
        value = get_ba_settings(user).get(key)
    if not value and key in dict(SETTING_KEY_CHOICES):
        value = get_setting(key)
    return value
Exemple #2
0
    def _get_row(self, shop_id, sale, ba, ca):
        try:
            stock_obj = ProductStock.objects.get(sale=sale,
                                                 shop_id=shop_id,
                                                 brand_attribute=ba,
                                                 common_attribute=ca)
            stock = stock_obj.rest_stock
            alert = stock_obj.alert
        except ProductStock.DoesNotExist:
            stock = 0
            alert = False

        try:
            barcode = Barcode.objects.get(sale=sale,
                                          brand_attribute=ba,
                                          common_attribute=ca).upc
        except Barcode.DoesNotExist:
            barcode = ''

        try:
            sku = ExternalRef.objects.get(sale=sale,
                                          brand_attribute=ba,
                                          common_attribute=ca).external_id
        except ExternalRef.DoesNotExist:
            sku = ''

        try:
            require_confirm = OrderConfirmSetting.objects.get(
                sale=sale, brand_attribute=ba,
                common_attribute=ca).require_confirm
        except OrderConfirmSetting.DoesNotExist:
            require_confirm = get_ba_settings(
                self.request.user).get('order_require_confirmation') == 'True'

        sale_cover = None
        if sale.product.pictures.count() > 0:
            sale_cover = sale.product.pictures.order_by('sort_order',
                                                        'id')[0].picture

        row_data = {
            'sale_id': sale.id,
            'shop_id': shop_id,
            'ba_id': ba.pk if ba else None,
            'ca_id': ca.pk if ca else None,
            'ba_name': ba.name if ba else '',
            'ca_name': ca.name if ca else '',
            'sale_cover': sale_cover.url if sale_cover else '',
            'product_name': sale.product.name or '',
            'stock': stock,
            'barcode': barcode,
            'sku': sku,
            'alert': alert,
            'order_require_confirm': require_confirm,
        }
        return row_data
Exemple #3
0
def get_currency(user, shop=None):
    default_currency = get_setting('default_currency')
    if user.is_superuser:
        return default_currency

    value = None
    if shop:
        value = shop.default_currency
    if not value:
        value = get_ba_settings(user).get('default_currency')
    return value or default_currency
Exemple #4
0
    def __init__(self, user=None, having_orders=False, *args, **kwargs):
        initial = kwargs.get('initial', {})
        if user is not None:
            initial = get_ba_settings(user).copy()
            initial['default_currency'] = initial.get('default_currency') \
                                       or get_setting('default_currency')
            initial['starting_invoice_number'] = initial.get('starting_invoice_number') \
                                       or get_setting('starting_invoice_number')
            initial['use_after_tax_price'] = initial.get('use_after_tax_price') \
                                       or get_setting('use_after_tax_price')
            initial['use_after_tax_price'] = initial[
                'use_after_tax_price'] == 'True'
            initial['order_require_confirmation'] = initial.get(
                'order_require_confirmation') == 'True'
            initial['unique_items'] = initial.get('unique_items') == 'True'

        super(SABrandSettingsForm, self).__init__(initial=initial,
                                                  *args,
                                                  **kwargs)
        if having_orders:
            self.fields['use_after_tax_price'].widget = \
                    forms.CheckboxInput({'disabled': 'true'})
Exemple #5
0
def get_brand_currency(user):
    default_currency = get_setting('default_currency')
    value = get_ba_settings(user).get('default_currency')
    return value or default_currency