Class: ShipmentReceiptItem
Overview
== Schema Information
Table name: shipment_receipt_items
Database name: primary
id :integer not null, primary key
currency :string(255)
effective_date :date
exclude_lead_time :boolean
lead_time :integer
quantity :integer
state :string(255)
total_cost :decimal(8, 2)
unit_cost :decimal(8, 2)
created_at :datetime
updated_at :datetime
creator_id :integer
last_gl_transaction_id :integer
purchase_order_id :integer
purchase_order_item_id :integer
shipment_item_id :integer
shipment_receipt_id :integer
updater_id :integer
Indexes
idx_po_id_sr_id (purchase_order_id,shipment_receipt_id)
index_shipment_receipt_items_on_state (state)
poi_id_state (purchase_order_item_id,state)
shipment_item_id_state (shipment_item_id,state)
sr_id_po_id (shipment_receipt_id,purchase_order_id)
Constant Summary
Models::Auditable::ALWAYS_IGNORED
Constants included
from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
#creator, #updater
Delegated Instance Attributes
collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
config
#after_commit
#publish_event
Instance Attribute Details
#quantity ⇒ Object
54
|
# File 'app/models/shipment_receipt_item.rb', line 54
validates :quantity, numericality: { greater_than: 0 }
|
#validate_serial_numbers ⇒ Object
Returns the value of attribute validate_serial_numbers.
60
61
62
|
# File 'app/models/shipment_receipt_item.rb', line 60
def validate_serial_numbers
@validate_serial_numbers
end
|
Class Method Details
A relation of ShipmentReceiptItems that are receipted. Active Record Scope
62
|
# File 'app/models/shipment_receipt_item.rb', line 62
scope :receipted, -> { where(state: "receipted") }
|
Instance Method Details
#actual_landed_cost ⇒ Object
86
87
88
|
# File 'app/models/shipment_receipt_item.rb', line 86
def actual_landed_cost
actual_landed_costs.first
end
|
#actual_landed_costs ⇒ ActiveRecord::Relation<LandedCost>
45
|
# File 'app/models/shipment_receipt_item.rb', line 45
has_many :actual_landed_costs, -> { actual }, class_name: 'LandedCost'
|
#build_serial_numbers ⇒ Object
127
128
129
130
131
132
133
|
# File 'app/models/shipment_receipt_item.rb', line 127
def build_serial_numbers
if purchase_order_item.line_item&.serial_numbers&.any?
purchase_order_item.line_item.serial_numbers.each { |sn| serial_numbers.build(qty: sn.qty, number: sn.number) }
else
serial_numbers.build(qty: qty_without_serial_number)
end
end
|
#currency_symbol ⇒ Object
78
79
80
|
# File 'app/models/shipment_receipt_item.rb', line 78
def currency_symbol
Money::Currency.new(currency).symbol
end
|
#estimated_landed_cost ⇒ Object
82
83
84
|
# File 'app/models/shipment_receipt_item.rb', line 82
def estimated_landed_cost
estimated_landed_costs.first
end
|
#estimated_landed_costs ⇒ ActiveRecord::Relation<LandedCost>
44
|
# File 'app/models/shipment_receipt_item.rb', line 44
has_many :estimated_landed_costs, -> { estimated }, class_name: 'LandedCost'
|
#has_stock? ⇒ Boolean
90
91
92
93
94
|
# File 'app/models/shipment_receipt_item.rb', line 90
def has_stock?
ile = item_ledger_entries.first
store_item = StoreItem.where(store_id: ile.store_id, item_id: ile.item_id, location: ile.location).first
!store_item.nil? and (store_item.qty_available >= quantity)
end
|
#item ⇒ Object
Alias for Purchase_order_item#item
58
|
# File 'app/models/shipment_receipt_item.rb', line 58
delegate :item, to: :purchase_order_item
|
#item_ledger_entries ⇒ ActiveRecord::Relation<ItemLedgerEntry>
42
|
# File 'app/models/shipment_receipt_item.rb', line 42
has_many :item_ledger_entries
|
#landed_costs ⇒ ActiveRecord::Relation<LandedCost>
43
|
# File 'app/models/shipment_receipt_item.rb', line 43
has_many :landed_costs
|
#link_serial_numbers_to_item_ledger_entry ⇒ Object
118
119
120
121
|
# File 'app/models/shipment_receipt_item.rb', line 118
def link_serial_numbers_to_item_ledger_entry
sn_ids = serial_numbers.ids
item_ledger_entries.each { |ile| ile.update(serial_number_ids: sn_ids) } if sn_ids.present?
end
|
39
|
# File 'app/models/shipment_receipt_item.rb', line 39
belongs_to :purchase_order, optional: true
|
38
|
# File 'app/models/shipment_receipt_item.rb', line 38
belongs_to :purchase_order_item, optional: true
|
#qty_without_serial_number ⇒ Object
123
124
125
|
# File 'app/models/shipment_receipt_item.rb', line 123
def qty_without_serial_number
quantity - serial_numbers.sum(:qty)
end
|
#reverse_item_ledger(reversed_gl_transaction) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'app/models/shipment_receipt_item.rb', line 96
def reverse_item_ledger(reversed_gl_transaction)
existing_ile = item_ledger_entries.where(category: "PO_RECEIPT").first
raise "Unable to find existing item ledger entry for shipment receipt item #{id}" if existing_ile.nil?
ItemLedgerEntry.create!(category: "PO_RECEIPT_VOID",
store: existing_ile.store,
item: existing_ile.item,
gl_date: Date.current,
quantity: -quantity,
currency: existing_ile.currency,
unit_cost: existing_ile.unit_cost,
total_cost: -existing_ile.total_cost,
shipment_receipt_item: self,
location: existing_ile.location,
ledger_transaction: reversed_gl_transaction)
void!
end
|
#serial_numbers ⇒ ActiveRecord::Relation<SerialNumber>
47
|
# File 'app/models/shipment_receipt_item.rb', line 47
has_many :serial_numbers
|
40
|
# File 'app/models/shipment_receipt_item.rb', line 40
belongs_to :shipment_item, optional: true
|
37
|
# File 'app/models/shipment_receipt_item.rb', line 37
belongs_to :shipment_receipt, optional: true
|
#store_item ⇒ Object
114
115
116
|
# File 'app/models/shipment_receipt_item.rb', line 114
def store_item
StoreItem.where(store_id: purchase_order.store_id, item_id: purchase_order_item.item_id, location: shipment_receipt.location).first
end
|