diff --git a/rattail_corepos/emails.py b/rattail_corepos/emails.py index 66dd464..644f4ce 100644 --- a/rattail_corepos/emails.py +++ b/rattail_corepos/emails.py @@ -62,6 +62,24 @@ class corepos_problems_invalid_person_numbers(ProblemReportEmail): } +class corepos_problems_phone_numbers_too_long(ProblemReportEmail): + """ + Looks for `meminfo` records with phone number which is too long to + properly fit in the `Customers` table. + """ + default_subject = "Phone numbers too long" + abstract = False + + def sample_data(self, request): + from corepos.db.office_op import model as corepos + + member = corepos.MemberInfo(card_number=42, + phone='(800) 555-1234 ABCDEFGHIJKLMNOP') + return { + 'problems': [member] + } + + class rattail_export_corepos_updates(ImporterEmail): """ Sent when a Rattail -> CORE-POS API export involves data changes. diff --git a/rattail_corepos/problems/corepos.py b/rattail_corepos/problems/corepos.py index c4590b0..3e81172 100644 --- a/rattail_corepos/problems/corepos.py +++ b/rattail_corepos/problems/corepos.py @@ -56,3 +56,32 @@ class InvalidPersonNumbers(ProblemReport): core_session.close() return problems + + +class PhoneNumbersTooLong(ProblemReport): + """ + Looks for ``meminfo`` records in CORE which have a phone number + value which is too long to fit into the corresponding + ``Customers`` table column in CORE. + """ + system_key = 'corepos' + problem_key = 'phone_numbers_too_long' + problem_title = "Phone numbers too long" + + def find_problems(self, **kwargs): + problems = [] + core_session = CoreSession() + + maxlen = self.app.maxlen(corepos.Customer.phone) + core_members = core_session.query(corepos.MemberInfo)\ + .order_by(corepos.MemberInfo.card_number)\ + .all() + + def inspect(member, i): + if member.phone and len(member.phone) > maxlen: + problems.append(member) + + self.progress_loop(inspect, core_members, + message="Looking for phone numbers too long") + core_session.close() + return problems diff --git a/rattail_corepos/templates/mail/corepos_problems_phone_numbers_too_long.html.mako b/rattail_corepos/templates/mail/corepos_problems_phone_numbers_too_long.html.mako new file mode 100644 index 0000000..fcb7c40 --- /dev/null +++ b/rattail_corepos/templates/mail/corepos_problems_phone_numbers_too_long.html.mako @@ -0,0 +1,19 @@ +## -*- coding: utf-8; -*- +<%inherit file="/base_problems.html.mako" /> + +<%def name="summary()"> +
+ There are ${len(problems)} member records which have a phone + number that is too long to properly fit in the `Customers` + table. Please investigate and fix at your convenience. +
+%def> + +<%def name="simple_row(member, i)"> +