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." )) initial_members = self.instance.staff_members.all( ) if self.instance.pk else [] staff_members = Select2MultipleField( label=_("Staff"), help_text=_("Select staff members for this shop."), model=get_user_model(), initial=initial_members, required=False) staff_members.widget = QuickAddUserMultiSelect( attrs={"data-model": "auth.User"}) staff_members.widget.choices = [(member.pk, force_text(member)) for member in initial_members] self.fields["staff_members"] = staff_members self.fields["domain"].required = WshopSettings.get_setting( "WSHOP_ENABLE_MULTIPLE_SHOPS") self.disable_protected_fields()
def check_and_raise_if_only_one_allowed(setting_name, obj): if WshopSettings.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})
def __init__(self, *args, **kwargs): super(StockAdjustmentForm, self).__init__(*args, **kwargs) if not WshopSettings.get_setting("WSHOP_ENABLE_MULTIPLE_SHOPS"): self.fields[ "purchase_price"].label = "Purchase price per unit (%(currency_name)s)" % { "currency_name": get_currency_name( Shop.objects.first().currency) }
def get_menu_entries(self, request): # not supported if WshopSettings.get_setting("WSHOP_ENABLE_MULTIPLE_SHOPS"): return [] return [ MenuEntry(text="Sample Data", category=SETTINGS_MENU_CATEGORY, subcategory="data_transfer", url="wshop_admin:sample_data", icon="fa fa-star") ]
def get_notifications(self, request): """ Injects a message to the user and also a notification """ # multi-shop not supported if not WshopSettings.get_setting("WSHOP_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="wshop_admin:sample_data")
def get_toolbar(self): if WshopSettings.get_setting("WSHOP_ENABLE_MULTIPLE_SHOPS"): return super(ShopListView, self).get_toolbar() else: return Toolbar([])
def get_toolbar(self): save_form_id = self.get_save_form_id() with_split_save = WshopSettings.get_setting("WSHOP_ENABLE_MULTIPLE_SHOPS") return get_default_edit_toolbar(self, save_form_id, with_split_save=with_split_save)
def _get_prices_include_tax(): from wshop.core.models import Shop if not WshopSettings.get_setting("WSHOP_ENABLE_MULTIPLE_SHOPS"): return Shop.objects.first().prices_include_tax return False
def _get_currency(): from wshop.core.models import Shop if not WshopSettings.get_setting("WSHOP_ENABLE_MULTIPLE_SHOPS"): return Shop.objects.first().currency return settings.WSHOP_HOME_CURRENCY