Skip to content
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

New variants should inherit tax category in UI #13068

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/helpers/admin/products_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def prepare_new_variant(product, producer_options)
# e.g producer_options = [['producer name', id]]
product.variants.build do |new_variant|
new_variant.supplier_id = producer_options.first.second if producer_options.one?
new_variant.tax_category_id = product.variants.first.tax_category_id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth adding a check to see if variant exists? Ive noted in UI that a minimum of one variant always exists

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UI prevents you from deleting a variant if there is only one left, and currently when creating a new product a variant will be created by default. So I think it's fair to assume there will always be one variant.

end
end

Expand Down
15 changes: 15 additions & 0 deletions spec/helpers/admin/products_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@
end
end
end

describe '#prepare_new_variant' do
let(:zone) { create(:zone_with_member) }
let(:product) {
create(:taxed_product, zone:, price: 12.54, tax_rate_amount: 0,
included_in_price: true)
}

context 'when tax category is present for first varient' do
it 'sets tax category for new variant' do
first_variant_tax_id = product.variants.first.tax_category_id
expect(helper.prepare_new_variant(product, []).tax_category_id).to eq(first_variant_tax_id)
end
end
end
end
Loading