Class: ShipmentItem

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/shipment_item.rb

Overview

== Schema Information

Table name: shipment_items
Database name: primary

id :integer not null, primary key
ea_quantity :integer
quantity :integer
state :string(255)
uom :string(255)
created_at :datetime
updated_at :datetime
creator_id :integer
purchase_order_id :integer
purchase_order_item_id :integer
purchase_order_shipment_id :integer
updater_id :integer

Indexes

idx_pos_id_po_id (purchase_order_shipment_id,purchase_order_id)
idx_pos_id_poi_id (purchase_order_shipment_id,purchase_order_item_id)
index_shipment_items_on_purchase_order_id (purchase_order_id)
index_shipment_items_on_purchase_order_item_id (purchase_order_item_id)

Foreign Keys

fk_rails_... (purchase_order_id => purchase_orders.id)
fk_rails_... (purchase_order_item_id => purchase_order_items.id)
fk_rails_... (purchase_order_shipment_id => purchase_order_shipments.id)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has many collapse

Delegated Instance Attributes collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.order_by_po_and_skuActiveRecord::Relation<ShipmentItem>

A relation of ShipmentItems that are order by po and sku. Active Record Scope

Returns:

See Also:



45
# File 'app/models/shipment_item.rb', line 45

scope :order_by_po_and_sku, -> { joins(:purchase_order_item).order('shipment_items.purchase_order_id, purchase_order_items.sku'.sql_safe) }

.with_receipted_quantityActiveRecord::Relation<ShipmentItem>

A relation of ShipmentItems that are with receipted quantity. Active Record Scope

Returns:

See Also:



46
47
48
49
50
51
# File 'app/models/shipment_item.rb', line 46

scope :with_receipted_quantity, -> {
  select_append(%{(select coalesce(sum(shipment_receipt_items.quantity),0)
                                                      from shipment_receipt_items
                                                      where shipment_receipt_items.state = 'receipted'
                                                      and shipment_receipt_items.shipment_item_id = shipment_items.id) as total_receipted_subquery}.sql_safe)
}

Instance Method Details

#all_items_receipted?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/models/shipment_item.rb', line 94

def all_items_receipted?
  total_receipted >= ea_quantity
end

#promised_delivery_dateObject

Alias for Purchase_order_shipment#promised_delivery_date

Returns:

  • (Object)

    Purchase_order_shipment#promised_delivery_date

See Also:



43
# File 'app/models/shipment_item.rb', line 43

delegate :promised_delivery_date, to: :purchase_order_shipment

#purchase_orderPurchaseOrder



39
# File 'app/models/shipment_item.rb', line 39

belongs_to :purchase_order

#purchase_order_itemPurchaseOrderItem



38
# File 'app/models/shipment_item.rb', line 38

belongs_to :purchase_order_item

#purchase_order_shipmentPurchaseOrderShipment



37
# File 'app/models/shipment_item.rb', line 37

belongs_to :purchase_order_shipment

#shipment_receipt_itemsActiveRecord::Relation<ShipmentReceiptItem>

Returns:

See Also:



41
# File 'app/models/shipment_item.rb', line 41

has_many :shipment_receipt_items

#some_items_receipted?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'app/models/shipment_item.rb', line 98

def some_items_receipted?
  total_receipted.positive?
end

#total_costObject



102
103
104
# File 'app/models/shipment_item.rb', line 102

def total_cost
  quantity * purchase_order_item.unit_cost
end

#total_openObject



90
91
92
# File 'app/models/shipment_item.rb', line 90

def total_open
  [ea_quantity - total_receipted, 0].max
end

#total_receiptedObject



82
83
84
85
86
87
88
# File 'app/models/shipment_item.rb', line 82

def total_receipted
  if respond_to?(:total_receipted_subquery)
    total_receipted_subquery
  else
    shipment_receipt_items.receipted.sum(:quantity)
  end
end