
from __future__ import print_function
from django.core.management.base import BaseCommand
from assopy import models as amodels

def generate_invoices_for_zero_amount_orders_for_year(year):
    orders = amodels.Order.objects.filter(
        created__year=year,
        method='bank',
        )
    for o in orders:
        if not o.complete():
            continue
        print ('Creating invoice for order %r' % o)
        o.confirm_order(o.created)
        o.complete()

class Command(BaseCommand):
    """
    The system did not generate invoices for orders with a zero amount
    in 2018 (e.g. as result of using discounts).
    
    We have to add them after the fact.
    """
    def handle(self, *args, **options):
        generate_invoices_for_zero_amount_orders_for_year(2018)


from __future__ import print_function
from django.core.management.base import BaseCommand
from assopy import models as amodels

def generate_invoices_for_zero_amount_orders_for_year(year):
    orders = amodels.Order.objects.filter(
        created__year=year,
        method='bank',
        )
    for o in orders:
        if not o.complete():
            continue
        if o.total() > 0:
            continue
        print ('Creating invoice for order %r' % o)
        o.confirm_order(o.created)
        o.complete()

class Command(BaseCommand):
    """
    The system did not generate invoices for orders with a zero amount
    in 2018 (e.g. as result of using discounts).
    
    We have to add them after the fact.
    """
    def handle(self, *args, **options):
        generate_invoices_for_zero_amount_orders_for_year(2018)

Make sure that only zero amount orders are modified.
Make sure that only zero amount orders are modified.

Note really necessary, since we don't have real bank orders,
but better safe than sorry.

  
  from __future__ import print_function
  from django.core.management.base import BaseCommand
  from assopy import models as amodels
  
  def generate_invoices_for_zero_amount_orders_for_year(year):
      orders = amodels.Order.objects.filter(
          created__year=year,
          method='bank',
          )
      for o in orders:
          if not o.complete():
+             continue
+         if o.total() > 0:
              continue
          print ('Creating invoice for order %r' % o)
          o.confirm_order(o.created)
          o.complete()
  
  class Command(BaseCommand):
      """
      The system did not generate invoices for orders with a zero amount
      in 2018 (e.g. as result of using discounts).
      
      We have to add them after the fact.
      """
      def handle(self, *args, **options):
          generate_invoices_for_zero_amount_orders_for_year(2018)
  
Make sure that only zero amount orders are modified.
## Code Before:

from __future__ import print_function
from django.core.management.base import BaseCommand
from assopy import models as amodels

def generate_invoices_for_zero_amount_orders_for_year(year):
    orders = amodels.Order.objects.filter(
        created__year=year,
        method='bank',
        )
    for o in orders:
        if not o.complete():
            continue
        print ('Creating invoice for order %r' % o)
        o.confirm_order(o.created)
        o.complete()

class Command(BaseCommand):
    """
    The system did not generate invoices for orders with a zero amount
    in 2018 (e.g. as result of using discounts).
    
    We have to add them after the fact.
    """
    def handle(self, *args, **options):
        generate_invoices_for_zero_amount_orders_for_year(2018)

## Instruction:
Make sure that only zero amount orders are modified.
## Code After:

from __future__ import print_function
from django.core.management.base import BaseCommand
from assopy import models as amodels

def generate_invoices_for_zero_amount_orders_for_year(year):
    orders = amodels.Order.objects.filter(
        created__year=year,
        method='bank',
        )
    for o in orders:
        if not o.complete():
            continue
        if o.total() > 0:
            continue
        print ('Creating invoice for order %r' % o)
        o.confirm_order(o.created)
        o.complete()

class Command(BaseCommand):
    """
    The system did not generate invoices for orders with a zero amount
    in 2018 (e.g. as result of using discounts).
    
    We have to add them after the fact.
    """
    def handle(self, *args, **options):
        generate_invoices_for_zero_amount_orders_for_year(2018)
