Class: Skr::PurchaseOrder
- Defined in:
- lib/skr/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
65 66 67 |
# File 'lib/skr/purchase_order.rb', line 65 def ( msg ) self.mark_transmitted if self.can_mark_transmitted? end |
#as_pdf(opts = {}) ⇒ Object
86 87 88 89 |
# File 'lib/skr/purchase_order.rb', line 86 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
69 70 71 |
# File 'lib/skr/purchase_order.rb', line 69 def set_maybe_completed! self.mark_received! unless received? or self.lines.incomplete.any? end |
#set_message_fields(msg) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/skr/purchase_order.rb', line 77 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
73 74 75 |
# File 'lib/skr/purchase_order.rb', line 73 def to_shipping_address Address.copy_from(self,'ship_') end |
#total ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/skr/purchase_order.rb', line 91 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 |