-
Notifications
You must be signed in to change notification settings - Fork 70
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
Allow admin to remove VAT rate #413
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,17 @@ def vat_rate_for(product_id) | |
end | ||
|
||
def vat_rate_by_code(vat_rate_code) | ||
@event_store | ||
last_available_vat_rate_event = @event_store | ||
.read | ||
.stream("Taxes::AvailableVatRate$#{vat_rate_code}") | ||
.last | ||
&.data | ||
&.fetch(:vat_rate) | ||
&.then { |vat_rate| Infra::Types::VatRate.new(vat_rate) } | ||
|
||
if last_available_vat_rate_event.instance_of?(AvailableVatRateAdded) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you only care about the the if statement wouldn't be necessary |
||
last_available_vat_rate_event | ||
.data | ||
.fetch(:vat_rate) | ||
.then { |vat_rate| Infra::Types::VatRate.new(vat_rate) } | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module VatRates | ||
class RemoveAvailableVatRate | ||
def call(event) | ||
AvailableVatRate.destroy_by(code: event.data.fetch(:vat_rate_code)) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,20 @@ | |
<tr> | ||
<th class="text-left py-2">Code</th> | ||
<th class="text-right py-2">Rate</th> | ||
<th class="text-right py-2"></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @available_vat_rates.each do |available_vat_rate| %> | ||
<tr class="border-t"> | ||
<td class="py-2"><%= available_vat_rate.code %></td> | ||
<td class="py-2 text-right"><%= available_vat_rate.rate %></td> | ||
<td class="text-right py-2"><%= available_vat_rate.rate %></td> | ||
<td class="text-right py-2"> | ||
<%= form_with url: available_vat_rates_path, method: :delete do |f| %> | ||
<%= f.hidden_field :vat_rate_code, value: available_vat_rate.code %> | ||
<%= f.submit 'Delete' %> | ||
<% end %> | ||
Comment on lines
+26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used To avoid this issue, I decided to send the parameter through the form instead. |
||
</tr> | ||
<% end %> | ||
</tbody> | ||
|
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.
Outside of scope of this task, but this method got me thinking.
This method is called in the AddAvailableVatRateHandler
It is called to check if tax rate with given code already exists. If not, then the handler publishes an event.
First of all, it breaks the tell don't ask rule. In current implementation there is possibility that two
AvailableVatRateAdded
events will be published. Therefore, the system will be in unexpected state.The question is if that is a major or minor problem.
Since this if statement has been added for some reason, let's assume it would a major issue if the vat rate code is duplicated.
To reproduce this behaviour you can follow those steps:
How do you think we could deal with that? (tip: look at the core concepts section in RES documentation)