Reputation: 27507
I'm building an ecommerce store and I'm at the "Returns/Exchanges" part. However, I'm having trouble conceptualizing how to implement a Return
s model/table in a relational database. So far I have these models:
User
(has_many :orders)
Order
(has_many :line_items, belongs_to :user)
LineItem
(belongs_to :order, belongs_to :variant)
Variant
(has_many :line_items)
Pretty generic. Let's say that the user placed an order with 2 line items:
LineItem 1: {quantity: 1, variant_id: 1}
LineItem 2: {quantity: 3, variant_id: 2}
Lets say the user wanted to return only 2 units of LineItem 2. Well then in the future they can still return 1 unit of LineItem 2 since there were 3 in total (quantity: 3
)... Well what kind of relationship would that be?
Does anyone have any experience implementing a Return
model? I would love some insight. Let me know if you need any more info.
Upvotes: 0
Views: 87
Reputation: 26264
I don't think it has to have that many features or edge cases. Probably the client will spend more money for you to make it handle every case than they will lose by a clerk just fudging the numbers to make the customer happy for the rare occasion one of these edge cases occur.
I would add return_date
and return_qty
to the line_item
table. Then, if someone returns 2/3 items, set return_qty = 2
and return_date = Time.now
. If they do return the 3rd item, increment return_qty
and overwrite return_date
. You will lose historical return dates but that just seems so rare and likely worthless information. You might not even need it.
Upvotes: 1