app/models/unidom/order/order_item.rb in unidom-order-0.3 vs app/models/unidom/order/order_item.rb in unidom-order-1.0
- old
+ new
@@ -20,20 +20,20 @@
scope :order_is, ->(order) { where order_id: (order.respond_to?(:id) ? order.id : order) }
scope :ordered_is, ->(ordered) { where ordered: ordered }
scope :placed_by, ->(placer) { where placer: placer }
- def self.order!(order, ordered, unit_price, quantity = 1, placer = order.placer)
- item = order.items.ordered_is(ordered).placed_by(placer).valid_at.alive.first
+ def self.order!(ordered, of: nil, by: of.placer, unit_price: 0, quantity: 1)
+ item = of.items.ordered_is(ordered).placed_by(by).valid_at.alive.first
if item.present?
item.quantity += quantity
item.unit_price = unit_price
item.purchase_amount = item.unit_price*item.quantity
item.subtotal_amount = item.purchase_amount+item.adjustments.valid_at.alive.sum(:amount).to_f
item.save!
else
- ordinal = 1+order.items.valid_at.alive.maximum(:ordinal).to_i
- order.items.create! ordered: ordered, placer: placer, ordinal: ordinal, quantity: quantity, unit_price: unit_price, purchase_amount: unit_price*quantity, subtotal_amount: unit_price*quantity, opened_at: Time.now
+ ordinal = 1+of.items.valid_at.alive.maximum(:ordinal).to_i
+ of.items.create! ordered: ordered, placer: by, ordinal: ordinal, quantity: quantity, unit_price: unit_price, purchase_amount: unit_price*quantity, subtotal_amount: unit_price*quantity, opened_at: Time.now
end
end
end