Skip to content

Commit

Permalink
Merge pull request #830 from crossroads/master
Browse files Browse the repository at this point in the history
#September2019Release2
  • Loading branch information
namrataukirde authored Oct 3, 2019
2 parents bccc341 + 76ecb50 commit e262338
Show file tree
Hide file tree
Showing 23 changed files with 193 additions and 81 deletions.
10 changes: 3 additions & 7 deletions app/controllers/api/v1/companies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ class CompaniesController < Api::V1::ApiController
def_param_group :company do
param :company, Hash, required: true do
param :name, String, desc: "name of the company"
param :crm_id, Integer, desc: "CRM Id"
param :crm_id, Integer, desc: "CRM Id", allow_nil: true
param :created_by_id, Integer, desc: "Id of user who created company record"
end
end

def create
if @company.save
render json: @company, serializer: serializer, status: 201
else
render json: { errors: @company.errors.full_messages.map { |message| { message: message } } }, status: 422
end
save_and_render_object_with_errors(@company)
end

def index
Expand All @@ -40,7 +36,7 @@ def update
if @company.update_attributes(company_params)
render json: @company, serializer: serializer
else
render_errors
render_error(@company.errors.full_messages.join('. '))
end
end

Expand Down
28 changes: 27 additions & 1 deletion app/controllers/api/v1/deliveries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def destroy
param :mobile, String
end
def confirm_delivery
return unless validate_schedule

@delivery = Delivery.find_by(id: params["delivery"]["id"])
@delivery.delete_old_associations
@delivery.gogovan_order = GogovanOrder.book_order(current_user,
Expand Down Expand Up @@ -134,7 +136,7 @@ def delete_existing_delivery
offer_id = params[:delivery][:offer_id]
Delivery.where(offer_id: offer_id).each do |delivery|
authorize!(:destroy, delivery)
delivery.destroy
delivery.destroy
end
end

Expand All @@ -147,6 +149,30 @@ def get_delivery_details
address_attributes: address_attributes])
end

def scheduled_date
scheduled_at = get_delivery_details.dig(:schedule_attributes, :scheduled_at)
return nil unless scheduled_at.present?
begin
Date.parse(scheduled_at)
rescue ArgumentError
nil
end
end

def validate_schedule
if scheduled_date.blank?
render_error(I18n.t('schedule.bad_date'))
return false
end

if Holiday.is_holiday?(scheduled_date)
render_error(I18n.t('schedule.holiday_conflict', date: scheduled_date));
return false
end

true
end

def address_attributes
[:address_type, :district_id, :street, :flat, :building]
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/inventory_numbers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create

api :PUT, "/v1/inventory_numbers", "Delete inventory_number"
def remove_number
InventoryNumber.find_by(code: params[:code]).destroy
InventoryNumber.find_by(code: params[:code]).try(:destroy)
render json: {}
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/packages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def search_stockit_items
with_inventory_no: params['withInventoryNumber'] == 'true') if params['searchText'].present?
params_for_filter = ['state', 'location'].each_with_object({}){|k, h| h[k] = params[k] if params[k].present?}
records = records.filter(params_for_filter)
records = records.order('id desc').offset(page - 1).limit(per_page)
records = records.order('packages.id desc').offset(page - 1).limit(per_page)
packages = ActiveModel::ArraySerializer.new(records,
each_serializer: stock_serializer,
root: "items",
Expand Down Expand Up @@ -270,7 +270,7 @@ def remove_stockit_prefix(stockit_inventory_number)
def package_params
get_package_type_id_value
set_favourite_image if @package && !@package.new_record?
attributes = [:quantity, :length, :width, :height, :notes, :item_id,
attributes = [:quantity, :length, :width, :height, :weight, :pieces, :notes, :item_id,
:received_at, :rejected_at, :package_type_id, :state_event,
:inventory_number, :designation_name, :donor_condition_id, :grade,
:location_id, :box_id, :pallet_id, :stockit_id,
Expand Down
14 changes: 8 additions & 6 deletions app/jobs/stockit_update_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ def perform(package_id)

# if Stockit can't find the item, it will create a new one and return the stockit_id
# We need to update the stockit_id of the GoodCity package in this case.
stockit_id = response['id']
package.update_column(:stockit_id, stockit_id) unless stockit_id.blank?
if response
stockit_id = response['id']
package.update_column(:stockit_id, stockit_id) unless stockit_id.blank?

if response && (errors = response["errors"] || response[:errors])
log_text = "Inventory: #{package.inventory_number} Package: #{package_id}"
errors.each { |attribute, error| log_text += " #{attribute}: #{error}" }
logger.error log_text
if (errors = response["errors"] || response[:errors])
log_text = "Inventory: #{package.inventory_number} Package: #{package_id}"
errors.each { |attribute, error| log_text += " #{attribute}: #{error}" }
logger.error log_text
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/appointment_slot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def self.for_date(date)
sl.quota.positive?
} unless slots.empty?

return [] if Holiday.is_holiday(date)
return [] if Holiday.is_holiday?(date)

# Generate slots based on preset if no special slot have been specified for that date
AppointmentSlotPreset
Expand Down
2 changes: 1 addition & 1 deletion app/models/holiday.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Holiday < ActiveRecord::Base
scope :within_days, ->(days) {
between_times(Time.zone.now.beginning_of_day, Time.zone.now.end_of_day + days) }

def self.is_holiday(date)
def self.is_holiday?(date)
Holiday.where(" date(holiday AT TIME ZONE 'HKT') = ?", date.to_date).count > 0
end

Expand Down
1 change: 1 addition & 0 deletions app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Package < ActiveRecord::Base
validates :package_type_id, :quantity, presence: true
validates :quantity, numericality: { greater_than_or_equal_to: 0 }
validates :received_quantity, numericality: { greater_than: 0 }
validates :weight, :pieces, numericality: { allow_blank: true, greater_than: 0 }
validates :width, :height, :length, numericality: { allow_blank: true, greater_than_or_equal_to: 0 }

scope :donor_packages, ->(donor_id) { joins(item: [:offer]).where(offers: { created_by_id: donor_id }) }
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/api/v1/package_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PackageSerializer < ApplicationSerializer
has_many :packages_locations, serializer: PackagesLocationSerializer
has_many :orders_packages, serializer: OrdersPackageSerializer

attributes :id, :quantity, :length, :width, :height, :notes,
attributes :id, :quantity, :length, :width, :height, :weight, :pieces, :notes,
:item_id, :state, :received_at, :rejected_at, :inventory_number,
:created_at, :updated_at, :package_type_id, :designation_id, :sent_on,
:offer_id, :designation_name, :grade, :donor_condition_id, :received_quantity,
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/api/v1/package_type_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Api::V1
class PackageTypeSerializer < ApplicationSerializer
embed :ids, include: true
attributes :id, :name, :code, :other_child_packages,
:default_child_packages, :other_terms, :visible_in_selects, :allow_requests
:default_child_packages, :other_terms, :visible_in_selects, :allow_requests, :allow_pieces

has_one :location, serializer: LocationSerializer

Expand Down
2 changes: 1 addition & 1 deletion app/serializers/api/v1/stockit_item_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class StockitItemSerializer < ApplicationSerializer
has_many :images, serializer: StockitImageSerializer
has_many :orders_packages, serializer: OrdersPackageSerializer

attributes :id, :quantity, :length, :width, :height, :notes,
attributes :id, :quantity, :length, :width, :height, :weight, :pieces, :notes,
:inventory_number, :created_at, :updated_at, :item_id, :is_set, :grade,
:designation_name, :designation_id, :sent_on, :code_id, :image_id,
:donor_condition_id, :set_item_id, :has_box_pallet, :case_number,
Expand Down
2 changes: 2 additions & 0 deletions app/services/stockit/item_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def item_params
description: package.notes,
location_id: package.stockit_location_id,
id: package.stockit_id,
pieces: package.pieces,
# designation_id: package.singleton_package? ? package.stockit_order_id : nil,
# designated_on: package.singleton_package? ? package.stockit_designated_on : nil
designation_id: package.stockit_order_id,
Expand All @@ -131,6 +132,7 @@ def package_params
length: package.length,
width: package.width,
height: package.height,
weight: package.weight,
description: package.notes
}
end
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ en:
notification:
new_offer: New offer submitted by %{name}
new_order: "New order from %{organisation_name_en}: %{contact_name}"
schedule:
bad_date: The selected date is either missing or invalid, please try again.
holiday_conflict: Crossroads will be closed on the %{date} due to a public holiday. Please select a different date.
offer:
thank_message: Thank you for your offer, our team will start reviewing it
soon. The reviewer will message you if they have questions about any of
Expand Down
3 changes: 3 additions & 0 deletions config/locales/zh-tw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ zh-tw:
notification:
new_offer: "%{name} 的新捐獻。"
new_order: "New order from %{organisation_name_zh_tw}: %{contact_name}"
schedule:
bad_date: The selected date is either missing or invalid, please try again.
holiday_conflict: Crossroads will be closed on the %{date} due to a public holiday. Please select a different date.
offer:
thank_message: 感謝您的捐獻,我們的團隊很快就會開始審查。假如審查員有任何關於捐獻物資的疑問,他們會以訊息向您查詢。由於儲存空間有限,社區的需要亦經常改變,我們可能無法接收部分物資。為此,我們深感遺憾,並先就此道歉。當審查完成時,您就能立刻安排已接受的物資的運輸。假如您有任何疑問,請隨時回覆此信息。
ggv_cancel_message: GoGoVan已取消預約於 %{time} 的貨車,請重新安排運輸。
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddWeightAndPiecesToPackages < ActiveRecord::Migration
def change
add_column :packages, :weight, :integer
add_column :packages, :pieces, :integer
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAllowPiecesToPackageTypes < ActiveRecord::Migration
def change
add_column :package_types, :allow_pieces, :boolean, default: false
end
end
Loading

0 comments on commit e262338

Please sign in to comment.