def _collect_client_birthdays(self, start, end, day_events, store): branch = api.get_current_branch(store) for v in ClientWithSalesView.find_by_birth_date(store, (start, end), branch=branch): for year in range(start.year, end.year + 1): date, ev = self._create_client_birthday(v, year) self._append_event(day_events, date, 'client_birthdays', ev)
def _collect_client_birthdays(self, start, end, day_events, store): branch = api.get_current_branch(store) for v in ClientWithSalesView.find_by_birth_date( store, (start, end), branch=branch): for year in xrange(start.year, end.year + 1): date, ev = self._create_client_birthday(v, year) self._append_event(day_events, date, 'client_birthdays', ev)
def _check_client_birthdays(self): if not api.sysparam.get_bool('BIRTHDAY_NOTIFICATION'): return # Display the info bar once per day date = api.user_settings.get('last-birthday-check') last_check = date and datetime.datetime.strptime(date, '%Y-%m-%d').date() if last_check and last_check >= datetime.date.today(): return # Only display the infobar if the user has access to calendar (because # clicking on the button will open it) and to sales (because it # requires that permission to be able to check client details) user = api.get_current_user(self.store) if not all([user.profile.check_app_permission(u'calendar'), user.profile.check_app_permission(u'sales')]): return branch = api.get_current_branch(self.store) clients_count = ClientWithSalesView.find_by_birth_date( self.store, datetime.datetime.today(), branch=branch).count() if clients_count: msg = stoqlib_ngettext( _("There is %s client doing birthday today!"), _("There are %s clients doing birthday today!"), clients_count) % (clients_count, ) button = gtk.Button(_("Check the calendar")) button.connect('clicked', self._on_check_calendar__clicked) self._birthdays_bar = self.add_info_bar( gtk.MESSAGE_INFO, "<b>%s</b>" % (glib.markup_escape_text(msg), ), action_widget=button)
def test_find_by_birth_date(self): client = self.create_client() client_view_obj = self.store.find( ClientWithSalesView, id=client.id).one() individual = client.person.individual # Clients without birthdate should be excluded by default self.assertNotIn( client_view_obj, list(ClientWithSalesView.find_by_birth_date( self.store, datetime.datetime(2015, 4, 20)))) individual.birth_date = datetime.datetime(1988, 4, 21) # The client should not appear here since his birthday is different # from the one we are querying self.assertNotIn( client_view_obj, list(ClientWithSalesView.find_by_birth_date( self.store, datetime.datetime(2015, 4, 20)))) self.assertNotIn( client_view_obj, list(ClientWithSalesView.find_by_birth_date( self.store, (datetime.datetime(2015, 2, 10), datetime.datetime(2015, 4, 20))))) self.assertIn( client_view_obj, list(ClientWithSalesView.find_by_birth_date( self.store, datetime.datetime(2015, 4, 21)))) self.assertIn( client_view_obj, list(ClientWithSalesView.find_by_birth_date( self.store, (datetime.datetime(2015, 4, 10), datetime.datetime(2015, 4, 28))))) branch = self.create_branch() # Adding the branch to the query should exclude the client again # as there isn't any sale referencing it on that branch yet self.assertNotIn( client_view_obj, list(ClientWithSalesView.find_by_birth_date( self.store, datetime.datetime(2015, 4, 21), branch=branch))) self.assertNotIn( client_view_obj, list(ClientWithSalesView.find_by_birth_date( self.store, (datetime.datetime(2015, 4, 10), datetime.datetime(2015, 4, 28)), branch=branch))) sale = self.create_sale() sale.branch = branch sale.client = client self.assertIn( client_view_obj, list(ClientWithSalesView.find_by_birth_date( self.store, datetime.datetime(2015, 4, 21), branch=branch))) self.assertIn( client_view_obj, list(ClientWithSalesView.find_by_birth_date( self.store, (datetime.datetime(2015, 4, 10), datetime.datetime(2015, 4, 28)), branch=branch))) other_sale = self.create_sale() other_sale.branch = branch other_sale.client = client # Even with another sale, the query should be distinct self.assertEqual( [client_view_obj], list(ClientWithSalesView.find_by_birth_date( self.store, datetime.datetime(2015, 4, 21), branch=branch))) self.assertEqual( [client_view_obj], list(ClientWithSalesView.find_by_birth_date( self.store, (datetime.datetime(2015, 4, 10), datetime.datetime(2015, 4, 28)), branch=branch)))