OrderDelivery.transaction do
params[:id_array].each do | id |
if order_delivery = OrderDelivery.find_by_id(id)
+ raise if order_delivery.order.retailer_id != session[:admin_user].retailer_id
order_delivery.status = params[:new_status]
order_delivery.update_ticket(params[:order_delivery_ticket_code][id])
order_delivery.save!
end
flash[:status] = "保存しました"
end
- rescue
+ rescue => e
flash[:status_e] = "保存に失敗しました"
end
end
file = params[:upload_file]
begin
if CSVUtil.valid_data_from_file?(file)
- line, update_line, result = OrderDelivery.update_by_csv(file)
+ line, update_line, result = OrderDelivery.update_by_csv(file, session[:admin_user].retailer_id)
unless result
line = line + 1
flash[:status] = "#{line}行目のデータが不正です。最初からやり直して下さい。"
+ flash[:has_error] = true
redirect_to :action => "index"
return
end
rescue => e
logger.error("order_statuses_controller#csv_upload catch error: " + e.to_s)
flash[:status] = "エラーが発生しました。最初からやり直してく下さい。"
+ flash[:has_error] = true
# flash[:error] = e.to_s
redirect_to :action => "index"
end
:page => params[:page],
:per_page => 10,
:conditions => flatten_conditions(@search_list),
- :order => "id desc"
+ :order => "order_deliveries.id desc",
+ :include => OrderDelivery::DEFAULT_INCLUDE
)
end
@search_list = []
status = params[:select] || OrderDelivery::YOYAKU_UKETSUKE
- @search_list << ["status=?", status]
+ @search_list << ["order_deliveries.status = ? ", status]
+ @search_list << ["orders.retailer_id = ? ", session[:admin_user].retailer_id]
end
end
end
def edit
+ order_delivery = OrderDelivery.find_by_order_id(params[:id])
+ raise ActiveRecord::RecordNotFound if order_delivery.nil? || order_delivery.order.retailer_id != session[:admin_user].retailer_id
if params[:recalculate]
recalculate
return
def update
get_order_delivery
#@order_delivery = OrderDelivery.find_by_order_id(params[:id])
- if @order_delivery.nil?
+ if @order_delivery.nil? || @order_delivery.order.retailer_id != session[:admin_user].retailer_id
raise ActiveRecord::RecordNotFound
end
begin
# 親と子も消す
order_delivery = OrderDelivery.find(:first, :conditions => ["id=?", params[:id]])
begin
- raise if order_delivery.nil?
+ raise if order_delivery.nil? || order_delivery.order.retailer_id != session[:admin_user].retailer_id
order_delivery.order_details.each(&:destroy)
order = order_delivery.order
order_delivery.destroy
end
def get_search_form
+ addparam = {'retailer_id' => session[:admin_user].retailer_id}
+ params[:search].merge! addparam unless params[:search].nil?
@search = SearchForm.new(params[:search])
@search, @search_list, @sex, @payment_id = Order.get_conditions(@search, params)
end
class Order < ActiveRecord::Base
acts_as_paranoid
belongs_to :customer
+ belongs_to :retailer
has_many :order_deliveries
def subtotal
unless search.shipped_at_to.blank?
search_list << ["order_deliveries.shipped_at < ?", search.shipped_at_to + 1 * 60 * 60 * 24 ]
end
+ unless search.retailer_id.blank?
+ search_list << ["orders.retailer_id = ? ", search.retailer_id]
+ end
end
search_list << ['order_deliveries.sex in (?)', sex] unless sex.empty?
search_list << ['order_deliveries.payment_id in (?)', payment_id] unless payment_id.empty?
end
class << self
- def update_by_csv(file)
+ def update_by_csv(file, retailer_id)
line = 0
update_line = 0
OrderDelivery.transaction do
CSV::Reader.parse(file) do |row|
if line != 0
record = OrderDelivery.find_by_order_id(row[0].to_i)
+ return [line-1, update_line, false] if record.order.retailer_id != retailer_id
params = get_params(Iconv.conv('UTF-8', 'cp932', row[49]), row[47], row[48])
if record
if record.update_attributes(params)
it "未指定だと新規受付を表示" do
get 'index'
- records = OrderDelivery.find(:all, :conditions => ["status=?", OrderDelivery::YOYAKU_UKETSUKE])
assigns[:order_deliveries].each do | record |
record.status.should == OrderDelivery::YOYAKU_UKETSUKE
+ record.order.retailer_id.should == 1
end
end
get 'index', :select => status
assigns[:order_deliveries].each do |record|
record.status.should == status
+ record.order.retailer_id.should == 1
end
end
assigns[:order_deliveries].each do |record|
record.id.should < prev_id if prev_id
prev_id = record.id
+ record.order.retailer_id.should == 1
end
end
end
+ describe "GET 'index'を違うショップがやった場合" do
+ before do
+ session[:admin_user] = admin_users(:admin18_retailer_id_is_another_shop)
+ end
+
+ it "should be successful" do
+ get 'index'
+ response.should be_success
+ end
+
+ it "admin/order_statuses/index を表示する" do
+ get 'index'
+ response.should render_template("admin/order_statuses/index.html.erb")
+ end
+
+ it "未指定だと新規受付を表示" do
+ get 'index'
+ assigns[:order_deliveries].each do | record |
+ record.status.should == OrderDelivery::YOYAKU_UKETSUKE
+ record.order.retailer_id.should == 2
+ end
+ end
+
+ it "選んだステータスの一覧" do
+ status = 2
+ get 'index', :select => status
+ assigns[:order_deliveries].each do |record|
+ record.status.should == status
+ record.order.retailer_id.should == 2
+ end
+ end
+
+ it "ID の降順で表示" do
+ prev_id = nil
+ get 'index'
+ assigns[:order_deliveries].each do |record|
+ record.id.should < prev_id if prev_id
+ prev_id = record.id
+ record.order.retailer_id.should == 2
+ end
+ end
+ end
+
+
describe "GET 'update'" do
it "/ にリダイレクトする" do
post 'update', :new_status => 3, :id_array => %w(1), :order_delivery_ticket_code => {"1" => "Test"}
record.status.should == 3
end
end
+
+ it "別のショップから受注のステータスは変更できない" do
+ session[:admin_user] = admin_users(:admin18_retailer_id_is_another_shop)
+ order_delivery_ticket_code = {"1" => "Test", "11" => "Test"}
+ post 'update', :new_status => 3, :id_array => %w(1 11), :order_delivery_ticket_code => order_delivery_ticket_code
+ OrderDelivery.find(1, 11).each do | record |
+ record.status.should_not == 3
+ end
+ flash[:status_e].should_not be_blank
+ end
+
+
end
describe "POST 'csv_upload'" do
csv = uploaded_file(File.dirname(__FILE__) + "/../../csv/order_status_update.csv", "text", "order_status_update.csv")
post 'csv_upload', :upload_file => csv
flash[:status].should_not be_nil
+ flash[:has_error].should be_nil
+ end
+
+ it "別のショップは自分以外へのショップへCSVアップロードはできない" do
+ session[:admin_user] = admin_users(:admin18_retailer_id_is_another_shop)
+ csv = uploaded_file(File.dirname(__FILE__) + "/../../csv/order_status_update.csv", "text", "order_status_update.csv")
+ post 'csv_upload', :upload_file => csv
+ flash[:has_error].should be_true
+ end
+
+ it "別のショップは自分のショップに対してはアップロードはできる" do
+ session[:admin_user] = admin_users(:admin18_retailer_id_is_another_shop)
+ csv = uploaded_file(File.dirname(__FILE__) + "/../../csv/order_status_update_other_shop.csv", "text", "order_status_update.csv")
+ post 'csv_upload', :upload_file => csv
+ flash[:status].should_not be_nil
+ flash[:has_error].should be_nil
end
+
+ it "マスターショップであっても別のショップへはCSVアップロードはできない" do
+ csv = uploaded_file(File.dirname(__FILE__) + "/../../csv/order_status_update_other_shop.csv", "text", "order_status_update.csv")
+ post 'csv_upload', :upload_file => csv
+ flash[:has_error].should be_true
+ end
+
+
end
end
fixtures :admin_users , :payments
fixtures :functions, :authorities, :authorities_functions
fixtures :products
+ fixtures :retailers
before do
@order = orders(:one)
it "商品コードで検索" do
code = 'NATSU0001'
- details = OrderDetail.find(:all, :conditions => ['product_code=?', code])
+ details = OrderDetail.find(:all, :conditions => ['order_details.product_code=? and orders.retailer_id = ?', code, 1], :include => {:order_delivery => :order})
+ expected = details.map(&:order_delivery).uniq.sort_by(&:id).reverse
+ post 'search', :search => {:product_code => code, :per_page => expected.size}
+ assigns[:order_deliveries].should == expected
+ end
+
+ it "電話番号(検索バグチェック用)" do
+ post 'search', :search => { :tel => "is_not_invalid_value" }
+ assigns[:order_deliveries].should == []
+ end
+
+ end
+
+ describe "POST / 検索結果表示 / 別ショップの場合" do
+ fixtures :payments
+ before do
+ session[:admin_user] = admin_users(:admin18_retailer_id_is_another_shop)
+ @order_delivery = order_deliveries :nobi_other_shop
+ end
+
+# it "条件に該当する受注一覧を表示" do
+# post 'search', :search => { :id => @order_delivery.id }
+# p assigns[:search].id
+# assigns[:order_deliveries][0].should == @order_delivery
+# end
+
+ it "顧客名" do
+ post 'search', :search => { :customer_name => @order_delivery.family_name }
+ assigns[:order_deliveries][0].should == @order_delivery
+ end
+
+ it "顧客名" do
+ post 'search', :search => { :customer_name => @order_delivery.first_name }
+ assigns[:order_deliveries][0].should == @order_delivery
+ end
+
+ it "顧客名(カナ)" do
+ post 'search', :search => { :customer_name_kana => @order_delivery.family_name_kana }
+ assigns[:order_deliveries][0].should == @order_delivery
+ end
+
+ it "顧客名(カナ)" do
+ post 'search', :search => { :customer_name_kana => @order_delivery.first_name_kana }
+ assigns[:order_deliveries][0].should == @order_delivery
+ end
+
+ it "メールアドレス" do
+ post 'search', :search => { :email => @order_delivery.email }
+ assigns[:order_deliveries][0].should == @order_delivery
+ end
+
+ it "生年月日" do
+ search = {}
+ search.merge! date_to_select(@order_delivery.birthday, 'search_birth_from')
+ search.merge! date_to_select(@order_delivery.birthday, 'search_birth_to')
+ post 'search', :search => search
+ assigns[:order_deliveries].each do | record |
+ record.birthday.should == @order_delivery.birthday
+ end
+ end
+
+ it "性別" do
+ post 'search', :sex => ['0']
+ assigns[:order_deliveries].each do | record |
+ record.sex.should == '0'
+ end
+ end
+
+ it "支払方法" do
+ post 'search', :payment_id => ['1']
+ assigns[:order_deliveries].each do | record |
+ record.payment_id.to_i.should == 1
+ end
+ end
+
+ it "登録・更新日" do
+ search = {}
+ search.merge! date_to_select(@order_delivery.updated_at, 'search_updated_at_from')
+ search.merge! date_to_select(@order_delivery.updated_at, 'search_updated_at_to')
+ post 'search', :search => search
+ assigns[:order_deliveries].each do | record |
+ record.updated_at.year.should == @order_delivery.updated_at.year
+ record.updated_at.month.should == @order_delivery.updated_at.month
+ record.updated_at.day.should == @order_delivery.updated_at.day
+ end
+ end
+
+ it "購入金額" do
+ search = { :total_from => @order_delivery.total, :total_to => @order_delivery.total }
+ post 'search', :search => search
+ assigns[:order_deliveries].each do | record |
+ record.total == @order_delivery.total
+ end
+ end
+
+# it "配送日" do
+# search = {}
+# search.merge! date_to_select(@order_delivery.deliv_date, 'search_deliv_date_from')
+# search.merge! date_to_select(@order_delivery.deliv_date, 'search_deliv_date_to')
+# post 'search', :search => search
+# assigns[:order_deliveries].each do | record |
+# record.deliv_date.year.should == @order_delivery.deliv_date.year
+# record.deliv_date.month.should == @order_delivery.deliv_date.month
+# record.deliv_date.day.should == @order_delivery.deliv_date.day
+# end
+# end
+
+ it "admin/order/list を表示する" do
+ post 'search'
+ response.should render_template("admin/orders/search.html.erb")
+ end
+
+ it "商品コードで検索" do
+ code = 'NATSU0001'
+ details = OrderDetail.find(:all, :conditions => ['order_details.product_code=? and orders.retailer_id = ?', code, 2], :include => {:order_delivery => :order})
expected = details.map(&:order_delivery).uniq.sort_by(&:id).reverse
post 'search', :search => {:product_code => code, :per_page => expected.size}
assigns[:order_deliveries].should == expected
get 'edit', :id => @order.id
assigns[:order_delivery].should == @order.order_deliveries.first
end
+
+ it "存在しないIDを指定" do
+ lambda { get :edit, :id => 10000 }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+
+ it "違うショップからアクセス" do
+ session[:admin_user] = admin_users(:admin18_retailer_id_is_another_shop)
+ lambda{ get 'edit', :id => @order.id }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+
end
describe "更新" do
# assigns[:order].total.should > -1
# assigns[:order].payment_total.should > -1
# end
+
+ it "別ユーザが編集するとエラー" do
+ session[:admin_user] = admin_users(:admin18_retailer_id_is_another_shop)
+ @order_delivery = order_deliveries(:customer_buy_one)
+ lambda { post 'update', :id => @order_delivery.order_id, :order_delivery => {:first_name => '何某'} }.should raise_error(ActiveRecord::RecordNotFound)
+ end
end
describe "「計算結果の確認」ボタン" do
assigns[:order_delivery].total.should > -1
assigns[:order_delivery].payment_total.should > -1
end
+
+ it "違うショップからは再計算できない" do
+ session[:admin_user] = admin_users(:admin18_retailer_id_is_another_shop)
+ lambda { post 'update', :id => @order_delivery.order_id, :order_delivery => {}}.should raise_error(ActiveRecord::RecordNotFound)
+ end
+
end
order_details.each do | detail |
OrderDetail.find(:first, :conditions=>["id=?",order.id]).should be_nil
end
- flash[:error].should be_blank
+ end
+
+ it "違うショップからは削除できない" do
+ session[:admin_user] = admin_users(:admin18_retailer_id_is_another_shop)
+ order = @order_delivery.order
+ order_details = @order_delivery.order_details
+ get :destroy, :id => @order_delivery.id
+ Order.find(:first, :conditions=>["id=?",order.id]).should_not be_nil
+ OrderDelivery.find(:first, :conditions=>["id=?",@order_delivery.id]).should_not be_nil
+ order_details.each do | detail |
+ OrderDetail.find(:first, :conditions=>["id=?",order.id]).should_not be_nil
+ end
end
end
end
end
- describe "POST 'destory'" do
+ describe "POST 'destroy'" do
it "親子とも消す" do
post 'destroy', :id => @order_delivery.id
Order.find_by_id(@order_delivery.order_id).should be_nil
1,38\r
1,39\r
1,40\r
+1,41\r
+1,42\r
+1,43\r
+1,44
\ No newline at end of file
<% open("#{RAILS_ROOT}/db/migrate/fixed_data/functions.yml").each_line do | fixture | %> \r
<%= fixture %>\r
<% end %>\r
+F1000:\r
+ id: 41\r
+ name: 仕入先マスタ\r
+ code: "supplier"\r
+ position: 1000\r
+F1001:\r
+ id: 42\r
+ name: 在庫管理 \r
+ code: "stock"\r
+ position: 1001\r
+F1002:\r
+ id: 43\r
+ name: 返品処理\r
+ code: "return_item"\r
+ position: 1002\r
+F1003:\r
+ id: 44\r
+ name: 環境設定\r
+ code: "setting"\r
+ position: 1003
\ No newline at end of file
status: 3
payment_id: 1
address_select: 0
+nobi_other_shop:
+ id: 3241
+ order_id: 3241
+ status: 1
+#deliv_date: 2008-04-09
+ # 発注者
+ family_name: 骨川
+ first_name: スネ夫
+ family_name_kana: ホネカワ
+ first_name_kana: スネオ
+ email: suneo@honekawa.com
+ tel01: 011
+ tel02: 2222
+ tel03: 3333
+ fax01: 044
+ fax02: 5555
+ fax03: 6666
+ zipcode01: 290
+ zipcode02: 0156
+ prefecture_id: 20
+ address_city: 住所そのいち
+ address_detail: 住所そのに
+ sex: 1
+ birthday: 2008-01-01
+#job: 1
+ message: 要望
+ # 配達先
+ deliv_family_name: 野比
+ deliv_first_name: のび太
+ deliv_family_name_kana: ノビ
+ deliv_first_name_kana: ノビタ
+ deliv_zipcode01: 330
+ deliv_zipcode02: 0800
+ deliv_tel01: 03
+ deliv_tel02: 0000
+ deliv_tel03: 0110
+ deliv_fax01: 045
+ deliv_fax02: 000
+ deliv_fax03: 9110
+ deliv_pref_id: 4
+ deliv_address_city: 配送先住所前
+ deliv_address_detail: 配送先住所後
+ discount: 7
+ deliv_fee: 20
+ charge: 400
+ use_point: 0
+ add_point: "加算ポイント"
+ subtotal: 5628
+ total: 5700
+ payment_total: 5700
+ payment_id: 1
+ delivery_trader_id: 1
+ delivery_time_id: 1
+#deliv_no: "配送伝票番号"
+ note: "SHOPメモ"
+ commit_date: 2002-12-12
+ cell01: 090
+ cell02: 2987
+ cell03: 8765
+
+# 受注集計用 多店舗
+# 発送済み 8 月購入
+<% (1..31).each do |i|
+ id = i + 3300
+%>
+other_shop_commited_august_<%= i %>:
+ id: <%= id %>
+ order_id: <%= id %>
+ subtotal: 33333
+ total: 33551
+ payment_total: 33551
+ discount: 2
+ deliv_fee: 20
+ charge: 200
+ use_point: 0
+ commit_date: 2008-09-01 00:00:00
+ status: <%= OrderDelivery::HAITATU_KANRYO %>
+<% end %>
+# 未発送 8 月購入 多店舗
+<% (1..31).each do |i|
+ id = i + 3400
+%>
+other_shop_not_commited_august_<%= i %>:
+ id: <%= id %>
+ order_id: <%= id %>
+ subtotal: 22222
+ total: 31322
+ payment_total: 31322
+ discount: 1000
+ deliv_fee: 10000
+ charge: 100
+ use_point: 0
+ status: <%= OrderDelivery::YOYAKU_UKETSUKE %>
+<% end %>
+# 発送済み 9 月購入 多店舗
+<% (1..30).each do |i|
+ id = i + 3500
+%>
+other_shop_commited_september_<%= i %>:
+ id: <%= id %>
+ order_id: <%= id %>
+ subtotal: 20000
+ total: 30000
+ payment_total: 30000
+ discount: 200
+ deliv_fee: 1200
+ charge: 9000
+ use_point: 0
+ commit_date: 2008-10-01 00:00:00
+ status: <%= OrderDelivery::HASSOU_TYUU %>
+ family_name: 田中
+ first_name: 一郎
+ family_name_kana: タナカ
+ first_name_kana: イチロウ
+ email: test@kbmj.com
+ tel01: '03'
+ tel02: '1111'
+ tel03: '2222'
+ zipcode01: '000'
+ zipcode02: '0000'
+ prefecture_id: 13
+ address_city: テスト市テスト町
+ address_detail: 1-2-3
+ sex: 2
+ birthday: 1980-01-01
+ deliv_family_name: 田中
+ deliv_first_name: 二郎
+ deliv_family_name_kana: タナカ
+ deliv_first_name_kana: ジロウ
+ deliv_tel01: '010'
+ deliv_tel02: '1111'
+ deliv_tel03: '1111'
+ deliv_zipcode01: '331'
+ deliv_zipcode02: '0812'
+ deliv_pref_id: 1
+ deliv_address_city: 千代田区神田神保町
+ deliv_address_detail: 1-2-3
+ add_point: 0
+ delivery_trader_id: 1
+ delivery_time_id: 3
+ payment_id: 1
+ address_select: 0
+<% end %>
style_category_name1: have_classcategory1
style_category_name2: classcategory1
+
+# 受注集計用 多店舗
+# 発送済み 8 月購入
+<% (1..31).each do |i|
+ id = i + 3300
+%>
+other_shop_commited_august_<%= i %>:
+ id: <%= id %>
+ order_delivery_id: <%= id %>
+ product_id: 11
+ product_name: 夏みかん(8月限定)
+ product_code: NATSU0001
+ price: 400
+ quantity: 20
+ product_style_id: 1
+<% end %>
+# 未発送 8 月購入 多店舗
+<% (1..31).each do |i|
+ id = i + 3400
+%>
+other_shop_not_commited_august_<%= i %>:
+ id: <%= id %>
+ order_delivery_id: <%= id %>
+ product_id: 11
+ product_name: 夏みかん(8月限定)
+ product_code: NATSU0001
+ price: 400
+ quantity: 20
+ product_style_id: 1
+<% end %>
+# 発送済み 9 月購入 多店舗
+<% (1..30).each do |i|
+ id = i + 3500
+%>
+other_shop_commited_september_<%= i %>:
+ id: <%= id %>
+ order_delivery_id: <%= id %>
+ product_id: 15
+ product_name: 2学期
+ product_code: NIGAKKI01
+ price: 4000
+ quantity: 3
+ product_style_id: 1
+<% end %>
guest_male:
id: 5
customer_id: 12
+#昨日の配送
+<% (11..20).each do |idx| %>
+last_day_delivery_<%= idx - 10 %>:
+ id: <%= idx %>
+ customer_id: 13
+<% end %>
history_00:
id: 6
not_customer_ritou:
id: 3240
code: '2009111312103240'
- received_at: 2009-11-13 03:10:44
\ No newline at end of file
+ received_at: 2009-11-13 03:10:44
+
+other_shop:
+ id: 3241
+ code: '2010040100000001'
+ received_at: 2010-04-01 03:10:44
+ retailer_id: 2
+
+# 受注集計用 多店舗
+# 発送済み 8 月購入
+<% (1..31).each do |i|
+ id = i + 3300
+%>
+other_shop_commited_august_<%= i %>:
+ id: <%= id %>
+ customer_id: 9
+ received_at: <%= "2008-08-%02d 00:00:00" % i %>
+ retailer_id: 2
+<% end %>
+# 未発送 8 月購入 多店舗
+<% (1..31).each do |i|
+ id = i + 3400
+%>
+other_shop_not_commited_august_<%= i %>:
+ id: <%= id %>
+ customer_id: 10
+ received_at: <%= "2008-08-%02d 00:00:00" % i %>
+ retailer_id: 2
+<% end %>
+# 発送済み 9 月購入 多店舗
+<% (1..30).each do |i|
+ id = i + 3500
+%>
+other_shop_commited_september_<%= i %>:
+ id: <%= id %>
+ customer_id: 9
+ received_at: <%= "2008-09-%02d 00:00:00" % i %>
+ retailer_id: 2
+<% end %>