class Skr::SalesOrder
invoice = Invoice.new
( sales_order: so ) invoice.lines.from_sales_order! invoice.save
Public Class Methods
new(attributes = {})
click to toggle source
Calls superclass method
# File lib/skr/models/sales_order.rb, line 115 def initialize(attributes = {}) super # order date must be set, otherwise things like terms that are set from it fail self.order_date ||= Date.today end
sales_history( ndays )
click to toggle source
@return [Array of Array[day_ago,date, order_count,line_count,total]]
# File lib/skr/models/sales_order.rb, line 90 def self.sales_history( ndays ) qry = "select * from #{Skr.config.table_prefix}so_dailly_sales_history where days_ago<#{ndays.to_i}" connection.execute(qry).values end
Private Instance Methods
cancel_all_lines()
click to toggle source
when the order is canceled, inform the lines
# File lib/skr/models/sales_order.rb, line 152 def cancel_all_lines self.pick_tickets.each{ |pt| pt.cancel! } self.lines.each{ | soline | soline.cancel! } true end
check_if_location_changed()
click to toggle source
When the location changes, lines need to have their sku_loc modified to point to the new location as well
# File lib/skr/models/sales_order.rb, line 124 def check_if_location_changed if location_id_changed? self.lines.each{ |l| l.location = self.location } end end
ensure_location_changes_are_valid()
click to toggle source
The location can only be updated if all the line's skus are setup in the new location
# File lib/skr/models/sales_order.rb, line 131 def ensure_location_changes_are_valid return true unless changes['location_id'] errors.add(:location, 'cannot be changed unless sales order is open') unless open? current = self.sku_ids setup = location.sku_locs.where( sku_id: current ).pluck('sku_id') missing = current - setup if missing.any? codes = Sku.where( id: missing ).pluck('code') errors.add(:location, "#{location.code} does not have skus #{codes.join(',')}") end end
on_invoice(inv)
click to toggle source
# File lib/skr/models/sales_order.rb, line 158 def on_invoice(inv) self.mark_complete! if may_mark_complete? and lines.unshipped.none? end
set_defaults()
click to toggle source
# File lib/skr/models/sales_order.rb, line 162 def set_defaults if customer self.form ||= customer.get_form('invoice') self.billing_address = customer.billing_address if self.billing_address.blank? self.shipping_address = customer.shipping_address if self.shipping_address.blank? end end
setup_new_pt(pt)
click to toggle source
Initialize a new {PickTicket} by copying the pickable lines to it
# File lib/skr/models/sales_order.rb, line 144 def setup_new_pt(pt) self.lines.each do | so_line | pt.lines << so_line.pt_lines.build if so_line.pickable_qty > 0 end true end