Skip to content

Conversation

@TheRumle
Copy link

@TheRumle TheRumle commented Apr 14, 2024

As seen in #418, #215 and #188 we would like to be able to re-imburse items. Here is my suggestion on how one could do it. Heavily inspired by @joandrsn #215 PR.

What makes this BL tedious is that all sale information must be 'preserved' - however, if we just put a field into the Sale entity we have create a filter on all existing logic - for instance, we don't want to make people 'coffee master' by considering reimbursed coffee. Therefore, making a 'is_reimbursed' field seems like a bad idea to me. I have instead created is_reimbursed to establish when it can occur.
I decided to create the Reimbursement class, and use it to keep track of who reimburses what, and for how much. I see a couple of critical things about my approach and would like to discuss them

  1. It does not go through the existing entities, therefore no logging, admin info, etc exists for it. I need help adding this.
  2. It deletes the existing sale. I find this to be the best way to represent that the sale was an error, and did not occur. We do lose data, but it is not correct data (unless someone abuses the feature)
  3. The code is yet another place to ensure correct state representation of related entities inventory, accounts, etc. We already suffer from this - introducing more places to keep track of entity behaviour feel icky.

@TheRumle TheRumle marked this pull request as draft April 14, 2024 13:33
@TheRumle TheRumle changed the title Reimbursement of latest bought items - Issues 418, 414, 215, 188 Reimbursement of latest bought items Apr 14, 2024
@TheRumle TheRumle marked this pull request as ready for review April 14, 2024 13:41
@TheRumle TheRumle marked this pull request as draft April 14, 2024 13:41
Copy link
Contributor

@jonasKjellerup jonasKjellerup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks fine. As for your discussion points:

  1. I think you should as a minimum stick to using the MoneyTransaction entity to manage the balance updates. This should also make the balance changes visible in the admin panel. Beyond that I am not super familiar with the admin panel so I don't have much to add there.
  2. I think this is fine.
  3. I am not really sure what you are getting at here, could you elaborate a bit?

if not sale:
raise SaleNotFoundError()
product = sale.product
product.quantity = product.quantity + 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing a .save() on product after updating the quantity.
Unless, the Django ORM does it as part of saving the new reimbursement,
in which case you don't need sale.member.save() on line 21.

product = sale.product
product.quantity = product.quantity + 1

sale.member.balance = sale.member.balance + sale.price
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be done through a MoneyTransaction (possibly a new subtype ReimbursementTransaction similar to how it is done for PayTransaction) such that it is recorded in a manner consistent with other balance changes.

('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('amount', models.IntegerField()),
('member', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='stregsystem.Member')),
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='stregsystem.Product')),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is a good idea for the reimbursement to be removed when a product is deleted (however unlikely the scenario may be). It gives an incorrect view of the customers history.
SET_NULL seems more appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With that said, it is consistent with how sales are handled, so I guess it is fine.

@TheRumle TheRumle marked this pull request as ready for review May 12, 2024 08:56
Copy link
Member

@krestenlaust krestenlaust left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

billede
Without having looked at the source code, I experience the following runtime error, whenever I try to refund. I'm not sure if it's supposed to work yet

@TheRumle TheRumle marked this pull request as draft May 12, 2024 13:47
@krestenlaust krestenlaust linked an issue May 17, 2024 that may be closed by this pull request
@TheRumle TheRumle closed this by deleting the head repository Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow user to cancel latest bought item

3 participants