Create factories zoned_order and taxed_product

This commit is contained in:
Rohan Mitchell
2015-03-24 11:53:18 +11:00
parent d489e06009
commit 69dc92dec1
3 changed files with 33 additions and 23 deletions

View File

@@ -182,6 +182,30 @@ FactoryGirl.define do
order.reload
end
end
factory :zoned_order, :parent => :order do
after(:create) do |order|
zone = create(:zone, default_tax: true)
Spree::ZoneMember.create!(zone: zone, zoneable: Spree::Country.find_by_name('Australia'))
unless order.bill_address
order.bill_address = create(:address)
order.save!
end
end
end
factory :taxed_product, :parent => :product do
ignore do
tax_rate_amount 0
zone nil
end
tax_category { create(:tax_category) }
after(:create) do |product, proxy|
create(:tax_rate, amount: proxy.tax_rate_amount, calculator: Spree::Calculator::DefaultTax.new, tax_category: product.tax_category, zone: proxy.zone)
end
end
end

View File

@@ -109,31 +109,19 @@ feature %q{
end
describe "Sales tax report" do
let!(:payment_method) { create(:payment_method, distributors: [user1.enterprises.first]) }
let!(:zone) { create(:zone, default_tax: true) }
let!(:zone_member) { Spree::ZoneMember.create!(zone: zone, zoneable: Spree::Country.find_by_name('Australia')) }
let(:user1) do
create_enterprise_user(enterprises: [create(:distributor_enterprise)])
end
let(:user2) do
create_enterprise_user(enterprises: [create(:distributor_enterprise)])
end
let(:tax_category1) { create(:tax_category) }
let(:tax_category2) { create(:tax_category) }
let!(:tax_rate1) { create(:tax_rate, amount: 0.0, calculator: Spree::Calculator::DefaultTax.new, tax_category: tax_category1, zone: zone) }
let!(:tax_rate2) { create(:tax_rate, amount: 0.2, calculator: Spree::Calculator::DefaultTax.new, tax_category: tax_category2, zone: zone) }
let(:product1) { create(:product, price: 12.54, tax_category: tax_category1) }
let(:product2) { create(:product, price: 500.15, tax_category: tax_category2) }
let(:user1) { create_enterprise_user enterprises: [create(:distributor_enterprise, with_payment_and_shipping: true)] }
let(:user2) { create_enterprise_user enterprises: [create(:distributor_enterprise, with_payment_and_shipping: true)] }
let(:shipping_method) { create(:shipping_method, name: "Shipping", description: "Expensive", calculator: Spree::Calculator::FlatRate.new(preferred_amount: 100.55)) }
let(:order1) { create(:order, distributor: user1.enterprises.first, shipping_method: shipping_method, bill_address: create(:address)) }
let(:order1) { create(:zoned_order, distributor: user1.enterprises.first, shipping_method: shipping_method) }
let(:product1) { create(:taxed_product, zone: order1.tax_zone, price: 12.54, tax_rate_amount: 0) }
let(:product2) { create(:taxed_product, zone: order1.tax_zone, price: 500.15, tax_rate_amount: 0.2) }
let!(:line_item1) { create(:line_item, variant: product1.master, price: 12.54, quantity: 1, order: order1) }
let!(:line_item2) { create(:line_item, variant: product2.master, price: 500.15, quantity: 3, order: order1) }
let!(:adj_shipping) { create(:adjustment, adjustable: order1, label: "Shipping", amount: 100.55) }
let!(:adj_li2_tax) { create(:adjustment, adjustable: line_item2, source: line_item2, originator: tax_rate2, label: "RandomTax", amount: 123.00) }
let!(:adj_li2_tax) { create(:adjustment, adjustable: line_item2, source: line_item2, originator: product2.tax_category.tax_rates.first, label: "RandomTax", amount: 123.00) }
before do
Spree::Config.shipment_inc_vat = true

View File

@@ -7,9 +7,7 @@ module Spree
describe "recording included tax" do
describe "TaxRate adjustments" do
let!(:zone) { create(:zone, default_tax: true) }
let!(:zone_member) { ZoneMember.create!(zone: zone, zoneable: Country.find_by_name('Australia')) }
let!(:order) { create(:order) }
let!(:order) { create(:zoned_order) }
let!(:line_item) { create(:line_item, order: order) }
let(:tax_rate) { create(:tax_rate, included_in_price: true, calculator: Calculator::FlatRate.new(preferred_amount: 0.1)) }
let(:adjustment) { line_item.adjustments(:reload).first }