special offers backoffice is ready now
This commit is contained in:
@@ -31,6 +31,8 @@ gem 'puma'
|
|||||||
# for uploading images
|
# for uploading images
|
||||||
gem 'cloudinary'
|
gem 'cloudinary'
|
||||||
|
|
||||||
|
gem 'tabulous'
|
||||||
|
|
||||||
# Use ActiveModel has_secure_password
|
# Use ActiveModel has_secure_password
|
||||||
# gem 'bcrypt', '~> 3.1.7'
|
# gem 'bcrypt', '~> 3.1.7'
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ GEM
|
|||||||
coffee-script-source
|
coffee-script-source
|
||||||
execjs
|
execjs
|
||||||
coffee-script-source (1.8.0)
|
coffee-script-source (1.8.0)
|
||||||
|
colored (1.2)
|
||||||
columnize (0.9.0)
|
columnize (0.9.0)
|
||||||
debug_inspector (0.0.2)
|
debug_inspector (0.0.2)
|
||||||
debugger-linecache (1.2.0)
|
debugger-linecache (1.2.0)
|
||||||
@@ -177,6 +178,9 @@ GEM
|
|||||||
actionpack (>= 3.0)
|
actionpack (>= 3.0)
|
||||||
activesupport (>= 3.0)
|
activesupport (>= 3.0)
|
||||||
sprockets (>= 2.8, < 4.0)
|
sprockets (>= 2.8, < 4.0)
|
||||||
|
tabulous (2.1.3)
|
||||||
|
colored (~> 1.2.0)
|
||||||
|
rails (>= 3.0, < 5.0.0)
|
||||||
thor (0.19.1)
|
thor (0.19.1)
|
||||||
thread_safe (0.3.4)
|
thread_safe (0.3.4)
|
||||||
tilt (1.4.1)
|
tilt (1.4.1)
|
||||||
@@ -211,6 +215,7 @@ DEPENDENCIES
|
|||||||
sass-rails (~> 5.0)
|
sass-rails (~> 5.0)
|
||||||
sdoc (~> 0.4.0)
|
sdoc (~> 0.4.0)
|
||||||
spring
|
spring
|
||||||
|
tabulous
|
||||||
turbolinks
|
turbolinks
|
||||||
uglifier (>= 1.3.0)
|
uglifier (>= 1.3.0)
|
||||||
web-console (~> 2.0)
|
web-console (~> 2.0)
|
||||||
|
|||||||
8
back-office/app/controllers/reports_controller.rb
Normal file
8
back-office/app/controllers/reports_controller.rb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
class ReportsController < ApplicationController
|
||||||
|
|
||||||
|
def items_to_order
|
||||||
|
@items = Item.items_to_order
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
4
back-office/app/controllers/special_offers_controller.rb
Normal file
4
back-office/app/controllers/special_offers_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
class SpecialOffersController < ApplicationController
|
||||||
|
active_scaffold :"special_offer" do |conf|
|
||||||
|
end
|
||||||
|
end
|
||||||
2
back-office/app/helpers/special_offers_helper.rb
Normal file
2
back-office/app/helpers/special_offers_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module SpecialOffersHelper
|
||||||
|
end
|
||||||
@@ -3,8 +3,24 @@ class Item < ActiveRecord::Base
|
|||||||
has_many :multi_media_descriptions
|
has_many :multi_media_descriptions
|
||||||
belongs_to :sub_category
|
belongs_to :sub_category
|
||||||
belongs_to :supplier
|
belongs_to :supplier
|
||||||
|
belongs_to :special_offer
|
||||||
|
|
||||||
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, :weight, :supplier_id
|
||||||
|
|
||||||
|
|
||||||
|
# todo build a front end in backoffice (rails)
|
||||||
|
def self.items_to_order
|
||||||
|
return Item.find_by_sql(%Q{
|
||||||
|
select s.name as supplier, i.name as item, sum(iic.count) amount, i.current_input_price
|
||||||
|
from carts c
|
||||||
|
join item_in_carts iic on iic.cart_id = c.id
|
||||||
|
join items i on i.id = iic.item_id
|
||||||
|
join suppliers s on i.supplier_id = s.id
|
||||||
|
where c.confirmed and not (c.packed or c.delivered)
|
||||||
|
group by s.name, i.name, i.current_input_price
|
||||||
|
order by s.name, amount desc;
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
16
back-office/app/models/special_offer.rb
Normal file
16
back-office/app/models/special_offer.rb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
class SpecialOffer < ActiveRecord::Base
|
||||||
|
belongs_to :item
|
||||||
|
belongs_to :category
|
||||||
|
belongs_to :section
|
||||||
|
belongs_to :sub_category
|
||||||
|
has_many :items
|
||||||
|
|
||||||
|
validates_presence_of :beginning, :ending, :image_url
|
||||||
|
validate :validate_beginning_before_ending
|
||||||
|
|
||||||
|
def validate_beginning_before_ending
|
||||||
|
if beginning && ending
|
||||||
|
errors.add(:ending, "End date must come after beginning date") if ending <= beginning
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
13
back-office/app/tabs/tabulous.rb
Normal file
13
back-office/app/tabs/tabulous.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
Tabulous.setup do
|
||||||
|
tabs do
|
||||||
|
|
||||||
|
get_from_suppliers_tab do
|
||||||
|
text { 'From suppliers' }
|
||||||
|
link_path { '/' }
|
||||||
|
visible_when { true }
|
||||||
|
enabled_when { true }
|
||||||
|
active_when { in_action('any').of_controller('pictures') }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
|
||||||
|
resources :special_offers do as_routes end
|
||||||
resources :suppliers do as_routes end
|
resources :suppliers do as_routes end
|
||||||
resources :places do as_routes end
|
resources :places do as_routes end
|
||||||
resources :delivery_destinations do as_routes end
|
resources :delivery_destinations do as_routes end
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class SpecialOffersControllerTest < ActionController::TestCase
|
||||||
|
setup do
|
||||||
|
@special_offer = special_offers(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:special_offers)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create special_offer" do
|
||||||
|
assert_difference('SpecialOffer.count') do
|
||||||
|
post :create, special_offer: { beginning: @special_offer.beginning, category_id: @special_offer.category_id, checkout_page: @special_offer.checkout_page, ending: @special_offer.ending, image_url: @special_offer.image_url, item_id: @special_offer.item_id, search_result_page: @special_offer.search_result_page, section_id: @special_offer.section_id, start_page: @special_offer.start_page, sub_category_id: @special_offer.sub_category_id, thank_you_page: @special_offer.thank_you_page }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to special_offer_path(assigns(:special_offer))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show special_offer" do
|
||||||
|
get :show, id: @special_offer
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get :edit, id: @special_offer
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update special_offer" do
|
||||||
|
patch :update, id: @special_offer, special_offer: { beginning: @special_offer.beginning, category_id: @special_offer.category_id, checkout_page: @special_offer.checkout_page, ending: @special_offer.ending, image_url: @special_offer.image_url, item_id: @special_offer.item_id, search_result_page: @special_offer.search_result_page, section_id: @special_offer.section_id, start_page: @special_offer.start_page, sub_category_id: @special_offer.sub_category_id, thank_you_page: @special_offer.thank_you_page }
|
||||||
|
assert_redirected_to special_offer_path(assigns(:special_offer))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy special_offer" do
|
||||||
|
assert_difference('SpecialOffer.count', -1) do
|
||||||
|
delete :destroy, id: @special_offer
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to special_offers_path
|
||||||
|
end
|
||||||
|
end
|
||||||
27
back-office/test/fixtures/special_offers.yml
vendored
Normal file
27
back-office/test/fixtures/special_offers.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
image_url: MyString
|
||||||
|
start_page: false
|
||||||
|
section_id: 1
|
||||||
|
category_id: 1
|
||||||
|
sub_category_id: 1
|
||||||
|
item_id: 1
|
||||||
|
thank_you_page: false
|
||||||
|
search_result_page: false
|
||||||
|
checkout_page: false
|
||||||
|
beginning: 2015-03-18
|
||||||
|
ending: 2015-03-18
|
||||||
|
|
||||||
|
two:
|
||||||
|
image_url: MyString
|
||||||
|
start_page: false
|
||||||
|
section_id: 1
|
||||||
|
category_id: 1
|
||||||
|
sub_category_id: 1
|
||||||
|
item_id: 1
|
||||||
|
thank_you_page: false
|
||||||
|
search_result_page: false
|
||||||
|
checkout_page: false
|
||||||
|
beginning: 2015-03-18
|
||||||
|
ending: 2015-03-18
|
||||||
7
back-office/test/models/special_offer_test.rb
Normal file
7
back-office/test/models/special_offer_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class SpecialOfferTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
10
front-api/db/migrate/20150315074249_add_flags_to_cart.rb
Normal file
10
front-api/db/migrate/20150315074249_add_flags_to_cart.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class AddFlagsToCart < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :carts, :confirmed, :boolean, default: false
|
||||||
|
add_column :carts, :packed, :boolean, default: false
|
||||||
|
add_column :carts, :canceled_on_check, :boolean, default: false
|
||||||
|
add_column :carts, :canceled_on_delivery, :boolean, default: false
|
||||||
|
add_column :carts, :delivered, :boolean, default: false
|
||||||
|
add_column :carts, :internal_note, :text
|
||||||
|
end
|
||||||
|
end
|
||||||
19
front-api/db/migrate/20150318044804_create_special_offers.rb
Normal file
19
front-api/db/migrate/20150318044804_create_special_offers.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
class CreateSpecialOffers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :special_offers do |t|
|
||||||
|
t.string :image_url
|
||||||
|
t.boolean :start_page
|
||||||
|
t.integer :section_id
|
||||||
|
t.integer :category_id
|
||||||
|
t.integer :sub_category_id
|
||||||
|
t.integer :item_id
|
||||||
|
t.boolean :thank_you_page
|
||||||
|
t.boolean :search_result_page
|
||||||
|
t.boolean :checkout_page
|
||||||
|
t.date :beginning
|
||||||
|
t.date :ending
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddSpecialOfferToItem < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :items, :special_offer_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150314033743) do
|
ActiveRecord::Schema.define(version: 20150318044933) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -23,6 +23,12 @@ ActiveRecord::Schema.define(version: 20150314033743) do
|
|||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "anonymous_id_string"
|
t.string "anonymous_id_string"
|
||||||
t.integer "delivery_destination_id"
|
t.integer "delivery_destination_id"
|
||||||
|
t.boolean "confirmed"
|
||||||
|
t.boolean "packed"
|
||||||
|
t.boolean "canceled_on_check"
|
||||||
|
t.boolean "canceled_on_delivery"
|
||||||
|
t.boolean "delivered"
|
||||||
|
t.text "internal_note"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "categories", force: :cascade do |t|
|
create_table "categories", force: :cascade do |t|
|
||||||
@@ -89,6 +95,7 @@ ActiveRecord::Schema.define(version: 20150314033743) do
|
|||||||
t.json "traits"
|
t.json "traits"
|
||||||
t.integer "supplier_id"
|
t.integer "supplier_id"
|
||||||
t.decimal "weight", precision: 5, scale: 3
|
t.decimal "weight", precision: 5, scale: 3
|
||||||
|
t.integer "special_offer_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "media_types", force: :cascade do |t|
|
create_table "media_types", force: :cascade do |t|
|
||||||
@@ -115,6 +122,22 @@ ActiveRecord::Schema.define(version: 20150314033743) do
|
|||||||
t.string "name"
|
t.string "name"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "special_offers", force: :cascade do |t|
|
||||||
|
t.string "image_url"
|
||||||
|
t.boolean "start_page"
|
||||||
|
t.integer "section_id"
|
||||||
|
t.integer "category_id"
|
||||||
|
t.integer "sub_category_id"
|
||||||
|
t.integer "item_id"
|
||||||
|
t.boolean "thank_you_page"
|
||||||
|
t.boolean "search_result_page"
|
||||||
|
t.boolean "checkout_page"
|
||||||
|
t.date "beginning"
|
||||||
|
t.date "ending"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "sub_categories", force: :cascade do |t|
|
create_table "sub_categories", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.integer "category_id"
|
t.integer "category_id"
|
||||||
|
|||||||
Reference in New Issue
Block a user