Esempio n. 1
0
 def __init__(self, *args, **kwargs):
     super(StockAdjustmentForm, self).__init__(*args, **kwargs)
     if not ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
         self.fields["purchase_price"].label = format_lazy(
             _("Purchase price per unit ({currency_name})"),
             currency_name=get_currency_name(Shop.objects.first().currency),
         )
Esempio n. 2
0
    def __init__(self, **kwargs):
        super(ShopBaseForm, self).__init__(**kwargs)
        self.fields["currency"] = forms.ChoiceField(
            choices=get_currency_choices(),
            required=True,
            label=_("Currency"),
            help_text=
            _("The primary shop currency. This is the currency used when selling your products."
              ))

        staff_members = Select2MultipleField(
            label=_("Staff"),
            help_text=_("Select staff members for this shop."),
            model=get_user_model(),
            required=False)
        staff_members.widget = QuickAddUserMultiSelect(
            attrs={"data-model": "auth.User"})
        initial_members = (self.instance.staff_members.all()
                           if self.instance.pk else [])
        staff_members.widget.choices = [(member.pk, force_text(member))
                                        for member in initial_members]
        self.fields["staff_members"] = staff_members
        self.fields["domain"].required = ShuupSettings.get_setting(
            "SHUUP_ENABLE_MULTIPLE_SHOPS")
        self.disable_protected_fields()
Esempio n. 3
0
def check_and_raise_if_only_one_allowed(setting_name, obj):
    if ShuupSettings.get_setting(setting_name):
        return
    if not obj.pk and obj.__class__.objects.count() >= 1:
        raise Problem(
            _("Only one %(model)s permitted.") %
            {"model": obj._meta.verbose_name})
Esempio n. 4
0
 def get_toolbar(self):
     save_form_id = self.get_save_form_id()
     with_split_save = ShuupSettings.get_setting(
         "SHUUP_ENABLE_MULTIPLE_SHOPS")
     return get_default_edit_toolbar(self,
                                     save_form_id,
                                     with_split_save=with_split_save)
Esempio n. 5
0
 def __str__(self):  # pragma: no cover
     if self.billing_address_id:
         name = self.billing_address.name
     else:
         name = "-"
     if ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
         return "Order %s (%s, %s)" % (self.identifier, self.shop.name, name)
     else:
         return "Order %s (%s)" % (self.identifier, name)
Esempio n. 6
0
 def __str__(self):  # pragma: no cover
     if self.billing_address_id:
         name = self.billing_address.name
     else:
         name = "-"
     if ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
         return "Order %s (%s, %s)" % (self.identifier, self.shop.name, name)
     else:
         return "Order %s (%s)" % (self.identifier, name)
Esempio n. 7
0
    def get_toolbar(self):
        save_form_id = self.get_save_form_id()
        with_split_save = ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS")
        toolbar = get_default_edit_toolbar(self, save_form_id, with_split_save=with_split_save)

        for button in get_provide_objects("admin_shop_edit_toolbar_button"):
            if button.visible_for_object(self.object):
                toolbar.append(button(self.object))

        return toolbar
Esempio n. 8
0
    def get_menu_entries(self, request):
        # not supported
        if ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
            return []

        return [
            MenuEntry(text="Sample Data",
                      category=SETTINGS_MENU_CATEGORY,
                      subcategory="data_transfer",
                      url="shuup_admin:sample_data",
                      icon="fa fa-star")
        ]
Esempio n. 9
0
    def __init__(self,
                 sales_unit: Optional[SalesUnit] = None,
                 *args,
                 **kwargs):
        super().__init__(*args, **kwargs)

        if not ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
            self.fields["purchase_price"].label = format_lazy(
                _("Purchase price per unit ({currency_name})"),
                currency_name=get_currency_name(Shop.objects.first().currency),
            )
        self.decimals = 0
        if sales_unit:
            self.decimals = sales_unit.decimals
            self.fields["delta"] = FormattedDecimalFormField(
                label=_("Quantity"), decimal_places=sales_unit.decimals)
Esempio n. 10
0
    def get_notifications(self, request):
        """ Injects a message to the user and also a notification """
        # multi-shop not supported
        if not ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
            from shuup.admin.shop_provider import get_shop
            shop = get_shop(request)

            if sample_manager.has_installed_samples(shop):
                messages.warning(request, _('There is sample data installed. '
                                            'Access "Settings > Sample Data" for more information.'))

                yield Notification(
                    _("There is sample data installed. Click here to consolidate or delete them."),
                    title=_("Sample Data"),
                    kind="warning",
                    url="shuup_admin:sample_data"
                )
Esempio n. 11
0
    def get_notifications(self, request):
        """ Injects a message to the user and also a notification """
        # multi-shop not supported
        if not ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
            # there would be only sample data for single-shops envs
            shop = Shop.objects.first()

            if sample_manager.has_installed_samples(shop):
                messages.warning(request, _('There is sample data installed. '
                                            'Access "Settings > Sample Data" for more information.'))

                yield Notification(
                    _("There is sample data installed. Click here to consolidate or delete them."),
                    title=_("Sample Data"),
                    kind="warning",
                    url="shuup_admin:sample_data"
                )
Esempio n. 12
0
    def get_notifications(self, request):
        """ Injects a message to the user and also a notification """
        # multi-shop not supported
        if not ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
            from shuup.admin.shop_provider import get_shop
            shop = get_shop(request)

            if sample_manager.has_installed_samples(shop):
                messages.warning(
                    request,
                    _("There is a sample data installed. "
                      "Search `Sample Data` for more information."))

                yield Notification(_(
                    "There is a sample data installed. Click here to consolidate or delete them."
                ),
                                   title=_("Sample Data"),
                                   kind="warning",
                                   url="shuup_admin:sample_data")
Esempio n. 13
0
    def __init__(self, **kwargs):
        super(ShopBaseForm, self).__init__(**kwargs)
        self.fields["currency"] = forms.ChoiceField(
            choices=get_currency_choices(),
            required=True,
            label=_("Currency"),
            help_text=_("The primary shop currency. This is the currency used when selling your products.")
        )

        staff_members = Select2MultipleField(
            label=_("Staff"),
            help_text=_("Select staff members for this shop."),
            model=get_user_model(),
            required=False
        )
        staff_members.widget = QuickAddUserMultiSelect(attrs={"data-model": "auth.User"})
        initial_members = (self.instance.staff_members.all() if self.instance.pk else [])
        staff_members.widget.choices = [(member.pk, force_text(member)) for member in initial_members]
        self.fields["staff_members"] = staff_members
        self.fields["domain"].required = ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS")
        self.disable_protected_fields()
Esempio n. 14
0
def check_and_raise_if_only_one_allowed(setting_name, obj):
    if ShuupSettings.get_setting(setting_name):
        return
    if not obj.pk and obj.__class__.objects.count() >= 1:
        raise Problem(_("Only one %(model)s permitted.") % {"model": obj._meta.verbose_name})
Esempio n. 15
0
 def get_toolbar(self):
     if ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
         return super(ShopListView, self).get_toolbar()
     else:
         return Toolbar([])
Esempio n. 16
0
 def get_toolbar(self):
     save_form_id = self.get_save_form_id()
     with_split_save = ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS")
     return get_default_edit_toolbar(self, save_form_id, with_split_save=with_split_save)
Esempio n. 17
0
def _get_prices_include_tax():
    from shuup.core.models import Shop
    if not ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
        return Shop.objects.first().prices_include_tax
    return False
Esempio n. 18
0
def _get_currency():
    from shuup.core.models import Shop
    if not ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
        return Shop.objects.first().currency
    return settings.SHUUP_HOME_CURRENCY