0001-lingo-send-reminder-notification-only-if-first-notif.patch
combo/apps/lingo/models.py | ||
---|---|---|
245 | 245 |
Notification.forget(user, notification_reminder_id) |
246 | 246 |
else: |
247 | 247 |
# invoice can be paid |
248 |
if pay_limit_date > now + remind_delta: |
|
249 |
message = _('Invoice %s to pay') % invoice['label'] |
|
250 |
else: |
|
251 |
message = _('Reminder: invoice %s to pay') % invoice['label'] |
|
252 |
notification_id = notification_reminder_id |
|
253 | 248 |
if not Notification.objects.find(user, notification_id).exists(): |
254 | 249 |
self.notify_remote_invoice_by_email(user, invoice) |
255 |
Notification.notify(user, |
|
256 |
summary=message, |
|
257 |
id=notification_id, |
|
258 |
url=items_page_url, |
|
259 |
end_timestamp=pay_limit_date) |
|
260 |
return notification_id |
|
250 |
notification = Notification.notify(user, |
|
251 |
summary=_('Invoice %s to pay') % invoice['label'], |
|
252 |
id=notification_id, |
|
253 |
url=items_page_url, |
|
254 |
end_timestamp=pay_limit_date) |
|
255 |
if pay_limit_date <= now + remind_delta and notification.acked: |
|
256 |
Notification.notify(user, |
|
257 |
summary=_('Reminder: invoice %s to pay') % invoice['label'], |
|
258 |
id=notification_reminder_id, |
|
259 |
url=items_page_url, |
|
260 |
end_timestamp=pay_limit_date) |
|
261 |
return [notification_id, notification_reminder_id] |
|
262 |
return [notification_id] |
|
263 |
return [] |
|
261 | 264 | |
262 | 265 |
def notify_new_remote_invoices(self): |
263 | 266 |
pending_invoices = self.get_remote_pending_invoices() |
... | ... | |
269 | 272 |
continue |
270 | 273 |
for invoice in items['invoices']: |
271 | 274 |
if Decimal(invoice['total_amount']) >= self.payment_min_amount: |
272 |
notification_ids.append(
|
|
275 |
notification_ids.extend(
|
|
273 | 276 |
self.notify_invoice(user, invoice)) |
274 | 277 |
# clear old notifications for invoice not in the source anymore |
275 | 278 |
Notification.objects.namespace(self.get_notification_namespace())\ |
tests/test_notification.py | ||
---|---|---|
360 | 360 |
for user in FAKE_PENDING_INVOICES['data']: |
361 | 361 |
for invoice in FAKE_PENDING_INVOICES['data'][user]['invoices']: |
362 | 362 |
invoice['pay_limit_date'] = new_pay_limit_date |
363 |
Notification.objects.all().ack() |
|
363 | 364 | |
364 | 365 |
# create remind notifications |
365 | 366 |
regie.notify_new_remote_invoices() |
366 | 367 |
assert Notification.objects.exclude(external_id__startswith='invoice-%s:reminder-' % regie.slug) \ |
367 |
.visible().count() == 0 |
|
368 |
.visible().new().count() == 0
|
|
368 | 369 |
assert Notification.objects.filter(external_id__startswith='invoice-%s:reminder-' % regie.slug) \ |
369 | 370 |
.visible().new().count() == 2 |
370 | 371 |
assert Notification.objects.count() == 4 |
371 | 372 | |
372 |
# url appeared on new new reminder notifications
|
|
373 |
assert len([notif for notif in Notification.objects.all() if notif.url == page.get_online_url()]) == 2
|
|
373 |
# url appeared on all notifications
|
|
374 |
assert len([notif for notif in Notification.objects.all() if notif.url == page.get_online_url()]) == 4
|
|
374 | 375 | |
375 | 376 |
# be sure the are no more reminders created |
376 | 377 |
regie.notify_new_remote_invoices() |
377 |
- |