Refactor cancelling positions and orders in the data model (#1088)

- [x] Data model
- [x] display in order view in backend
- [x] review all usages of OrderPositions.objects
- [x] review all usages of order.positions
- [x] review all other model usages
- [x] review plugins
- [x] plugins backwards-compatible API?
- [x] decide on way forward for REST API
- [x] need to cancel fees
- [x] tests
- [ ] plugins
  - [ ] gdpr
  - [ ] reports
- [x] docs
This commit is contained in:
Raphael Michel
2019-01-10 16:52:34 +01:00
committed by GitHub
parent 588955901c
commit 8abfbba9d0
41 changed files with 579 additions and 351 deletions

View File

@@ -58,6 +58,14 @@ def env():
price=Decimal("42.00"),
positionid=2,
)
OrderPosition.objects.create(
order=o,
item=t_shirt,
variation=variation,
price=Decimal("42.00"),
positionid=3,
canceled=True
)
gs = GlobalSettingsObject()
gs.settings.ecb_rates_date = date.today()
gs.settings.ecb_rates_dict = json.dumps({

View File

@@ -740,7 +740,7 @@ class OrderTestCase(BaseQuotaTestCase):
q = Question.objects.create(question='Foo', type=Question.TYPE_BOOLEAN, event=self.event)
self.item1.questions.add(q)
assert self.order.can_modify_answers
self.order.status = Order.STATUS_REFUNDED
self.order.status = Order.STATUS_CANCELED
assert not self.order.can_modify_answers
self.order.status = Order.STATUS_PAID
assert self.order.can_modify_answers
@@ -963,7 +963,7 @@ class OrderTestCase(BaseQuotaTestCase):
assert o.has_external_refund
def test_pending_order_pending_refund(self):
self.order.status = Order.STATUS_REFUNDED
self.order.status = Order.STATUS_CANCELED
self.order.save()
self.order.payments.create(
amount=Decimal('46.00'),
@@ -1023,6 +1023,14 @@ class OrderTestCase(BaseQuotaTestCase):
assert not o.has_pending_refund
assert not o.has_external_refund
def test_canceled_positions(self):
self.op1.canceled = True
self.op1.save()
assert OrderPosition.objects.count() == 1
assert OrderPosition.all.count() == 2
assert self.order.positions.count() == 1
assert self.order.all_positions.count() == 2
class ItemCategoryTest(TestCase):
"""

View File

@@ -616,6 +616,26 @@ class OrderChangeManagerTests(TestCase):
self.order.refresh_from_db()
assert self.order.positions.count() == 1
assert self.order.total == self.op2.price
self.op1.refresh_from_db()
assert self.op1.canceled
def test_cancel_with_addon(self):
self.shirt.category = self.event.categories.create(name='Add-ons', is_addon=True)
self.ticket.addons.create(addon_category=self.shirt.category)
self.ocm.add_position(self.shirt, None, Decimal('13.00'), self.op1)
self.ocm.commit()
self.order.refresh_from_db()
self.ocm = OrderChangeManager(self.order, None)
assert self.order.positions.count() == 3
self.ocm.cancel(self.op1)
self.ocm.commit()
self.order.refresh_from_db()
assert self.order.positions.count() == 1
assert self.order.total == self.op2.price
self.op1.refresh_from_db()
assert self.op1.canceled
assert self.op1.addons.first().canceled
def test_free_to_paid(self):
self.order.status = Order.STATUS_PAID