Skip to content

Commit

Permalink
Improve update_accounts_delinquent_status command logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bertini36 committed Feb 3, 2021
1 parent 41d365e commit 2e269c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion billing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.7.12'
__version__ = '1.7.13'
__copyright__ = 'Copyright (c) 2020, Skioo SA'
__licence__ = 'MIT'
__URL__ = 'https://github.com/skioo/django-customer-billing'
18 changes: 14 additions & 4 deletions billing/management/commands/update_accounts_delinquent_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

class Command(BaseCommand):
help = (
'This command mark accounts as delinquent and vice versa when account has '
'pending invoices or not valid credit cards registered'
'Marks accounts as delinquent and vice versa when account has pending invoices '
'or not valid credit cards registered.'
)

def add_arguments(self, parser):
Expand All @@ -33,15 +33,15 @@ def add_arguments(self, parser):

def handle(self, *args, **options):
dry_run = options['dry_run']
logger.info('update-delinquents-command', dry_run=dry_run)
logger.info('update-accounts-delinquent-status', dry_run=dry_run)

account_ids = Account.objects.values_list('id', flat=True)
new_delinquent_account_ids, new_compliant_account_ids = (
get_accounts_which_delinquent_status_has_to_change(account_ids)
)

logger.info(
'update-delinquents-command',
'update-accounts-delinquent-status',
new_delinquent_accounts=len(new_delinquent_account_ids),
new_compliant_accounts=len(new_compliant_account_ids),
)
Expand All @@ -53,14 +53,24 @@ def handle(self, *args, **options):
bar = progressbar.ProgressBar()
accounts = bar(accounts)

n_accounts_marked_as_delinquent = 0
for account in accounts:
reasons = get_reasons_account_is_violating_delinquent_criteria(account.id)
mark_account_as_delinquent(account.id, reason='. '.join(reasons))
n_accounts_marked_as_delinquent += 1

accounts = Account.objects.filter(id__in=new_compliant_account_ids)
if options['progress']:
bar = progressbar.ProgressBar()
accounts = bar(accounts)

n_accounts_marked_as_compliant = 0
for account in accounts:
mark_account_as_compliant(account.id, reason='Requirements met again')
n_accounts_marked_as_compliant += 1

logger.info(
'update-accounts-delinquent-status',
n_accounts_marked_as_delinquent=n_accounts_marked_as_delinquent,
n_accounts_marked_as_compliant=n_accounts_marked_as_compliant,
)

0 comments on commit 2e269c8

Please sign in to comment.