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
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
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 ⇒ void
- #total_open ⇒ void
- #total_receipted ⇒ void
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
Methods included from Models::AfterCommittable
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
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_quantity ⇒ ActiveRecord::Relation<ShipmentItem>
A relation of ShipmentItems that are with receipted quantity. Active Record Scope
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
100 101 102 |
# File 'app/models/shipment_item.rb', line 100 def all_items_receipted? total_receipted >= ea_quantity end |
#promised_delivery_date ⇒ Object
Alias for Purchase_order_shipment#promised_delivery_date
46 |
# File 'app/models/shipment_item.rb', line 46 delegate :promised_delivery_date, to: :purchase_order_shipment |
#purchase_order ⇒ PurchaseOrder?
41 |
# File 'app/models/shipment_item.rb', line 41 belongs_to :purchase_order |
#purchase_order_item ⇒ PurchaseOrderItem?
39 |
# File 'app/models/shipment_item.rb', line 39 belongs_to :purchase_order_item |
#purchase_order_shipment ⇒ PurchaseOrderShipment?
37 |
# File 'app/models/shipment_item.rb', line 37 belongs_to :purchase_order_shipment |
#shipment_receipt_items ⇒ ActiveRecord::Relation<ShipmentReceiptItem>
44 |
# File 'app/models/shipment_item.rb', line 44 has_many :shipment_receipt_items |
#some_items_receipted? ⇒ Boolean
105 106 107 |
# File 'app/models/shipment_item.rb', line 105 def some_items_receipted? total_receipted.positive? end |
#total_cost ⇒ void
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_open ⇒ void
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_receipted ⇒ void
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 |