- since = self.schedule.expires_at
- n = now()
- if since is None or since < n:
- since = n
- new_exp = self.schedule.get_next_installment(since)
- if self.schedule.payed_at is None:
- self.schedule.payed_at = n
- if self.schedule.expires_at is None or self.schedule.expires_at < new_exp:
- self.schedule.expires_at = new_exp
- self.schedule.save()
-
- if not self.schedule.email_sent:
- self.schedule.send_email()
+ self.schedule.set_payed()
+ self.report_activity()
+
+ @property
+ def updated_at(self):
+ try:
+ return self.notification_set.all().order_by('-received_at')[0].received_at
+ except IndexError:
+ return None
+
+ def report_activity(self):
+ if self.status not in ['COMPLETED', 'CANCELED', 'REJECTED']:
+ return
+
+ if self.status != 'COMPLETED':
+ name = settings.CIVICRM_ACTIVITIES['Failed contribution']
+ elif self.is_recurring():
+ name = settings.CIVICRM_ACTIVITIES['Recurring contribution']
+ else:
+ name = settings.CIVICRM_ACTIVITIES['Contribution']
+
+ report_activity.delay(
+ self.schedule.email,
+ self.schedule.key,
+ f'payu:{self.id}',
+ name,
+ self.updated_at,
+ {
+ 'kwota': self.schedule.amount,
+ }
+ )