Class: Skr::PurchaseOrder
- Defined in:
- lib/skr/models/purchase_order.rb
Overview
A Purchase Order (often abbreviated as PO) is a record of a request to purchase a product from a Vendor. It contains one or more Sku, the quantity desired for each and the price offered for them.
A Purchase Order progresses through set stages:
* It starts of as "saved"
This state indicates that the PO has been saved but no further action has been under-taken.
* Once it has been sent to the Vendor, it transitions to Sent.
* On reciept of a confirmation from the vendor it becomes Confirmed At this point the PO may be
considered a binding agreement with the {Vendor}.
* When the ordered SKUs are received, the PO will be marked as either Partial or Complete.
* A {PoReceipt} is then created from the Purchase Order.
Instance Method Summary collapse
- #after_message_transmitted(msg) ⇒ Object
- #as_pdf(opts = {}) ⇒ Object
- #set_maybe_completed! ⇒ Object
- #set_message_fields(msg) ⇒ Object
- #to_shipping_address ⇒ Object
- #total ⇒ Object
Instance Method Details
#after_message_transmitted(msg) ⇒ Object
74 75 76 |
# File 'lib/skr/models/purchase_order.rb', line 74 def ( msg ) self.mark_transmitted if self.can_mark_transmitted? end |
#as_pdf(opts = {}) ⇒ Object
95 96 97 98 |
# File 'lib/skr/models/purchase_order.rb', line 95 def as_pdf( opts={} ) defaults = { :purchase_order => self, :include_received=>false } Latex::Runner.new( 'purchase_order', defaults.merge( opts ) ).pdf( "PurchaseOrder_#{self.visible_id}.pdf" ) end |
#set_maybe_completed! ⇒ Object
78 79 80 |
# File 'lib/skr/models/purchase_order.rb', line 78 def set_maybe_completed! self.mark_received! unless received? or self.lines.incomplete.any? end |
#set_message_fields(msg) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/skr/models/purchase_order.rb', line 86 def ( msg ) msg.recipient = self.vendor.payments_address.email_with_name if msg.recipient.blank? msg.subject = "Purchase Order # #{self.visible_id}" attach = msg..build attach.set_type_to_pdf pdf = self.as_pdf attach.file = pdf end |
#to_shipping_address ⇒ Object
82 83 84 |
# File 'lib/skr/models/purchase_order.rb', line 82 def to_shipping_address Address.copy_from(self,'ship_') end |
#total ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/skr/models/purchase_order.rb', line 100 def total if total = self.read_attribute('total') BigDecimal.new(total) elsif self.association(:lines).loaded? self.lines.inject(0){|sum,line| sum + line.total } else BigDecimal.new( self.lines.sum('price*qty') ) end end |