Class: RightnowOms::Order

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

Constant Summary collapse

REQUIRED_ATTRS =
%W(
  province city district neighborhood room
  receiver payment_mode order_items user_id
  required_arrival_time
)
OPTIONAL_ATTRS =
%W(
  street remarks vbrk mobile tel
)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_with_items(order) ⇒ Object



54
55
56
57
58
59
# File 'app/models/rightnow_oms/order.rb', line 54

def create_with_items(order)
  o = new_with_items(order)
  o.save

  o
end

.new_with_items(order) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/rightnow_oms/order.rb', line 41

def new_with_items(order)
  items = order.delete(:order_items)

  Order.new(order) do |o|
    items.each do |i|
      children = i.delete(:children)

      oi = o.order_items.build(i.merge(order: o))
      children.each { |c| oi.children.build(c.merge(order: o)) } if children
    end
  end
end

Instance Method Details

#delivery_addressObject



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

def delivery_address
  "#{province}#{city}#{district}#{street}#{neighborhood}#{room}"
end

#order_noObject



31
32
33
34
# File 'app/models/rightnow_oms/order.rb', line 31

def order_no
  @generator ||= OrderNoGenerator.new(self)
  @generator.generate
end