# encoding:utf-8
class UpdateOrder < ActiveRecord::Base
  has_paper_trail
  self.table_name = "update_orders"
  after_create :update_order_express

  def update_order_express
    # 复制商品图片
    orders = Order.find_by_sql("select * from orders where order_id = '#{self.order_id} ' limit 1")
    # 创建商品图片
    orders.each do |order|
      if order.status=='processing'
        order.express_company=self.express_company
        order.express_order_no=self.express_order_no
        #更新物流公司code
        express = ExpressCompany.where("express_company = ?", self.express_company).first
        if !express.blank?
          order.express_code = express.express_code
        end
        order.save
        self.status=1
        self.save
      end
    end

  end
  rails_admin do
    navigation_label '仓储物流管理'
    weight -300
    #parent Order
    list do
      filters [:order_id,:express_order_no]
      # include_all_fields
      field :id
      field :order_id
      field :express_order_no
      field :express_company
      field :status
    end
    show do
      field :id
      field :order_id
      field :express_order_no
      field :express_company
      field :status
    end

    edit do
      field :id
      field :order_id
      field :express_order_no
      field :express_company
      field :status
    end
  end
end
