Class: Spree::PurchaseOrder
- Inherits:
-
Object
- Object
- Spree::PurchaseOrder
- Includes:
- HasCustomFields, HasStatus, Metadata, NumberIdentifier, Receivable, SingleStoreResource
- Defined in:
- app/models/spree/purchase_order.rb
Overview
Goods bought from a supplier and expected at one of the merchant's own warehouses (docs/plans/6.0-inventory-operations.md).
Replaces the 5.x "external receive" — a StockTransfer with no source location — with a record that has the things a purchase actually has: a supplier, a unit cost, an expected date and a number to quote back.
Ordered units never count toward availability. Nothing here touches
count_on_hand until Spree::PurchaseOrders::Receive runs, because the
merchant only has the goods once they land.
Every status change is a workflow — Spree::PurchaseOrders::Receive, never
purchase_order.receive! — so receiving can take the quantities the
warehouse counted rather than assuming the order arrived intact.
Constant Summary
Constants included from Receivable
Receivable::CLOSED_STATUSES, Receivable::INCOMING_STATUSES, Receivable::OPEN_STATUSES
Class Method Summary collapse
- .open_by_date(column, late) ⇒ ActiveRecord::Relation
- .ransackable_scopes_skip_sanitize_args ⇒ Object
Instance Method Summary collapse
- #display_subtotal ⇒ Spree::Money
-
#editable? ⇒ Boolean
Whether the merchant may still edit the lines.
- #event_serializer_class ⇒ Object
-
#subtotal ⇒ BigDecimal
What the supplier will invoice for everything ordered.
Methods included from Metadata
#private_metadata, #private_metadata=
Methods included from Receivable
#closed?, #closed_short?, #fully_received?, #incoming?, #items_count, #open?, #over?, #quantity_expected_total, #quantity_received_total, #quantity_rejected_total, #short?, #status_after_receive
Class Method Details
.open_by_date(column, late) ⇒ ActiveRecord::Relation
75 76 77 78 79 80 |
# File 'app/models/spree/purchase_order.rb', line 75 def self.open_by_date(column, late) return all if late.nil? date = arel_table[column] late ? open.where(date.lt(Date.current)) : open.where(date.gteq(Date.current).or(date.eq(nil))) end |
.ransackable_scopes_skip_sanitize_args ⇒ Object
67 68 69 |
# File 'app/models/spree/purchase_order.rb', line 67 def self.ransackable_scopes_skip_sanitize_args %i[overdue past_cancel_by] end |
Instance Method Details
#display_subtotal ⇒ Spree::Money
91 92 93 |
# File 'app/models/spree/purchase_order.rb', line 91 def display_subtotal Spree::Money.new(subtotal, currency: currency) end |
#editable? ⇒ Boolean
Whether the merchant may still edit the lines. Once the order is placed with the supplier, what was ordered is a matter of record.
99 100 101 |
# File 'app/models/spree/purchase_order.rb', line 99 def editable? draft? end |
#event_serializer_class ⇒ Object
103 104 105 |
# File 'app/models/spree/purchase_order.rb', line 103 def event_serializer_class 'Spree::Api::V3::PurchaseOrderEventSerializer'.safe_constantize end |
#subtotal ⇒ BigDecimal
What the supplier will invoice for everything ordered.
86 87 88 |
# File 'app/models/spree/purchase_order.rb', line 86 def subtotal items.sum(&:total_cost) end |