foodsoft/app/models/supplier_category.rb
Patrick Gansterer d90d188dbf Add SupplierCategory
This allows the categorization of suppliers. For a better reporting
it is necessary to split the expenses of the invoices.
E.g. we want to be able to generate independent sums of general cost
like the rent or electricity and the cost of the bought articles.
2020-07-30 17:46:07 +02:00

19 lines
531 B
Ruby

class SupplierCategory < ActiveRecord::Base
belongs_to :financial_transaction_class
has_many :suppliers
normalize_attributes :name, :description
validates :name, presence: true, uniqueness: true, length: { minimum: 2 }
before_destroy :check_for_associated_suppliers
protected
# Deny deleting the category when there are associated suppliers.
def check_for_associated_suppliers
raise I18n.t('activerecord.errors.has_many_left', collection: Supplier.model_name.human) if suppliers.undeleted.any?
end
end