Class: ShipmentItem
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ShipmentItem
- 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
- #purchase_order ⇒ PurchaseOrder
- #purchase_order_item ⇒ PurchaseOrderItem
- #purchase_order_shipment ⇒ PurchaseOrderShipment
Methods included from Models::Auditable
Has many collapse
Delegated Instance Attributes collapse
-
#promised_delivery_date ⇒ Object
Alias for Purchase_order_shipment#promised_delivery_date.
Class Method Summary collapse
-
.order_by_po_and_sku ⇒ ActiveRecord::Relation<ShipmentItem>
A relation of ShipmentItems that are order by po and sku.
-
.with_receipted_quantity ⇒ ActiveRecord::Relation<ShipmentItem>
A relation of ShipmentItems that are with receipted quantity.
Instance Method Summary collapse
- #all_items_receipted? ⇒ Boolean
- #some_items_receipted? ⇒ Boolean
- #total_cost ⇒ Object
- #total_open ⇒ Object
- #total_receipted ⇒ Object
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
Class Method Details
.order_by_po_and_sku ⇒ ActiveRecord::Relation<ShipmentItem>
A relation of ShipmentItems that are order by po and sku. Active Record Scope
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_quantity ⇒ ActiveRecord::Relation<ShipmentItem>
A relation of ShipmentItems that are with receipted quantity. Active Record Scope
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
93 94 95 |
# File 'app/models/shipment_item.rb', line 93 def all_items_receipted? total_receipted >= ea_quantity end |
#promised_delivery_date ⇒ Object
Alias for Purchase_order_shipment#promised_delivery_date
42 |
# File 'app/models/shipment_item.rb', line 42 delegate :promised_delivery_date, to: :purchase_order_shipment |
#purchase_order ⇒ PurchaseOrder
38 |
# File 'app/models/shipment_item.rb', line 38 belongs_to :purchase_order |
#purchase_order_item ⇒ PurchaseOrderItem
37 |
# File 'app/models/shipment_item.rb', line 37 belongs_to :purchase_order_item |
#purchase_order_shipment ⇒ PurchaseOrderShipment
36 |
# File 'app/models/shipment_item.rb', line 36 belongs_to :purchase_order_shipment |
#shipment_receipt_items ⇒ ActiveRecord::Relation<ShipmentReceiptItem>
40 |
# File 'app/models/shipment_item.rb', line 40 has_many :shipment_receipt_items |
#some_items_receipted? ⇒ Boolean
97 98 99 |
# File 'app/models/shipment_item.rb', line 97 def some_items_receipted? total_receipted.positive? end |
#total_cost ⇒ Object
101 102 103 |
# File 'app/models/shipment_item.rb', line 101 def total_cost self.quantity * self.purchase_order_item.unit_cost end |
#total_open ⇒ Object
89 90 91 |
# File 'app/models/shipment_item.rb', line 89 def total_open [ea_quantity - total_receipted, 0].max end |
#total_receipted ⇒ Object
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 |