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 :enum 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
Constants included
from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
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
config
#after_commit
#publish_event
Instance Attribute Details
#actual_shipping_cost ⇒ Object
63
64
|
# File 'app/models/purchase_order_shipment.rb', line 63
validates :weight, :width, :length, :height, :actual_shipping_cost,
numericality: { greater_than: 0.0, if: :is_drop_ship_goods_delivery }
|
#currency ⇒ Object
66
|
# File 'app/models/purchase_order_shipment.rb', line 66
validates :currency, presence: true
|
#drop_ship_carrier ⇒ Object
validates_associated :shipment_items, :on => :create
Validations:
-
Presence
({ if: :is_drop_ship_goods_delivery })
62
|
# File 'app/models/purchase_order_shipment.rb', line 62
validates :drop_ship_carrier, presence: { if: :is_drop_ship_goods_delivery }
|
#height ⇒ Object
63
64
|
# File 'app/models/purchase_order_shipment.rb', line 63
validates :weight, :width, :length, :height, :actual_shipping_cost,
numericality: { greater_than: 0.0, if: :is_drop_ship_goods_delivery }
|
#length ⇒ Object
63
64
|
# File 'app/models/purchase_order_shipment.rb', line 63
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.
59
60
61
|
# File 'app/models/purchase_order_shipment.rb', line 59
def linked_pos
@linked_pos
end
|
#require_drop_ship_po_package_info ⇒ Object
Returns the value of attribute require_drop_ship_po_package_info.
59
60
61
|
# File 'app/models/purchase_order_shipment.rb', line 59
def require_drop_ship_po_package_info
@require_drop_ship_po_package_info
end
|
#tracking_number ⇒ Object
65
|
# File 'app/models/purchase_order_shipment.rb', line 65
validates :tracking_number, presence: { if: :is_drop_ship_goods_delivery }
|
#weight ⇒ Object
63
64
|
# File 'app/models/purchase_order_shipment.rb', line 63
validates :weight, :width, :length, :height, :actual_shipping_cost,
numericality: { greater_than: 0.0, if: :is_drop_ship_goods_delivery }
|
#width ⇒ Object
63
64
|
# File 'app/models/purchase_order_shipment.rb', line 63
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
57
|
# File 'app/models/purchase_order_shipment.rb', line 57
scope :open_shipments, -> { where(state: %w[preparing shipped partially_receipted]) }
|
Instance Method Details
#all_items_receipted? ⇒ Boolean
126
127
128
|
# File 'app/models/purchase_order_shipment.rb', line 126
def all_items_receipted?
shipment_items.all?(&:fully_receipted?)
end
|
47
|
# File 'app/models/purchase_order_shipment.rb', line 47
belongs_to :carrier, class_name: 'Supplier', optional: true
|
#currency_symbol ⇒ Object
179
180
181
|
# File 'app/models/purchase_order_shipment.rb', line 179
def currency_symbol
Money::Currency.new(currency).symbol
end
|
#drop_ship_delivery ⇒ Object
196
197
198
|
# File 'app/models/purchase_order_shipment.rb', line 196
def drop_ship_delivery
purchase_orders.first.drop_ship_delivery
end
|
#enter_shipment_items(params) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'app/models/purchase_order_shipment.rb', line 142
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
122
123
124
|
# File 'app/models/purchase_order_shipment.rb', line 122
def events_for_select
[["#{human_state_name.titleize} (Current)", '']] + possible_events_for_select
end
|
#fully_landed_costed? ⇒ Boolean
134
135
136
|
# File 'app/models/purchase_order_shipment.rb', line 134
def fully_landed_costed?
shipment_receipts.all? { |sr| sr.landed_cost.present? }
end
|
#is_drop_ship_goods_delivery ⇒ Object
188
189
190
191
192
193
194
|
# File 'app/models/purchase_order_shipment.rb', line 188
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
114
115
116
|
# File 'app/models/purchase_order_shipment.rb', line 114
def possible_events
state_transitions.map(&:event).sort
end
|
#possible_events_for_select ⇒ Object
118
119
120
|
# File 'app/models/purchase_order_shipment.rb', line 118
def possible_events_for_select
possible_events.map { |evt| [evt.to_s.titleize, evt] }
end
|
#purchase_order_items ⇒ ActiveRecord::Relation<PurchaseOrderItem>
54
|
# File 'app/models/purchase_order_shipment.rb', line 54
has_many :purchase_order_items, through: :shipment_items
|
#purchase_orders ⇒ ActiveRecord::Relation<PurchaseOrder>
53
|
# File 'app/models/purchase_order_shipment.rb', line 53
has_many :purchase_orders, through: :shipment_items
|
#set_estimated_landed_cost ⇒ Object
166
167
168
169
170
171
172
|
# File 'app/models/purchase_order_shipment.rb', line 166
def set_estimated_landed_cost
supplier = Supplier.find(purchase_orders.map(&:supplier_id).uniq.first)
return if supplier.estimated_landed_cost_ptg.blank?
estimated_landed_cost_calc = shipment_items.sum(&:total_cost) * (supplier.estimated_landed_cost_ptg / 100)
update(estimated_landed_cost: estimated_landed_cost_calc)
end
|
#shipment_items ⇒ ActiveRecord::Relation<ShipmentItem>
49
|
# File 'app/models/purchase_order_shipment.rb', line 49
has_many :shipment_items, dependent: :destroy
|
#shipment_items_grouped_by_po ⇒ Object
183
184
185
186
|
# File 'app/models/purchase_order_shipment.rb', line 183
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>
50
51
52
|
# File 'app/models/purchase_order_shipment.rb', line 50
has_many :shipment_items_with_receipted_quantity, lambda {
with_receipted_quantity
}, class_name: 'ShipmentItem'
|
#shipment_receipts ⇒ ActiveRecord::Relation<ShipmentReceipt>
55
|
# File 'app/models/purchase_order_shipment.rb', line 55
has_many :shipment_receipts
|
#some_items_receipted? ⇒ Boolean
130
131
132
|
# File 'app/models/purchase_order_shipment.rb', line 130
def some_items_receipted?
shipment_items.any? { |si| si.partially_receipted? or si.fully_receipted? }
end
|
#to_s ⇒ Object
138
139
140
|
# File 'app/models/purchase_order_shipment.rb', line 138
def to_s
"PO Shipment #{carrier.try(:full_name)} #{date_shipped} "
end
|
#update_states ⇒ Object
174
175
176
177
|
# File 'app/models/purchase_order_shipment.rb', line 174
def update_states
shipment_items.each(&:receipt_items)
receipt_items
end
|