Signed-off-by: Adrian Hinz <ahinz@voicetelecom.pl>

This commit is contained in:
Adrian Hinz 2016-10-03 10:31:18 +02:00
parent 61e40939bf
commit 6448fc0281
14 changed files with 187 additions and 1 deletions

View File

@ -3,4 +3,30 @@ class ProductsController < ApplicationController
def index
end
def new
end
def create
end
def edit
end
def update
end
def destroy
end
private
def product_params
params.require(:product).permit(:name, :vat_id)
end
end

3
app/models/product.rb Normal file
View File

@ -0,0 +1,3 @@
class Product < ApplicationRecord
belongs_to :vat
end

3
app/models/user_firm.rb Normal file
View File

@ -0,0 +1,3 @@
class UserFirm < ApplicationRecord
belongs_to :user
end

3
app/models/vat.rb Normal file
View File

@ -0,0 +1,3 @@
class Vat < ApplicationRecord
has_many :products
end

View File

@ -0,0 +1,11 @@
class CreateVats < ActiveRecord::Migration[5.0]
def change
create_table :vats do |t|
t.string :name
t.date :start_date
t.decimal :tax_rate, { precision: 6, scale: 2 }
t.timestamps
end
end
end

View File

@ -0,0 +1,12 @@
class CreateProducts < ActiveRecord::Migration[5.0]
def change
create_table :products do |t|
t.string :name
t.references :vat, foreign_key: true
t.decimal :netto_price, { precision: 18, scale: 2 }
t.string :qnt_name
t.timestamps
end
end
end

View File

@ -0,0 +1,19 @@
class CreateUserFirms < ActiveRecord::Migration[5.0]
def change
create_table :user_firms do |t|
t.references :user, foreign_key: true
t.string :name
t.string :street
t.string :postcode
t.string :city
t.string :nip
t.string :regon
t.string :bank_name
t.string :bank_account
t.boolean :main
t.boolean :active
t.timestamps
end
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160930103815) do
ActiveRecord::Schema.define(version: 20161003081718) do
create_table "customers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t|
t.string "name"
@ -23,6 +23,33 @@ ActiveRecord::Schema.define(version: 20160930103815) do
t.datetime "updated_at", null: false
end
create_table "products", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t|
t.string "name"
t.integer "vat_id"
t.decimal "netto_price", precision: 18, scale: 2
t.string "qnt_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["vat_id"], name: "index_products_on_vat_id", using: :btree
end
create_table "user_firms", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t|
t.integer "user_id"
t.string "name"
t.string "street"
t.string "postcode"
t.string "city"
t.string "nip"
t.string "regon"
t.string "bank_name"
t.string "bank_account"
t.boolean "main"
t.boolean "active"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_user_firms_on_user_id", using: :btree
end
create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
@ -40,4 +67,14 @@ ActiveRecord::Schema.define(version: 20160930103815) do
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end
create_table "vats", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t|
t.string "name"
t.date "start_date"
t.decimal "tax_rate", precision: 6, scale: 2
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_foreign_key "products", "vats"
add_foreign_key "user_firms", "users"
end

13
test/fixtures/products.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
vat: one
netto_price:
qnt_name: MyString
two:
name: MyString
vat: two
netto_price:
qnt_name: MyString

27
test/fixtures/user_firms.yml vendored Normal file
View File

@ -0,0 +1,27 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
user: one
name: MyString
street: MyString
postcode: MyString
city: MyString
nip: MyString
regon: MyString
bank_name: MyString
bank_account: MyString
main: false
active: false
two:
user: two
name: MyString
street: MyString
postcode: MyString
city: MyString
nip: MyString
regon: MyString
bank_name: MyString
bank_account: MyString
main: false
active: false

11
test/fixtures/vats.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
start_date: 2016-10-03
tax_rate:
two:
name: MyString
start_date: 2016-10-03
tax_rate:

View File

@ -0,0 +1,7 @@
require 'test_helper'
class ProductTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class UserFirmTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

7
test/models/vat_test.rb Normal file
View File

@ -0,0 +1,7 @@
require 'test_helper'
class VatTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end