X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d527b63f5320d32e5c598354fd60ebc00d88d7bb..30e79991759b2d512e397a61d0e3a3e8ca40ae17:/src/club/payu/models.py?ds=sidebyside diff --git a/src/club/payu/models.py b/src/club/payu/models.py index 1a49dd707..5764f8842 100644 --- a/src/club/payu/models.py +++ b/src/club/payu/models.py @@ -7,6 +7,7 @@ from urllib.request import HTTPError from django.contrib.sites.models import Site from django.db import models from django.urls import reverse +from django.utils.timezone import now from django.utils.translation import ugettext_lazy as _ from . import POSS @@ -36,6 +37,7 @@ class Order(models.Model): ('CANCELED', _('Canceled')), ('REJECTED', _('Rejected')), ]) + completed_at = models.DateTimeField(null=True, blank=True) class Meta: abstract = True @@ -124,6 +126,8 @@ class Order(models.Model): token.save() # else? + if 'orderId' not in response: + raise ValueError("Expecting dict with `orderId` key, got: %s" % response) self.order_id = response['orderId'] self.save() @@ -148,5 +152,7 @@ class Notification(models.Model): status = self.get_status() if self.order.status not in (status, 'COMPLETED'): self.order.status = status + if status == 'COMPLETED': + self.order.completed_at = now() self.order.save() self.order.status_updated()