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

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



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

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:



49
50
51
52
53
54
# File 'app/models/shipment_item.rb', line 49

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)


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

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:



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

delegate :promised_delivery_date, to: :purchase_order_shipment

#purchase_orderPurchaseOrder?

Returns:



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

belongs_to :purchase_order

#purchase_order_itemPurchaseOrderItem?

Returns:



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

belongs_to :purchase_order_item

#purchase_order_shipmentPurchaseOrderShipment?

Returns:



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

belongs_to :purchase_order_shipment

#shipment_receipt_itemsActiveRecord::Relation<ShipmentReceiptItem>

Returns:



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

has_many :shipment_receipt_items

#some_items_receipted?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'app/models/shipment_item.rb', line 105

def some_items_receipted?
  total_receipted.positive?
end

#total_costvoid

This method returns an undefined value.



110
111
112
# File 'app/models/shipment_item.rb', line 110

def total_cost
  quantity * purchase_order_item.unit_cost
end

#total_openvoid

This method returns an undefined value.



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

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

#total_receiptedvoid

This method returns an undefined value.



86
87
88
89
90
91
92
# File 'app/models/shipment_item.rb', line 86

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