def validate(self, data): data = super().validate(data) Item.clean_per_order(data.get('min_per_order'), data.get('max_per_order')) Item.clean_available(data.get('available_from'), data.get('available_until')) return data
def validate(self, data): data = super().validate(data) if self.instance and ('addons' in data or 'variations' in data): raise ValidationError(_('Updating add-ons or variations via PATCH/PUT is not supported. Please use the ' 'dedicated nested endpoint.')) Item.clean_per_order(data.get('min_per_order'), data.get('max_per_order')) Item.clean_available(data.get('available_from'), data.get('available_until')) return data
def add_position(self, item: Item, variation: ItemVariation, price: Decimal, addon_to: Order = None, subevent: SubEvent = None): if price is None: price = get_price(item, variation, subevent=subevent, invoice_address=self._invoice_address) else: if item.tax_rule.tax_applicable(self._invoice_address): price = item.tax(price, base_price_is='gross') else: price = TaxedPrice(gross=price, net=price, tax=Decimal('0.00'), rate=Decimal('0.00'), name='') if price is None: raise OrderError(self.error_messages['product_invalid']) if not addon_to and item.category and item.category.is_addon: raise OrderError(self.error_messages['addon_to_required']) if addon_to: if not item.category or item.category_id not in addon_to.item.addons.values_list('addon_category', flat=True): raise OrderError(self.error_messages['addon_invalid']) if self.order.event.has_subevents and not subevent: raise OrderError(self.error_messages['subevent_required']) new_quotas = (variation.quotas.filter(subevent=subevent) if variation else item.quotas.filter(subevent=subevent)) if not new_quotas: raise OrderError(self.error_messages['quota_missing']) if self.order.event.settings.invoice_include_free or price.gross != Decimal('0.00'): self._invoice_dirty = True self._totaldiff += price.gross self._quotadiff.update(new_quotas) self._operations.append(self.AddOperation(item, variation, price, addon_to, subevent))
def get_form_kwargs(self): """ Returns the keyword arguments for instantiating the form. """ newinst = Item(event=self.request.event) kwargs = super().get_form_kwargs() kwargs.update({'instance': newinst, 'user': self.request.user}) return kwargs
def validate(self, data): data = super().validate(data) if self.instance and ('addons' in data or 'variations' in data or 'bundles' in data): raise ValidationError(_('Updating add-ons, bundles, or variations via PATCH/PUT is not supported. Please use the ' 'dedicated nested endpoint.')) Item.clean_per_order(data.get('min_per_order'), data.get('max_per_order')) Item.clean_available(data.get('available_from'), data.get('available_until')) if data.get('issue_giftcard'): if data.get('tax_rule') and data.get('tax_rule').rate > 0: raise ValidationError( _("Gift card products should not be associated with non-zero tax rates since sales tax will be " "applied when the gift card is redeemed.") ) if data.get('admission'): raise ValidationError(_( "Gift card products should not be admission products at the same time." )) return data
def validate_tax_rule(self, value): Item.clean_tax_rule(value, self.context['event']) return value
def validate_category(self, value): Item.clean_category(value, self.context['event']) return value