added suppliers, weight to item
This commit is contained in:
4
back-office/app/controllers/suppliers_controller.rb
Normal file
4
back-office/app/controllers/suppliers_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class SuppliersController < ApplicationController
|
||||
active_scaffold :"supplier" do |conf|
|
||||
end
|
||||
end
|
||||
2
back-office/app/helpers/suppliers_helper.rb
Normal file
2
back-office/app/helpers/suppliers_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module SuppliersHelper
|
||||
end
|
||||
@@ -1,2 +1,6 @@
|
||||
class Cart < ActiveRecord::Base
|
||||
|
||||
has_many :item_in_carts
|
||||
belongs_to :user
|
||||
|
||||
end
|
||||
|
||||
@@ -2,6 +2,9 @@ class Item < ActiveRecord::Base
|
||||
belongs_to :unit
|
||||
has_many :multi_media_descriptions
|
||||
belongs_to :sub_category
|
||||
belongs_to :supplier
|
||||
|
||||
validates_presence_of :name, :description, :list_price, :current_input_price, :tags, :unit_id, :code, :sub_category_id, :weight, :supplier_id
|
||||
|
||||
|
||||
validates_presence_of :name, :description, :list_price, :current_input_price, :tags, :unit_id, :code, :sub_category_id
|
||||
end
|
||||
|
||||
@@ -5,4 +5,8 @@ class ItemInCart < ActiveRecord::Base
|
||||
validates_uniqueness_of :item_id, scope: :cart_id
|
||||
validates :item_id, presence: true
|
||||
validates :cart_id, presence: true
|
||||
|
||||
def to_s
|
||||
item.name + " " + count.to_s + " " + price.to_s
|
||||
end
|
||||
end
|
||||
|
||||
6
back-office/app/models/supplier.rb
Normal file
6
back-office/app/models/supplier.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class Supplier < ActiveRecord::Base
|
||||
has_many :items
|
||||
|
||||
validates_uniqueness_of :name
|
||||
validates_presence_of :name
|
||||
end
|
||||
10
back-office/app/models/user.rb
Normal file
10
back-office/app/models/user.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class User < ActiveRecord::Base
|
||||
has_many :carts
|
||||
|
||||
validates_presence_of :first_name, :last_name, :password, :email, :password_confirmation
|
||||
|
||||
validates :email, :uniqueness => {:case_sensitive => false, :message => "Email already exists!"},
|
||||
format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, message: "invalid email" }
|
||||
|
||||
validates :password, confirmation: true, length: { in:6..20, too_short: 'password needs to be at least 6 characters long' }
|
||||
end
|
||||
@@ -1,5 +1,6 @@
|
||||
Rails.application.routes.draw do
|
||||
|
||||
resources :suppliers do as_routes end
|
||||
resources :places do as_routes end
|
||||
resources :delivery_destinations do as_routes end
|
||||
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
|
||||
|
||||
16
back-office/db/migrate/20150314033113_create_suppliers.rb
Normal file
16
back-office/db/migrate/20150314033113_create_suppliers.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class CreateSuppliers < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :suppliers do |t|
|
||||
t.string :name
|
||||
t.string :address
|
||||
t.string :postal_code
|
||||
t.string :town
|
||||
t.string :phone
|
||||
t.string :contact_person
|
||||
t.string :email
|
||||
t.text :note
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddSupplierToItem < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :items, :supplier_id, :integer
|
||||
end
|
||||
end
|
||||
149
back-office/db/schema.rb
Normal file
149
back-office/db/schema.rb
Normal file
@@ -0,0 +1,149 @@
|
||||
# encoding: UTF-8
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150314033704) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
create_table "carts", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.boolean "ordered", default: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "anonymous_id_string"
|
||||
t.integer "delivery_destination_id"
|
||||
end
|
||||
|
||||
create_table "categories", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.integer "section_id"
|
||||
t.string "image_url"
|
||||
end
|
||||
|
||||
create_table "delivery_destinations", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "address"
|
||||
t.string "place"
|
||||
t.string "postal_code"
|
||||
t.string "phone"
|
||||
t.string "email"
|
||||
t.text "note"
|
||||
t.boolean "email_verified"
|
||||
t.boolean "phone_verified"
|
||||
t.string "phone_verification_code"
|
||||
t.string "email_verification_code"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "user_id"
|
||||
t.string "anonymous_id_string"
|
||||
end
|
||||
|
||||
create_table "filter_criteria", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.string "field_name"
|
||||
t.integer "type"
|
||||
t.string "owner_type"
|
||||
t.integer "owner_id"
|
||||
end
|
||||
|
||||
create_table "filter_criteria_values", force: :cascade do |t|
|
||||
t.string "filter_text"
|
||||
t.string "filter_value"
|
||||
t.integer "filter_criteria_id"
|
||||
end
|
||||
|
||||
create_table "item_in_carts", force: :cascade do |t|
|
||||
t.integer "cart_id"
|
||||
t.integer "item_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "count"
|
||||
t.decimal "price"
|
||||
end
|
||||
|
||||
create_table "items", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "code", limit: 10
|
||||
t.decimal "current_input_price", precision: 5, scale: 2
|
||||
t.decimal "list_price", precision: 5, scale: 2
|
||||
t.integer "unit_id"
|
||||
t.decimal "units_in_pack", precision: 5, scale: 3
|
||||
t.text "description"
|
||||
t.integer "sub_category_id"
|
||||
t.integer "stock"
|
||||
t.boolean "on_display"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "tags"
|
||||
t.json "traits"
|
||||
t.integer "supplier_id"
|
||||
end
|
||||
|
||||
create_table "media_types", force: :cascade do |t|
|
||||
t.string "name"
|
||||
end
|
||||
|
||||
create_table "multi_media_descriptions", force: :cascade do |t|
|
||||
t.string "url"
|
||||
t.integer "item_id"
|
||||
t.integer "media_type_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "places", force: :cascade do |t|
|
||||
t.string "postal_code"
|
||||
t.decimal "delivery_price"
|
||||
t.string "name"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "sections", force: :cascade do |t|
|
||||
t.string "name"
|
||||
end
|
||||
|
||||
create_table "sub_categories", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.integer "category_id"
|
||||
end
|
||||
|
||||
create_table "suppliers", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "address"
|
||||
t.string "postal_code"
|
||||
t.string "town"
|
||||
t.string "phone"
|
||||
t.string "contact_person"
|
||||
t.string "email"
|
||||
t.text "note"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "units", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "short_name", limit: 4
|
||||
t.string "description_suffix"
|
||||
t.string "number_of_pieces_suffix"
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "first_name"
|
||||
t.string "last_name"
|
||||
t.string "email"
|
||||
t.string "password_digest"
|
||||
end
|
||||
|
||||
end
|
||||
49
back-office/test/controllers/suppliers_controller_test.rb
Normal file
49
back-office/test/controllers/suppliers_controller_test.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
require 'test_helper'
|
||||
|
||||
class SuppliersControllerTest < ActionController::TestCase
|
||||
setup do
|
||||
@supplier = suppliers(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_not_nil assigns(:suppliers)
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get :new
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create supplier" do
|
||||
assert_difference('Supplier.count') do
|
||||
post :create, supplier: { address: @supplier.address, contact_person: @supplier.contact_person, email: @supplier.email, name: @supplier.name, note: @supplier.note, phone: @supplier.phone, postal_code: @supplier.postal_code, town: @supplier.town }
|
||||
end
|
||||
|
||||
assert_redirected_to supplier_path(assigns(:supplier))
|
||||
end
|
||||
|
||||
test "should show supplier" do
|
||||
get :show, id: @supplier
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get :edit, id: @supplier
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update supplier" do
|
||||
patch :update, id: @supplier, supplier: { address: @supplier.address, contact_person: @supplier.contact_person, email: @supplier.email, name: @supplier.name, note: @supplier.note, phone: @supplier.phone, postal_code: @supplier.postal_code, town: @supplier.town }
|
||||
assert_redirected_to supplier_path(assigns(:supplier))
|
||||
end
|
||||
|
||||
test "should destroy supplier" do
|
||||
assert_difference('Supplier.count', -1) do
|
||||
delete :destroy, id: @supplier
|
||||
end
|
||||
|
||||
assert_redirected_to suppliers_path
|
||||
end
|
||||
end
|
||||
21
back-office/test/fixtures/suppliers.yml
vendored
Normal file
21
back-office/test/fixtures/suppliers.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
name: MyString
|
||||
address: MyString
|
||||
postal_code: MyString
|
||||
town: MyString
|
||||
phone: MyString
|
||||
contact_person: MyString
|
||||
email: MyString
|
||||
note: MyText
|
||||
|
||||
two:
|
||||
name: MyString
|
||||
address: MyString
|
||||
postal_code: MyString
|
||||
town: MyString
|
||||
phone: MyString
|
||||
contact_person: MyString
|
||||
email: MyString
|
||||
note: MyText
|
||||
7
back-office/test/models/supplier_test.rb
Normal file
7
back-office/test/models/supplier_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class SupplierTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddWeigthToItem < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :items, :weight, :decimal, precision: 5, scale: 3
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150313065130) do
|
||||
ActiveRecord::Schema.define(version: 20150314033743) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -87,6 +87,8 @@ ActiveRecord::Schema.define(version: 20150313065130) do
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "tags"
|
||||
t.json "traits"
|
||||
t.integer "supplier_id"
|
||||
t.decimal "weight", precision: 5, scale: 3
|
||||
end
|
||||
|
||||
create_table "media_types", force: :cascade do |t|
|
||||
@@ -118,6 +120,19 @@ ActiveRecord::Schema.define(version: 20150313065130) do
|
||||
t.integer "category_id"
|
||||
end
|
||||
|
||||
create_table "suppliers", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "address"
|
||||
t.string "postal_code"
|
||||
t.string "town"
|
||||
t.string "phone"
|
||||
t.string "contact_person"
|
||||
t.string "email"
|
||||
t.text "note"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "units", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "short_name", limit: 4
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class User < ActiveRecord::Base
|
||||
has_many :carts
|
||||
has_secure_password
|
||||
validates_presence_of :first_name, :last_name, :password, :email, :password_confirmation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user