Class: Order

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/order.rb

Instance Method Summary collapse

Instance Method Details

#cancel!Object

go back to edit mode, but return inventiry and zero shipped



56
57
58
59
60
# File 'app/models/order.rb', line 56

def cancel!
  self.shipped_on = nil
  self.basket.cancel_order!
  self.save
end

#generate_order_numberObject

many a european goverment requires buisnesses to have running order/transaction numbers. this is what we use, but it can easily be changed by redifining this method format RYYYYRUNIN R, 4 digit year and a running number



20
21
22
23
24
25
26
27
# File 'app/models/order.rb', line 20

def generate_order_number
  if last = Order.first # last, but default order is reversed
    num = last.number[5..9].to_i + 1
  else
    num = 30000
  end
  self.number = "R#{Time.now.year}#{num}"
end

#pay_nowObject



48
49
50
# File 'app/models/order.rb', line 48

def pay_now
  self.paid_on = Date.today
end

#pos_checkout(email) ⇒ Object

quick checkout, ie ship (hand over) and pay (externally)



63
64
65
66
67
68
69
70
71
# File 'app/models/order.rb', line 63

def pos_checkout email
  self.ordered_on    = Date.today unless self.ordered_on
  self.paid_on    = Date.today unless self.paid_on
  self.shipped_on = Date.today unless self.shipped_on
  self.shipment_price = 0 unless self.shipment_price
  self.shipment_tax   = 0 unless self.shipment_tax
  self.email = email
  self.basket.deduct!
end

#ship_nowObject



51
52
53
# File 'app/models/order.rb', line 51

def ship_now
  self.shipped_on = Date.today
end

#shipment_type=(typ) ⇒ Object



73
74
75
76
77
78
79
# File 'app/models/order.rb', line 73

def shipment_type= typ
  write_attribute(:shipment_type, typ)
  calc = OfficeClerk::ShippingMethod.all[typ.to_sym]
  cost = calc.price_for(self.basket)
  self.shipment_price = cost
  self.shipment_tax = OfficeClerk.config("defaults.tax").to_f rescue 0
end

#taxesObject

return a hash of rate => amount , because products may have different taxes, the items in an order may have a collection of tax rates.



41
42
43
44
45
46
# File 'app/models/order.rb', line 41

def taxes
  cart = basket.taxes
  #relies on basket creating a default value of 0
  cart[self.shipment_tax] += shipment_tax_value if self.shipment_tax and self.shipment_tax != 0
  cart
end

#total_priceObject



29
30
31
# File 'app/models/order.rb', line 29

def total_price
  basket.total_price + shipment_price.round(2)
end

#total_taxObject

total tax is for when the rates don’t matter, usually to cutomers. only on bills or invoices do we need the detailed list you get from the taxes function



35
36
37
# File 'app/models/order.rb', line 35

def total_tax
  basket.total_tax + shipment_tax_value
end