-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨
Marketplace
: Initial CRUD for TaxRate
- #1137 This throws together the basic `CRUD` operations for `TaxRate`. Going to do a bit of tidying and add some tests, then record a video of the use case. I may decide I want to add in the setting of the `TaxRate` on the `Product`, but maybe I'll wait and add that independently...
- Loading branch information
Showing
15 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Marketplace | ||
class TaxRate < Record | ||
self.table_name = "marketplace_tax_rates" | ||
belongs_to :marketplace | ||
self.location_parent = :marketplace | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Marketplace | ||
class TaxRatePolicy < ApplicationPolicy | ||
alias_method :tax_rate, :object | ||
|
||
def create? | ||
person.member_of?(tax_rate.marketplace.space) | ||
end | ||
|
||
alias_method :update?, :create? | ||
|
||
def permitted_attributes(_) | ||
[:label, :tax_rate] | ||
end | ||
|
||
class Scope < ApplicationScope | ||
def resolve | ||
scope.all | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= form_with(model: tax_rate.location) do |tax_rate_form| %> | ||
<%= render "text_field", attribute: :label, form: tax_rate_form %> | ||
<%= render "number_field", attribute: :tax_rate, form: tax_rate_form, required: true, step: 1, min: 0, max: 100 %> | ||
|
||
<%= tax_rate_form.submit %> | ||
<%- end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= link_to tax_rate.location(:edit) do %> | ||
<%= tax_rate.label %>: <%= number_to_percentage(tax_rate.tax_rate, precision: 0) %> | ||
<%- end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<%- breadcrumb :edit_tax_rate, tax_rate %> | ||
<%= render "form", tax_rate: tax_rate %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<%- breadcrumb :new_tax_rate, tax_rate %> | ||
<%= render "form", tax_rate: tax_rate %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Marketplace | ||
class TaxRatesController < Controller | ||
def new | ||
tax_rate | ||
end | ||
|
||
def create | ||
if tax_rate.save | ||
redirect_to marketplace.location(child: :tax_rates) | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def tax_rate_params | ||
policy(TaxRate).permit(params.require(:tax_rate)) | ||
end | ||
|
||
helper_method def tax_rate | ||
@tax_rate ||= if params[:id] | ||
policy_scope(marketplace.tax_rates).find(params[:id]) | ||
elsif params[:tax_rate] | ||
marketplace.tax_rates.new(tax_rate_params) | ||
else | ||
marketplace.tax_rates.new | ||
end.tap do |tax_rate| | ||
authorize(tax_rate) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
<% required ||= required | false %> | ||
<% required = local_assigns[:required] || false %> | ||
<% min = local_assigns[:min] %> | ||
<% max = local_assigns[:max] %> | ||
<% step = local_assigns[:step] %> | ||
<div> | ||
<%= form.label attribute %> | ||
<%= form.number_field attribute, required: required %> | ||
<%= form.number_field attribute, required: required, min: min, max: max, step: step %> | ||
<%= render partial: "error", locals: { model: form.object, attribute: attribute } %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateMarketplaceTaxRates < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :marketplace_tax_rates, id: :uuid do |t| | ||
t.integer :tax_rate | ||
t.string :label | ||
t.references :marketplace, type: :uuid, foreign_key: {to_table: :furniture_placements} | ||
t.timestamps | ||
end | ||
|
||
change_table :marketplace_products do |t| | ||
t.references :tax_rate, type: :uuid, foreign_key: {to_table: :marketplace_tax_rates} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters