Class: PurchaseOrderShipment
Overview
== Schema Information
Table name: purchase_order_shipments
Database name: primary
id :integer not null, primary key
actual_shipping_cost :decimal(8, 2)
bill_of_lading :string(255)
container_number :string(255)
container_type :integer default("carton"), not null
currency :string(255)
date_shipped :date
drop_ship_carrier :string(255)
estimated_landed_cost :decimal(10, 2)
height :float
landed_cost :decimal(10, 2)
length :float
notes :text
promised_delivery_date :date
state :string(255)
tracking_number :string(255)
weight :float
width :float
created_at :datetime
updated_at :datetime
carrier_id :integer
creator_id :integer
updater_id :integer
Indexes
index_purchase_order_shipments_on_carrier_id (carrier_id)
Foreign Keys
fk_rails_... (carrier_id => parties.id)
Constant Summary
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
#creator, #updater
Class Method Summary
collapse
Instance Method Summary
collapse
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
#publish_event
Instance Attribute Details
#actual_shipping_cost ⇒ Object
60
61
|
# File 'app/models/purchase_order_shipment.rb', line 60
validates :weight, :width, :length, :height, :actual_shipping_cost,
numericality: { greater_than: 0.0, if: :is_drop_ship_goods_delivery }
|
#currency ⇒ Object
63
|
# File 'app/models/purchase_order_shipment.rb', line 63
validates :currency, presence: true
|
#drop_ship_carrier ⇒ Object
validates_associated :shipment_items, :on => :create
Validations:
-
Presence
({ if: :is_drop_ship_goods_delivery })
59
|
# File 'app/models/purchase_order_shipment.rb', line 59
validates :drop_ship_carrier, presence: { if: :is_drop_ship_goods_delivery }
|
#height ⇒ Object
60
61
|
# File 'app/models/purchase_order_shipment.rb', line 60
validates :weight, :width, :length, :height, :actual_shipping_cost,
numericality: { greater_than: 0.0, if: :is_drop_ship_goods_delivery }
|
#length ⇒ Object
60
61
|
# File 'app/models/purchase_order_shipment.rb', line 60
validates :weight, :width, :length, :height, :actual_shipping_cost,
numericality: { greater_than: 0.0, if: :is_drop_ship_goods_delivery }
|
#linked_pos ⇒ Object
Returns the value of attribute linked_pos.
56
57
58
|
# File 'app/models/purchase_order_shipment.rb', line 56
def linked_pos
@linked_pos
end
|
#require_drop_ship_po_package_info ⇒ Object
Returns the value of attribute require_drop_ship_po_package_info.
56
57
58
|
# File 'app/models/purchase_order_shipment.rb', line 56
def require_drop_ship_po_package_info
@require_drop_ship_po_package_info
end
|
#tracking_number ⇒ Object
62
|
# File 'app/models/purchase_order_shipment.rb', line 62
validates :tracking_number, presence: { if: :is_drop_ship_goods_delivery }
|
#weight ⇒ Object
60
61
|
# File 'app/models/purchase_order_shipment.rb', line 60
validates :weight, :width, :length, :height, :actual_shipping_cost,
numericality: { greater_than: 0.0, if: :is_drop_ship_goods_delivery }
|
#width ⇒ Object
60
61
|
# File 'app/models/purchase_order_shipment.rb', line 60
validates :weight, :width, :length, :height, :actual_shipping_cost,
numericality: { greater_than: 0.0, if: :is_drop_ship_goods_delivery }
|
Class Method Details
A relation of PurchaseOrderShipments that are open shipments. Active Record Scope
54
|
# File 'app/models/purchase_order_shipment.rb', line 54
scope :open_shipments, -> { where(state: %w(preparing shipped partially_receipted)) }
|
Instance Method Details
#all_items_receipted? ⇒ Boolean
123
124
125
|
# File 'app/models/purchase_order_shipment.rb', line 123
def all_items_receipted?
shipment_items.all?(&:fully_receipted?)
end
|
44
|
# File 'app/models/purchase_order_shipment.rb', line 44
belongs_to :carrier, class_name: 'Supplier', optional: true
|
#currency_symbol ⇒ Object
176
177
178
|
# File 'app/models/purchase_order_shipment.rb', line 176
def currency_symbol
Money::Currency.new(currency).symbol
end
|
#drop_ship_delivery ⇒ Object
193
194
195
|
# File 'app/models/purchase_order_shipment.rb', line 193
def drop_ship_delivery
purchase_orders.first.drop_ship_delivery
end
|
#enter_shipment_items(params) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'app/models/purchase_order_shipment.rb', line 139
def enter_shipment_items(params)
PurchaseOrderShipment.transaction do
params.each do |id, attrs|
next if attrs['qty_shipped'].blank?
poi = PurchaseOrderItem.find(id)
qty_shipped = attrs['qty_shipped'].to_i
next unless !poi.nil? && qty_shipped.positive?
uom_to_ea_qty = poi.unit_quantity / poi.quantity
shipment_items.build(purchase_order: poi.purchase_order,
purchase_order_item: poi,
quantity: qty_shipped,
uom: poi.uom,
ea_quantity: uom_to_ea_qty * qty_shipped)
end
end
end
|
#events_for_select ⇒ Object
119
120
121
|
# File 'app/models/purchase_order_shipment.rb', line 119
def events_for_select
[["#{human_state_name.titleize} (Current)", '']] + possible_events_for_select
end
|
#fully_landed_costed? ⇒ Boolean
131
132
133
|
# File 'app/models/purchase_order_shipment.rb', line 131
def fully_landed_costed?
shipment_receipts.all? { |sr| sr.landed_cost.present? }
end
|
#is_drop_ship_goods_delivery ⇒ Object
185
186
187
188
189
190
191
|
# File 'app/models/purchase_order_shipment.rb', line 185
def is_drop_ship_goods_delivery
require_drop_ship_po_package_info or (purchase_orders.present? and purchase_orders.all? do |po|
po.drop_ship_delivery.present?
end and shipment_items.present? and shipment_items.all? do |si|
si.purchase_order_item.item.is_goods?
end)
end
|
#possible_events ⇒ Object
111
112
113
|
# File 'app/models/purchase_order_shipment.rb', line 111
def possible_events
state_transitions.map(&:event).sort
end
|
#possible_events_for_select ⇒ Object
115
116
117
|
# File 'app/models/purchase_order_shipment.rb', line 115
def possible_events_for_select
possible_events.map { |evt| [evt.to_s.titleize, evt] }
end
|
#purchase_order_items ⇒ ActiveRecord::Relation<PurchaseOrderItem>
51
|
# File 'app/models/purchase_order_shipment.rb', line 51
has_many :purchase_order_items, through: :shipment_items
|
#purchase_orders ⇒ ActiveRecord::Relation<PurchaseOrder>
50
|
# File 'app/models/purchase_order_shipment.rb', line 50
has_many :purchase_orders, through: :shipment_items
|
#set_estimated_landed_cost ⇒ Object
163
164
165
166
167
168
169
|
# File 'app/models/purchase_order_shipment.rb', line 163
def set_estimated_landed_cost
supplier = Supplier.find(self.purchase_orders.map(&:supplier_id).uniq.first)
if supplier.estimated_landed_cost_ptg.present?
estimated_landed_cost_calc = self.shipment_items.map{|si| si.total_cost }.sum * (supplier.estimated_landed_cost_ptg / 100)
self.update(estimated_landed_cost: estimated_landed_cost_calc)
end
end
|
#shipment_items ⇒ ActiveRecord::Relation<ShipmentItem>
46
|
# File 'app/models/purchase_order_shipment.rb', line 46
has_many :shipment_items, dependent: :destroy
|
#shipment_items_grouped_by_po ⇒ Object
180
181
182
183
|
# File 'app/models/purchase_order_shipment.rb', line 180
def shipment_items_grouped_by_po
shipment_items.with_receipted_quantity.includes(:shipment_receipt_items,
{ purchase_order: :order }).order_by_po_and_sku.group_by(&:purchase_order)
end
|
#shipment_items_with_receipted_quantity ⇒ ActiveRecord::Relation<ShipmentItem>
47
48
49
|
# File 'app/models/purchase_order_shipment.rb', line 47
has_many :shipment_items_with_receipted_quantity, lambda {
with_receipted_quantity
}, class_name: 'ShipmentItem'
|
#shipment_receipts ⇒ ActiveRecord::Relation<ShipmentReceipt>
52
|
# File 'app/models/purchase_order_shipment.rb', line 52
has_many :shipment_receipts
|
#some_items_receipted? ⇒ Boolean
127
128
129
|
# File 'app/models/purchase_order_shipment.rb', line 127
def some_items_receipted?
shipment_items.any? { |si| si.partially_receipted? or si.fully_receipted? }
end
|
#to_s ⇒ Object
135
136
137
|
# File 'app/models/purchase_order_shipment.rb', line 135
def to_s
"PO Shipment #{carrier.try(:full_name)} #{date_shipped} "
end
|
#update_states ⇒ Object
171
172
173
174
|
# File 'app/models/purchase_order_shipment.rb', line 171
def update_states
shipment_items.each(&:receipt_items)
receipt_items
end
|