diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index b0b65b956a..9a1cfd27ba 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -31,7 +31,6 @@ module Spree searchable_associations :supplier, :properties, :primary_taxon, :variants searchable_scopes :active, :with_properties - belongs_to :tax_category, class_name: 'Spree::TaxCategory' belongs_to :shipping_category, class_name: 'Spree::ShippingCategory' belongs_to :supplier, class_name: 'Enterprise', touch: true belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true @@ -59,8 +58,6 @@ module Spree validates :supplier, presence: true validates :primary_taxon, presence: true - validates :tax_category, presence: true, - if: proc { Spree::Config[:products_require_tax_category] } validates :variant_unit, presence: true validates :unit_value, presence: @@ -205,14 +202,6 @@ module Spree group(column_names.map { |col_name| "#{table_name}.#{col_name}" }) end - def tax_category - if self[:tax_category_id].nil? - TaxCategory.find_by(is_default: true) - else - TaxCategory.find(self[:tax_category_id]) - end - end - # for adding products which are closely related to existing ones def duplicate duplicator = Spree::Core::ProductDuplicator.new(self) diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 0c98ba005d..16536cb60d 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -28,9 +28,10 @@ module Spree supplier_name).join('_or_')}_cont".freeze belongs_to :product, -> { with_deleted }, touch: true, class_name: 'Spree::Product' + belongs_to :tax_category, class_name: 'Spree::TaxCategory' - delegate_belongs_to :product, :name, :description, :tax_category_id, :shipping_category_id, - :meta_keywords, :tax_category, :shipping_category + delegate_belongs_to :product, :name, :description, :shipping_category_id, + :meta_keywords, :shipping_category has_many :inventory_units, inverse_of: :variant has_many :line_items, inverse_of: :variant @@ -61,8 +62,9 @@ module Spree localize_number :price, :weight validate :check_currency - validates :price, numericality: { greater_than_or_equal_to: 0 }, - presence: true + validates :price, numericality: { greater_than_or_equal_to: 0 }, presence: true + validates :tax_category, presence: true, + if: proc { Spree::Config[:products_require_tax_category] } validates :unit_value, presence: true, if: ->(variant) { %w(weight volume).include?(variant.product&.variant_unit) @@ -166,6 +168,14 @@ module Spree select("spree_variants.id")) end + def tax_category + if self[:tax_category_id].nil? + TaxCategory.find_by(is_default: true) + else + TaxCategory.find(self[:tax_category_id]) + end + end + def price_with_fees(distributor, order_cycle) price + fees_for(distributor, order_cycle) end