Skip to content

Commit

Permalink
Merge pull request #521 from crossroads/master
Browse files Browse the repository at this point in the history
#JuneRelease2
  • Loading branch information
namrataukirde authored Jul 2, 2018
2 parents ef21991 + f1acc41 commit 6f1e578
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 16 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ gem 'oj', '2.10.2' # 2.10.3 causes a 'too deeply nested' error
gem 'oj_mimic_json'
gem 'redis'
gem 'redis-rails', '~> 5.0.2'
gem 'sprockets', '~>3.7.2'
gem 'rollbar'
gem 'apipie-rails' , git: "https://github.com/Apipie/apipie-rails.git", branch: 'master'
gem "go_go_van_api", git: "[email protected]:crossroads/go_go_van_api.git", branch: 'master'
Expand Down
7 changes: 4 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ GEM
codeclimate-test-reporter (1.0.8)
simplecov (<= 0.13)
coderay (1.1.1)
concurrent-ruby (1.0.4)
concurrent-ruby (1.0.5)
connection_pool (2.2.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
Expand Down Expand Up @@ -234,7 +234,7 @@ GEM
method_source (~> 0.8.1)
slop (~> 3.4)
puma (3.0.2)
rack (1.6.9)
rack (1.6.10)
rack-cors (0.4.0)
rack-protection (2.0.1)
rack
Expand Down Expand Up @@ -359,7 +359,7 @@ GEM
spring (1.6.4)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
sprockets (3.7.1)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.0)
Expand Down Expand Up @@ -463,6 +463,7 @@ DEPENDENCIES
sinatra
spring
spring-commands-rspec
sprockets (~> 3.7.2)
state_machine
timecop
traco
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def stockit_serializer

def update_offer_state(offer)
offer.items.reload
if [:reviewed, :scheduled].include?(offer.state_name) && offer.items.all?{|i| i.state_name == :rejected}
if [:reviewed, :scheduled].include?(offer.state_name) && offer.items.all?{ |i| i.state_name == :rejected }
offer.re_review!
end
end
Expand Down
17 changes: 10 additions & 7 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Order < ActiveRecord::Base
belongs_to :process_completed_by, class_name: 'User'
belongs_to :dispatch_started_by, class_name: 'User'
belongs_to :closed_by, class_name: 'User'
belongs_to :submitted_by, class_name: 'User'
belongs_to :stockit_local_order, -> { joins("inner join orders on orders.detail_id = stockit_local_orders.id and orders.detail_type = 'LocalOrder'") }, foreign_key: 'detail_id'

has_many :packages
Expand Down Expand Up @@ -115,20 +116,22 @@ def set_initial_state
end

before_transition on: :submit do |order|
order.submitted_at = Time.now
order.submitted_by = User.current_user
order.add_to_stockit
end

before_transition on: :start_processing do |order|
if order.submitted?
order.processed_at = Time.now
order.processed_by_id = User.current_user.id
order.processed_by = User.current_user
end
end

before_transition on: :redesignate_cancelled_order do |order|
if order.cancelled?
order.processed_at = Time.now
order.processed_by_id = User.current_user.id
order.processed_by = User.current_user
order.nullify_columns(:process_completed_at, :process_completed_by_id, :cancelled_at,
:cancelled_by_id, :dispatch_started_by_id, :dispatch_started_at)
end
Expand All @@ -137,20 +140,20 @@ def set_initial_state
before_transition on: :start_dispatching do |order|
if order.awaiting_dispatch?
order.dispatch_started_at = Time.now
order.dispatch_started_by_id = User.current_user.id
order.dispatch_started_by = User.current_user
end
end

before_transition on: :finish_processing do |order|
if order.processing?
order.process_completed_at = Time.now
order.process_completed_by_id = User.current_user.id
order.process_completed_by = User.current_user
end
end

before_transition on: :cancel do |order|
order.cancelled_at = Time.now
order.cancelled_by_id = User.current_user.id
order.cancelled_by = User.current_user
order.orders_packages.each do |orders_package|
orders_package.cancel
end
Expand All @@ -159,7 +162,7 @@ def set_initial_state
before_transition on: :close do |order|
if order.dispatching?
order.closed_at = Time.now
order.closed_by_id = User.current_user.id
order.closed_by = User.current_user
end
end

Expand All @@ -172,7 +175,7 @@ def set_initial_state
before_transition on: :reopen do |order|
if order.closed?
order.dispatch_started_at = Time.now
order.dispatch_started_by_id = User.current_user.id
order.dispatch_started_by = User.current_user
order.nullify_columns(:closed_at, :closed_by_id)
end
end
Expand Down
8 changes: 7 additions & 1 deletion app/serializers/api/v1/order_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class OrderSerializer < ApplicationSerializer
:country_name, :state, :purpose_description, :created_by_id, :item_ids,
:gc_organisation_id, :processed_at, :processed_by_id, :cancelled_at, :cancelled_by_id,
:process_completed_at, :process_completed_by_id, :closed_at, :closed_by_id, :dispatch_started_at,
:dispatch_started_by_id
:dispatch_started_by_id, :submitted_at, :submitted_by_id

has_one :created_by, serializer: UserProfileSerializer, root: :user
has_one :stockit_contact, serializer: StockitContactSerializer, root: :contact
Expand All @@ -18,6 +18,12 @@ class OrderSerializer < ApplicationSerializer
has_many :cart_packages, serializer: BrowsePackageSerializer, root: :packages
has_many :orders_packages, serializer: OrdersPackageSerializer
has_many :orders_purposes, serializer: OrdersPurposeSerializer
has_one :closed_by, serializer: UserSerializer
has_one :processed_by, serializer: UserSerializer
has_one :cancelled_by, serializer: UserSerializer
has_one :process_completed_by, serializer: UserSerializer
has_one :dispatch_started_by, serializer: UserSerializer
has_one :submitted_by, serializer: UserSerializer

def include_packages?
@options[:include_packages]
Expand Down
11 changes: 10 additions & 1 deletion app/serializers/api/v1/order_transport_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ module Api::V1
class OrderTransportSerializer < ApplicationSerializer
embed :ids, include: true
attributes :id, :order_id, :scheduled_at, :timeslot, :gogovan_transport_id,
:transport_type, :need_english, :need_cart, :need_carry, :designation_id
:transport_type, :need_english, :need_cart, :need_carry, :designation_id,
:need_over_6ft, :remove_net, :need_over_six_ft

has_one :contact, serializer: ContactSerializer
has_one :gogovan_order, serializer: GogovanOrderSerializer

def need_over_six_ft
object.need_over_6ft
end

def need_over_six_ft__sql
"need_over_6ft"
end

def designation_id
object.order_id
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api::V1
class OrganisationWithoutOrderSerializer < ApplicationSerializer
embed :ids, include: true

attributes :id, :name_en, :name_zh_tw, :description_en, :description_zh_tw, :registration,
:website, :organisation_type_id, :district_id, :country_id, :created_at,
:updated_at
end
end
2 changes: 1 addition & 1 deletion app/serializers/api/v1/organisations_user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class OrganisationsUserSerializer < ActiveModel::Serializer
embed :ids, include: true
attributes :id, :user_id, :organisation_id, :position
has_one :user, serializer: UserSerializer
# has_one :organisation, serializer: OrganisationSerializer
has_one :organisation, serializer: OrganisationWithoutOrderSerializer
end
end
2 changes: 1 addition & 1 deletion config/initializers/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
GGV_POLL_JOB_WAIT_TIME = 60.seconds
GGV_POLL_JOB_WAIT_TIME_FOR_ONLINE_DONOR = 30.seconds
SYSTEM_USER_MOBILE = "+85264522773"
GOODCITY_NUMBER = "+85258088700"
GOODCITY_NUMBER = "+85222729348"
TWILIO_QUEUE_WAIT_TIME = 30
STOCKIT_PREFIX = "X"
APP_NAME_AND_LOGIN_PERMISSION_MAPPING = {
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20180620045905_add_submitted_by_id_to_orders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSubmittedByIdToOrders < ActiveRecord::Migration
def change
add_column :orders, :submitted_by_id, :integer
end
end
5 changes: 5 additions & 0 deletions db/migrate/20180620045951_add_submitted_at_to_orders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSubmittedAtToOrders < ActiveRecord::Migration
def change
add_column :orders, :submitted_at, :datetime
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180612100305) do
ActiveRecord::Schema.define(version: 20180620045951) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -279,6 +279,8 @@
t.integer "closed_by_id"
t.datetime "dispatch_started_at"
t.integer "dispatch_started_by_id"
t.integer "submitted_by_id"
t.datetime "submitted_at"
end

add_index "orders", ["code"], name: "orders_code_idx", using: :gin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'rails_helper'

describe Api::V1::OrganisationWithoutOrderSerializer do
let(:organisation_without_order) { build(:organisation) }
let(:serializer) { Api::V1::OrganisationWithoutOrderSerializer.new(organisation_without_order) }
let(:json) { JSON.parse( serializer.to_json ) }

it "creates JSON" do
expect(json['organisation_without_order']['id']).to eql(organisation_without_order.id)
expect(json['organisation_without_order']['name_en']).to eql(organisation_without_order.name_en)
expect(json['organisation_without_order']['name_zh_tw']).to eql(organisation_without_order.name_zh_tw)
expect(json['organisation_without_order']['description_en']).to eql(organisation_without_order.description_en)
expect(json['organisation_without_order']['description_zh_tw']).to eql(organisation_without_order.description_zh_tw)
expect(json['organisation_without_order']['registration']).to eql(organisation_without_order.registration)
expect(json['organisation_without_order']['organisation_type_id']).to eql(organisation_without_order.organisation_type_id)
expect(json['organisation_without_order']['district_id']).to eql(organisation_without_order.district_id)
expect(json['organisation_without_order']['country_id']).to eql(organisation_without_order.country_id)
end

it "translates JSON" do
I18n.locale = 'zh-tw'
expect(json['organisation_without_order']['name_zh_tw']).to eql(organisation_without_order.name_zh_tw)
expect(json['organisation_without_order']['description_zh_tw']).to eql(organisation_without_order.description_zh_tw)
end
end

0 comments on commit 6f1e578

Please sign in to comment.