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.
This commit is contained in:
parent
f5bbe0d5ae
commit
d90d188dbf
11 changed files with 90 additions and 25 deletions
|
@ -27,6 +27,7 @@ class SuppliersController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@supplier = Supplier.new(supplier_params)
|
@supplier = Supplier.new(supplier_params)
|
||||||
|
@supplier.supplier_category ||= SupplierCategory.first
|
||||||
if @supplier.save
|
if @supplier.save
|
||||||
flash[:notice] = I18n.t('suppliers.create.notice')
|
flash[:notice] = I18n.t('suppliers.create.notice')
|
||||||
redirect_to suppliers_path
|
redirect_to suppliers_path
|
||||||
|
@ -70,7 +71,7 @@ class SuppliersController < ApplicationController
|
||||||
params
|
params
|
||||||
.require(:supplier)
|
.require(:supplier)
|
||||||
.permit(:name, :address, :phone, :phone2, :fax, :email, :url, :contact_person, :customer_number,
|
.permit(:name, :address, :phone, :phone2, :fax, :email, :url, :contact_person, :customer_number,
|
||||||
:iban, :custom_fields, :delivery_days, :order_howto, :note,
|
:iban, :custom_fields, :delivery_days, :order_howto, :note, :supplier_category_id,
|
||||||
:shared_supplier_id, :min_order_quantity, :shared_sync_method)
|
:shared_supplier_id, :min_order_quantity, :shared_sync_method)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class FinancialTransactionClass < ApplicationRecord
|
class FinancialTransactionClass < ApplicationRecord
|
||||||
has_many :financial_transaction_types, dependent: :destroy
|
has_many :financial_transaction_types, dependent: :destroy
|
||||||
|
has_many :supplier_category, dependent: :restrict_with_exception
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
|
|
|
@ -8,6 +8,7 @@ class Supplier < ApplicationRecord
|
||||||
has_many :orders
|
has_many :orders
|
||||||
has_many :deliveries
|
has_many :deliveries
|
||||||
has_many :invoices
|
has_many :invoices
|
||||||
|
belongs_to :supplier_category
|
||||||
belongs_to :shared_supplier # for the sharedLists-App
|
belongs_to :shared_supplier # for the sharedLists-App
|
||||||
|
|
||||||
validates :name, :presence => true, :length => { :in => 4..30 }
|
validates :name, :presence => true, :length => { :in => 4..30 }
|
||||||
|
|
19
app/models/supplier_category.rb
Normal file
19
app/models/supplier_category.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
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
|
|
@ -12,6 +12,9 @@
|
||||||
= f.input :url
|
= f.input :url
|
||||||
= f.input :contact_person
|
= f.input :contact_person
|
||||||
= f.input :customer_number
|
= f.input :customer_number
|
||||||
|
- supplier_categories = SupplierCategory.order(:name)
|
||||||
|
- if supplier_categories.count > 1
|
||||||
|
= f.association :supplier_category, collection: supplier_categories, include_blank: false
|
||||||
- if FoodsoftConfig[:use_iban]
|
- if FoodsoftConfig[:use_iban]
|
||||||
= f.input :iban
|
= f.input :iban
|
||||||
= f.input :delivery_days
|
= f.input :delivery_days
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
%dd= @supplier.contact_person
|
%dd= @supplier.contact_person
|
||||||
%dt= heading_helper(Supplier, :customer_number) + ':'
|
%dt= heading_helper(Supplier, :customer_number) + ':'
|
||||||
%dd= @supplier.customer_number
|
%dd= @supplier.customer_number
|
||||||
|
- if SupplierCategory.count > 1
|
||||||
|
%dt= heading_helper(Supplier, :supplier_category) + ':'
|
||||||
|
%dd= @supplier.supplier_category.try(:name)
|
||||||
- if FoodsoftConfig[:use_iban]
|
- if FoodsoftConfig[:use_iban]
|
||||||
%dt= heading_helper(Supplier, :iban) + ':'
|
%dt= heading_helper(Supplier, :iban) + ':'
|
||||||
%dd= @supplier.iban
|
%dd= @supplier.iban
|
||||||
|
|
25
db/migrate/20181201000400_create_supplier_categories.rb
Normal file
25
db/migrate/20181201000400_create_supplier_categories.rb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
class CreateSupplierCategories < ActiveRecord::Migration
|
||||||
|
class FinancialTransactionClass < ActiveRecord::Base; end
|
||||||
|
class SupplierCategory < ActiveRecord::Base; end
|
||||||
|
class Supplier < ActiveRecord::Base; end
|
||||||
|
|
||||||
|
def change
|
||||||
|
create_table :supplier_categories do |t|
|
||||||
|
t.string :name, null: false
|
||||||
|
t.string :description
|
||||||
|
t.references :financial_transaction_class, null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_reference :suppliers, :supplier_category
|
||||||
|
|
||||||
|
reversible do |dir|
|
||||||
|
dir.up do
|
||||||
|
ftc = FinancialTransactionClass.first
|
||||||
|
sc = SupplierCategory.create name: 'Other', financial_transaction_class_id: ftc.id
|
||||||
|
Supplier.update_all supplier_category_id: sc.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
change_column_null :suppliers, :supplier_category_id, false
|
||||||
|
end
|
||||||
|
end
|
|
@ -488,6 +488,12 @@ ActiveRecord::Schema.define(version: 20181205010000) do
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "supplier_categories", force: :cascade do |t|
|
||||||
|
t.string "name", limit: 255, null: false
|
||||||
|
t.string "description", limit: 255
|
||||||
|
t.integer "financial_transaction_class_id", limit: 4
|
||||||
|
end
|
||||||
|
|
||||||
create_table "suppliers", force: :cascade do |t|
|
create_table "suppliers", force: :cascade do |t|
|
||||||
t.string "name", limit: 255, default: "", null: false
|
t.string "name", limit: 255, default: "", null: false
|
||||||
t.string "address", limit: 255, default: "", null: false
|
t.string "address", limit: 255, default: "", null: false
|
||||||
|
@ -506,6 +512,7 @@ ActiveRecord::Schema.define(version: 20181205010000) do
|
||||||
t.datetime "deleted_at"
|
t.datetime "deleted_at"
|
||||||
t.string "shared_sync_method", limit: 255
|
t.string "shared_sync_method", limit: 255
|
||||||
t.string "iban", limit: 255
|
t.string "iban", limit: 255
|
||||||
|
t.integer "supplier_category_id", limit: 4
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "suppliers", ["name"], name: "index_suppliers_on_name", unique: true, using: :btree
|
add_index "suppliers", ["name"], name: "index_suppliers_on_name", unique: true, using: :btree
|
||||||
|
|
|
@ -27,4 +27,5 @@ financial_transaction_class = FinancialTransactionClass.create(:name => "Other")
|
||||||
FinancialTransactionType.create(:name => "Foodcoop", :financial_transaction_class_id => financial_transaction_class.id)
|
FinancialTransactionType.create(:name => "Foodcoop", :financial_transaction_class_id => financial_transaction_class.id)
|
||||||
|
|
||||||
# First entry for article categories
|
# First entry for article categories
|
||||||
|
SupplierCategory.create(:name => "Other")
|
||||||
ArticleCategory.create(:name => "Other", :description => "other, misc, unknown")
|
ArticleCategory.create(:name => "Other", :description => "other, misc, unknown")
|
||||||
|
|
|
@ -2,11 +2,13 @@ require_relative 'seed_helper.rb'
|
||||||
|
|
||||||
## Suppliers & articles
|
## Suppliers & articles
|
||||||
|
|
||||||
|
SupplierCategory.create(:id => 1, :name => "Other")
|
||||||
|
|
||||||
Supplier.create([
|
Supplier.create([
|
||||||
{:id => 1, :name => "Beautiful bakery", :address => "Smallstreet 1, Cookilage", :phone => "0123456789", :email => "info@bbakery.test", :min_order_quantity => "100"},
|
{:id => 1, :name => "Beautiful bakery", :supplier_category_id => 1, :address => "Smallstreet 1, Cookilage", :phone => "0123456789", :email => "info@bbakery.test", :min_order_quantity => "100"},
|
||||||
{:id => 2, :name => "Chocolatiers", :address => "Multatuliroad 1, Amsterdam", :phone => "0123456789", :email => "info@chocolatiers.test", :url => "http://www.chocolatiers.test/", :contact_person => "Max Pure", :delivery_days => "Tue, Fr (Amsterdam)"},
|
{:id => 2, :name => "Chocolatiers", :supplier_category_id => 1, :address => "Multatuliroad 1, Amsterdam", :phone => "0123456789", :email => "info@chocolatiers.test", :url => "http://www.chocolatiers.test/", :contact_person => "Max Pure", :delivery_days => "Tue, Fr (Amsterdam)"},
|
||||||
{:id => 3, :name => "Cheesemaker", :address => "Cheesestreet 5, London", :phone => "0123456789", :url => "http://www.cheesemaker.test/"},
|
{:id => 3, :name => "Cheesemaker", :supplier_category_id => 1, :address => "Cheesestreet 5, London", :phone => "0123456789", :url => "http://www.cheesemaker.test/"},
|
||||||
{:id => 4, :name => "The Nuthome", :address => "Alexanderplatz, Berlin", :phone => "0123456789", :email => "info@thenuthome.test", :url => "http://www.thenuthome.test/", :note => "delivery in Berlin; €9 delivery costs for orders under €123"}
|
{:id => 4, :name => "The Nuthome", :supplier_category_id => 1, :address => "Alexanderplatz, Berlin", :phone => "0123456789", :email => "info@thenuthome.test", :url => "http://www.thenuthome.test/", :note => "delivery in Berlin; €9 delivery costs for orders under €123"}
|
||||||
])
|
])
|
||||||
|
|
||||||
ArticleCategory.create(:id => 1, :name => "Other", :description => "other, misc, unknown")
|
ArticleCategory.create(:id => 1, :name => "Other", :description => "other, misc, unknown")
|
||||||
|
|
|
@ -2,11 +2,13 @@ require_relative 'seed_helper.rb'
|
||||||
|
|
||||||
## Suppliers & articles
|
## Suppliers & articles
|
||||||
|
|
||||||
|
SupplierCategory.create(:id => 1, :name => "Other")
|
||||||
|
|
||||||
Supplier.create([
|
Supplier.create([
|
||||||
{:id => 1, :name => "Koekenbakker", :address => "Dorpsstraat 1, Koekange", :phone => "012 3456789", :email => "info@dekoekenbakker.test", :min_order_quantity => "100"},
|
{:id => 1, :name => "Koekenbakker", :supplier_category_id => 1, :address => "Dorpsstraat 1, Koekange", :phone => "012 3456789", :email => "info@dekoekenbakker.test", :min_order_quantity => "100"},
|
||||||
{:id => 2, :name => "Chocolademakkers", :address => "Multatuliweg 1, Amsterdam", :phone => "012 3456789", :email => "info@chocolademakkers.test", :url => "http://www.chocolademakkers.test/", :contact_person => "Max Puur", :delivery_days => "di, vr (Amsterdam)"},
|
{:id => 2, :name => "Chocolademakkers", :supplier_category_id => 1, :address => "Multatuliweg 1, Amsterdam", :phone => "012 3456789", :email => "info@chocolademakkers.test", :url => "http://www.chocolademakkers.test/", :contact_person => "Max Puur", :delivery_days => "di, vr (Amsterdam)"},
|
||||||
{:id => 3, :name => "Kaasmaker", :address => "Waagplein, Alkmaar", :phone => "012 3456789", :url => "http://www.kaaskamer.test/"},
|
{:id => 3, :name => "Kaasmaker", :supplier_category_id => 1, :address => "Waagplein, Alkmaar", :phone => "012 3456789", :url => "http://www.kaaskamer.test/"},
|
||||||
{:id => 4, :name => "Notenhuis", :address => "Damrak 1, Amsterdam", :phone => "012 3456789", :email => "info@notenhuis.test", :url => "http://www.notenhuis.test/", :note => "leveren in Amsterdam; €9 leverkosten bij bestellingen onder €123"}
|
{:id => 4, :name => "Notenhuis", :supplier_category_id => 1, :address => "Damrak 1, Amsterdam", :phone => "012 3456789", :email => "info@notenhuis.test", :url => "http://www.notenhuis.test/", :note => "leveren in Amsterdam; €9 leverkosten bij bestellingen onder €123"}
|
||||||
])
|
])
|
||||||
|
|
||||||
ArticleCategory.create(:id => 1, :name => "Other", :description => "overig, anders, onbekend")
|
ArticleCategory.create(:id => 1, :name => "Other", :description => "overig, anders, onbekend")
|
||||||
|
|
Loading…
Reference in a new issue