class Skr::PurchaseOrder
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.
Public Instance Methods
after_message_transmitted( msg )
click to toggle source
# File lib/skr/purchase_order.rb, line 65 def after_message_transmitted( msg ) self.mark_transmitted if self.can_mark_transmitted? end
as_pdf( opts={} )
click to toggle source
# 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!()
click to toggle source
# 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 )
click to toggle source
# File lib/skr/purchase_order.rb, line 77 def set_message_fields( msg ) msg.recipient = self.vendor.payments_address.email_with_name if msg.recipient.blank? msg.subject = "Purchase Order # #{self.visible_id}" attach = msg.attachments.build attach.set_type_to_pdf pdf = self.as_pdf attach.file = pdf end
to_shipping_address()
click to toggle source
# File lib/skr/purchase_order.rb, line 73 def to_shipping_address Address.copy_from(self,'ship_') end
total()
click to toggle source
# 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
Private Instance Methods
set_defaults()
click to toggle source
# File lib/skr/purchase_order.rb, line 103 def set_defaults self.location ||= Location.default self.order_date ||= Date.today self.terms ||= self.vendor.terms if self.vendor self.ship_addr = self.location.address if self.ship_addr.blank? && self.location end