Module: Spree::Purchase::PurchaseOrder
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/spree/purchase/purchase_order.rb
Overview
The buyer's own purchase-order reference, shared by Spree::Cart and Spree::Order. Not to be confused with Spree::PurchaseOrder, which is the merchant's procurement order to a supplier — the opposite direction (docs/plans/6.0-b2b-customer-po-numbers.md).
A corporate buyer reconciles the order, the invoice and the payment against this number years later, so it is a plain indexed column rather than metadata, and it carries onto the order at completion. The optional document is the PO itself — the signed paperwork the number refers to.
Constant Summary collapse
- MAX_PO_DOCUMENT_SIZE =
A scanned or exported purchase order, not an archive. Bounded because the download action reads the whole blob into memory to serve it.
10.megabytes
- PO_DOCUMENT_CONTENT_TYPES =
What a purchase order plausibly arrives as: an export from the buyer's procurement system (often a spreadsheet or CSV), a scan, or a photo of one.
%w[ application/pdf image/jpeg image/png image/heic image/webp application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document application/vnd.ms-excel application/vnd.openxmlformats-officedocument.spreadsheetml.sheet application/vnd.oasis.opendocument.spreadsheet text/csv ].freeze
Instance Method Summary collapse
-
#copy_po_document_from!(source) ⇒ void
Attaches the purchase order document of
sourceto this persisted record. -
#po_number_required? ⇒ Boolean
Whether the buyer's own procurement process demands a PO reference on this purchase.
Instance Method Details
#copy_po_document_from!(source) ⇒ void
This method returns an undefined value.
Attaches the purchase order document of source to this persisted
record. The same blob is attached to both rather than uploaded twice,
and the source keeps its copy, so a transaction that rolls back leaves
the buyer's upload where they left it.
On a persisted, unchanged record attach saves at once and answers
nil instead of raising when the save is refused. Unchecked, the record
would silently have no paperwork, so the refusal is raised instead.
82 83 84 85 86 87 88 89 |
# File 'app/models/concerns/spree/purchase/purchase_order.rb', line 82 def copy_po_document_from!(source) return unless source.po_document.attached? return if po_document.attach(source.po_document.blob) # A callback can refuse the save without saying why. errors.add(:po_document, :invalid) if errors.empty? raise ActiveRecord::RecordInvalid, self end |
#po_number_required? ⇒ Boolean
Whether the buyer's own procurement process demands a PO reference on this purchase. Read through the resolved company, so a buyer who has not yet said which node they are buying for is asked only once their membership is unambiguous.
66 67 68 |
# File 'app/models/concerns/spree/purchase/purchase_order.rb', line 66 def po_number_required? resolved_company&.po_number_required? || false end |