Exemplo n.º 1
0
 def test_pretty_date_week(self):
     self.assertEqual(
         pretty_date(getdate('2018-08-29'), getdate('2018-08-19')),
         'in a week'
     )
Exemplo n.º 2
0
def send_reminders(posting_date=today()):
    settings = frappe.get_single("Gym Settings")
    if not settings.sms_before_expiry and not settings.sms_on_expiry:
        return None
    days_before_expiry = compose(
        tuple, partial(map, lambda x: add_days(posting_date, cint(x))),
        compact)(settings.days_before_expiry.split("\n"))
    subscriptions = frappe.db.sql(
        """
            SELECT
                s.name AS name,
                m.name AS member,
                m.member_name AS member_name,
                s.posting_date AS posting_date,
                s.from_date AS from_date,
                s.to_date AS to_date,
                m.notification_number AS mobile_no
            FROM
                `tabGym Subscription` AS s,
                `tabGym Member` AS m
            WHERE
                s.docstatus = 1 AND
                s.status = 'Paid' AND
                s.member = m.name AND
                IFNULL(m.notification_number, '') != '' AND (
                    s.to_date < %(posting_date)s OR
                    s.to_date IN %(days_before_expiry)s
                )
        """,
        values={
            "posting_date": posting_date,
            "days_before_expiry": days_before_expiry
        },
        as_dict=1,
    )
    for sub in subscriptions:
        template = (settings.sms_on_expiry
                    if date_diff(sub.get("to_date"), posting_date) < 0 else
                    settings.sms_before_expiry)
        try:
            content = get_sms_text(
                template,
                merge(
                    sub,
                    {
                        "eta":
                        pretty_date(getdate(sub.get("to_date")),
                                    ref_date=getdate(posting_date))
                    },
                ),
            )
            subject = "SMS: {} for {}".format(template, sub.get("member"))
            if content:
                request_sms(
                    sub.get("mobile_no"),
                    content,
                    communication={
                        "subject": subject,
                        "reference_doctype": "Gym Subscription",
                        "reference_name": sub.get("name"),
                        "timeline_doctype": "Gym Member",
                        "timeline_name": sub.get("member"),
                    },
                )
        except TypeError:
            pass
    return None
Exemplo n.º 3
0
 def test_pretty_date_tomorrow(self):
     self.assertEqual(
         pretty_date(getdate('2018-08-20'), getdate('2018-08-19')),
         'tomorrow'
     )
Exemplo n.º 4
0
 def test_pretty_date_days(self):
     self.assertEqual(
         pretty_date(getdate('2018-08-25'), getdate('2018-08-19')),
         'in 6 days'
     )
Exemplo n.º 5
0
 def test_pretty_date_years(self):
     self.assertEqual(
         pretty_date(getdate('2020-10-25'), getdate('2018-08-19')),
         'in 2 years'
     )
Exemplo n.º 6
0
 def test_pretty_date_today(self):
     self.assertEqual(
         pretty_date(getdate('2018-08-19'), getdate('2018-08-19')),
         'today'
     )
Exemplo n.º 7
0
 def test_pretty_date_year(self):
     self.assertEqual(
         pretty_date(getdate('2019-10-25'), getdate('2018-08-19')),
         'in a year'
     )
Exemplo n.º 8
0
 def test_pretty_date_months(self):
     self.assertEqual(
         pretty_date(getdate('2018-10-25'), getdate('2018-08-19')),
         'in 2 months'
     )
Exemplo n.º 9
0
 def test_pretty_date_month(self):
     self.assertEqual(
         pretty_date(getdate('2018-09-25'), getdate('2018-08-19')),
         'in a month'
     )
Exemplo n.º 10
0
 def test_pretty_date_weeks(self):
     self.assertEqual(
         pretty_date(getdate('2018-09-05'), getdate('2018-08-19')),
         'in 2 weeks'
     )
def send_reminders(posting_date=today()):
    settings = frappe.get_single('Gym Settings')
    if not settings.sms_before_expiry and not settings.sms_on_expiry:
        return None
    days_before_expiry = compose(
        tuple,
        partial(map, lambda x: add_days(posting_date, cint(x))),
        compact,
    )(settings.days_before_expiry.split('\n'))
    subscriptions = frappe.db.sql(
        """
            SELECT
                s.name AS name,
                m.name AS member,
                m.member_name AS member_name,
                s.posting_date AS posting_date,
                s.from_date AS from_date,
                s.to_date AS to_date,
                m.notification_number AS mobile_no
            FROM
                `tabGym Subscription` AS s,
                `tabGym Member` AS m
            WHERE
                s.docstatus = 1 AND
                s.status = 'Paid' AND
                s.member = m.name AND
                IFNULL(m.notification_number, '') != '' AND (
                    s.to_date < %(posting_date)s OR
                    s.to_date IN %(days_before_expiry)s
                )
        """,
        values={
            'posting_date': posting_date,
            'days_before_expiry': days_before_expiry,
        },
        as_dict=1,
    )
    for sub in subscriptions:
        template = settings.sms_on_expiry \
            if date_diff(sub.get('to_date'), posting_date) < 0 \
            else settings.sms_before_expiry
        try:
            content = get_sms_text(
                template,
                merge(
                    sub, {
                        'eta':
                        pretty_date(getdate(sub.get('to_date')),
                                    ref_date=getdate(posting_date))
                    }),
            )
            subject = 'SMS: {} for {}'.format(template, sub.get('member'))
            if content:
                request_sms(sub.get('mobile_no'),
                            content,
                            communication={
                                'subject': subject,
                                'reference_doctype': 'Gym Subscription',
                                'reference_name': sub.get('name'),
                                'timeline_doctype': 'Gym Member',
                                'timeline_name': sub.get('member'),
                            })
        except TypeError:
            pass
    return None