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

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 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:



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

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:



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

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)


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

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:



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

delegate :promised_delivery_date, to: :purchase_order_shipment

#purchase_orderPurchaseOrder



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

belongs_to :purchase_order

#purchase_order_itemPurchaseOrderItem



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

belongs_to :purchase_order_item

#purchase_order_shipmentPurchaseOrderShipment



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

belongs_to :purchase_order_shipment

#shipment_receipt_itemsActiveRecord::Relation<ShipmentReceiptItem>

Returns:

See Also:



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

has_many :shipment_receipt_items

#some_items_receipted?Boolean

Returns:

  • (Boolean)


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

def some_items_receipted?
  total_receipted.positive?
end

#total_costObject



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

def total_cost
  self.quantity * self.purchase_order_item.unit_cost
end

#total_openObject



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

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

#total_receiptedObject



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

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