This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@search= ShippingItem.joins(:shipment => {:shipment_booking => {:dest_place => :address}}). | |
departed. | |
merge(Shipment.with_check_price_done). | |
merge(Shipment.eta_in_prev_months 12). | |
where(:unit_check_price.gt => 0). | |
select('MAX(shipment_bookings.eta) AS latest_eta, shipping_items.item_variant_id AS latest_iv_id, addresses.country AS latest_country'). | |
group('shipping_items.item_variant_id, addresses.country'). | |
search(params[:search]) | |
@subquery = @search.relation.to_sql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#routes | |
scope :path => 'shipping_reports', :controller => 'ShippingReports', :as => 'shipping_reports' do | |
get 'index' | |
end | |
#test | |
class ShippingReportsControllerTest < ActionController::TestCase | |
test "routing" do | |
assert_routing '/shipping_reports/index', { :controller => "ShippingReports", :action => "index" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
has_many :own_use_contents, :dependent => :destroy, :inverse_of => :own_use_package do | |
def total_quantity | |
loaded? ? to_a.sum(&:quantity) : sum(:quantity) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shipment < ActiveRecord::Base | |
has_many :shipping_items | |
end | |
class ShippingItem < ActiveRecord::Base | |
belongs_to :shipment | |
has_many :container_allocations | |
end | |
class ContainerAllocation < ActiveRecord::Base | |
belongs_to shipping_item | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReturnedItem < AR:Base | |
belongs_to :sold_item | |
delegate :unit_price, :to => :sold_item | |
has_one :item_variant, :through => :sold_item | |
delegate :full_name, :sku, :packaging, :uom_string, :to => :item_variant | |
end | |
#item_variant is another AR model | |
## | |
#My problem is | |
ReturnedItem.new(:sold_item => an_saved_sold_item).full_name => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert_template(:partial => 'shared/_item_variant_table_title') | |
#ArgumentError: assertion message must be String or Proc: | |
#<expecting partial <"shared/_item_variant_table_title"> but action rendered | |
# <["shared/_item_variant_table_title", | |
# "_item_variant_table_title", | |
# "shared/_flash_div", | |
# "_flash_div"]>>(<Test::Unit::Assertions::AssertionMessage>) | |
assert_template(:partial => 'shared/_item_variant_table_title', :count => 1) | |
#ArgumentError: assertion message must be String or Proc: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyModel < ActiveRecord::Base | |
serialize :preferences, Hash | |
PREFS_KEYS = [:hostname, :has_retail] | |
PREFS_KEYS.each do |key| | |
define_method(key) do | |
preferences[key] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update_deliver_partially | |
@purchase_order = PurchaseOrder.find(params[:id], :include => {:purchased_items => {:item_variant => :item_family}}) | |
# authorize! :update | |
@purchase_order.attributes = params[:purchase_order] | |
@stock_receipt = @purchase_order.stock_receipts.to_a.find{|sr| sr.new_record?} | |
#logger.debug @stock_receipt.inspect | |
# @purchased_items.each {|pi| p "in controller #{pi.wh_alloc_hash.inspect}"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shipment | |
has_many :shipping_items, :inverse_of => :shipment, :dependent => :destroy do | |
def linked_po_ids | |
joins(:purchased_item => :purchase_order).select('DISTINCT purchase_orders.id AS po_id').map{|si| si.po_id} | |
def linked_pos | |
? #how to return the purchase orders (objects) ? | |
end | |
end | |
def linked_pos |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def any_missing_specs | |
if item_variants.loaded? | |
item_variants.any?{|si| si.m3 == 0 || si.weight == 0} | |
else | |
item_variants.where({:m3 => 0 } | {:weight => 0}).size != 0 #metawhere | |
end | |
end |