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
Models::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
53
|
# File 'app/models/shipment_receipt_item.rb', line 53
validates :quantity, numericality: { greater_than: 0 }
|
#validate_serial_numbers ⇒ Object
Returns the value of attribute validate_serial_numbers.
59
60
61
|
# File 'app/models/shipment_receipt_item.rb', line 59
def validate_serial_numbers
@validate_serial_numbers
end
|
Class Method Details
A relation of ShipmentReceiptItems that are receipted. Active Record Scope
61
|
# File 'app/models/shipment_receipt_item.rb', line 61
scope :receipted, -> { where(state: "receipted") }
|
Instance Method Details
#actual_landed_cost ⇒ Object
85
86
87
|
# File 'app/models/shipment_receipt_item.rb', line 85
def actual_landed_cost
actual_landed_costs.first
end
|
#actual_landed_costs ⇒ ActiveRecord::Relation<LandedCost>
44
|
# File 'app/models/shipment_receipt_item.rb', line 44
has_many :actual_landed_costs, -> { actual }, class_name: 'LandedCost'
|
#build_serial_numbers ⇒ Object
126
127
128
129
130
131
132
|
# File 'app/models/shipment_receipt_item.rb', line 126
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
77
78
79
|
# File 'app/models/shipment_receipt_item.rb', line 77
def currency_symbol
Money::Currency.new(currency).symbol
end
|
#estimated_landed_cost ⇒ Object
81
82
83
|
# File 'app/models/shipment_receipt_item.rb', line 81
def estimated_landed_cost
estimated_landed_costs.first
end
|
#estimated_landed_costs ⇒ ActiveRecord::Relation<LandedCost>
43
|
# File 'app/models/shipment_receipt_item.rb', line 43
has_many :estimated_landed_costs, -> { estimated }, class_name: 'LandedCost'
|
#has_stock? ⇒ Boolean
89
90
91
92
93
|
# File 'app/models/shipment_receipt_item.rb', line 89
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
57
|
# File 'app/models/shipment_receipt_item.rb', line 57
delegate :item, to: :purchase_order_item
|
#item_ledger_entries ⇒ ActiveRecord::Relation<ItemLedgerEntry>
41
|
# File 'app/models/shipment_receipt_item.rb', line 41
has_many :item_ledger_entries
|
#landed_costs ⇒ ActiveRecord::Relation<LandedCost>
42
|
# File 'app/models/shipment_receipt_item.rb', line 42
has_many :landed_costs
|
#link_serial_numbers_to_item_ledger_entry ⇒ Object
117
118
119
120
|
# File 'app/models/shipment_receipt_item.rb', line 117
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
|
38
|
# File 'app/models/shipment_receipt_item.rb', line 38
belongs_to :purchase_order, optional: true
|
37
|
# File 'app/models/shipment_receipt_item.rb', line 37
belongs_to :purchase_order_item, optional: true
|
#qty_without_serial_number ⇒ Object
122
123
124
|
# File 'app/models/shipment_receipt_item.rb', line 122
def qty_without_serial_number
quantity - serial_numbers.sum(:qty)
end
|
#reverse_item_ledger(reversed_gl_transaction) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'app/models/shipment_receipt_item.rb', line 95
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>
46
|
# File 'app/models/shipment_receipt_item.rb', line 46
has_many :serial_numbers
|
39
|
# File 'app/models/shipment_receipt_item.rb', line 39
belongs_to :shipment_item, optional: true
|
36
|
# File 'app/models/shipment_receipt_item.rb', line 36
belongs_to :shipment_receipt, optional: true
|
#store_item ⇒ Object
113
114
115
|
# File 'app/models/shipment_receipt_item.rb', line 113
def store_item
StoreItem.where(store_id: purchase_order.store_id, item_id: purchase_order_item.item_id, location: shipment_receipt.location).first
end
|