-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement voucher per event and for all events of an organizer | Create Voucher #473
Conversation
Reviewer's Guide by SourceryThis PR implements a new voucher management system in the admin area that allows administrators to create, update, and delete vouchers. The vouchers can be used by organizers to reduce billing invoice prices, with options to limit their usage to specific events or organizers. The implementation includes new model classes, views, forms, and templates to support the voucher management functionality. Class diagram for the new InvoiceVoucher modelclassDiagram
class InvoiceVoucher {
+String code
+PositiveInteger max_usages
+PositiveInteger redeemed
+Decimal budget
+DateTime valid_until
+String price_mode
+Decimal value
+ManyToManyField limit_events
+ManyToManyField limit_organizer
+DateTime created_at
+String created_by
+DateTime updated_at
+String updated_by
+is_active() bool
}
class Event
class Organizer
InvoiceVoucher --> Event : limit_events
InvoiceVoucher --> Organizer : limit_organizer
note for InvoiceVoucher "Represents a voucher that can be used to reduce billing invoice prices."
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @odkhang - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider removing redundant method overrides that only call super() (e.g. get(), post(), get_form_kwargs()) to reduce code duplication and improve maintainability.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
ctx = super().get_context_data(**kwargs) | ||
return ctx | ||
|
||
def get(self, request, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Remove unnecessary method overrides that just call super()
Several methods in these views (get(), get_context_data(), get_form_kwargs(), form_valid() in VoucherCreate) just call super() without adding functionality. These can be removed to reduce code noise.
Suggested implementation:
If there are other methods in the file that just call super() without adding functionality (like get(), get_form_kwargs(), form_valid()), they should also be removed in the same way. However, I can't see them in the provided code snippet to make those specific changes.
form_class = InvoiceVoucherForm | ||
return form_class | ||
|
||
def get_object(self, queryset=None) -> InvoiceVoucherForm: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Fix incorrect return type annotation
The return type should be InvoiceVoucher, not InvoiceVoucherForm, as this method returns an InvoiceVoucher instance.
@@ -127,3 +132,113 @@ | |||
) | |||
|
|||
return HttpResponseRedirect(reverse('control:admin.task_management')) | |||
|
|||
|
|||
class VoucherList(PaginationMixin, AdministratorPermissionRequiredMixin, ListView): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider creating a base class for voucher views to reduce code duplication and simplify the create/update views.
The code can be simplified while maintaining all functionality:
- Create a base class for shared voucher view logic:
class BaseVoucherView(AdministratorPermissionRequiredMixin):
model = InvoiceVoucher
template_name = 'pretixcontrol/admin/vouchers/detail.html'
context_object_name = 'voucher'
form_class = InvoiceVoucherForm
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
ctx['currency'] = settings.DEFAULT_CURRENCY
return ctx
def get_success_url(self) -> str:
return reverse('control:admin.vouchers')
- Simplify the create/update views to only include unique behavior:
class VoucherCreate(BaseVoucherView, CreateView):
pass
class VoucherUpdate(BaseVoucherView, UpdateView):
def get_object(self, queryset=None) -> InvoiceVoucher:
try:
return InvoiceVoucher.objects.get(id=self.kwargs['voucher'])
except InvoiceVoucher.DoesNotExist:
raise Http404(_("The requested voucher does not exist."))
def form_valid(self, form):
messages.success(self.request, _('Your changes have been saved.'))
return super().form_valid(form)
This removes empty method overrides and duplicated code while preserving all functionality. The base class makes the relationship between these views explicit and easier to maintain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR has many do-nothing overrides. But they are minor.
self.fields['event_effect'].queryset = Event.objects.all() | ||
self.fields['organizer_effect'].queryset = Organizer.objects.all() | ||
|
||
def clean(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This override is unnecessary.
This PR partly resolves - #382 Implement voucher per event and for all events of an organizer
This PR implement:
Summary by Sourcery
Implement a voucher management system in the admin area, enabling the creation, update, and deletion of vouchers that can be used by organizers to adjust billing invoices. This includes a new admin page for managing vouchers and the ability to limit voucher usage to specific events or organizers.
New Features:
Enhancements:
Summary by Sourcery
Implement a new voucher management system in the admin area, allowing administrators to create, update, and delete vouchers for organizers to use in reducing billing invoice prices. This includes a new 'Voucher' page and associated views and templates for managing voucher details and effects.
New Features:
Enhancements: