Exemple #1
0
def process_packings(queryset):

    """
    Given a Packing and Packing Items that have been
    completed, process and generate Invoices
    """
    
    packings = queryset
    packing_count = 0
    
    for packing in packings:

        packing_items = PackingItem.objects.filter(packing=packing)
        
        invoice_kwargs = {
            'packing': packing,
            'signed_off_at': timezone.now(), }
            
        invoice = Invoice(**invoice_kwargs)
        invoice.save()
        try:
            print u'%s' % invoice
        except:
            pass

        packing_item_count = 0
        
        for packing_item in packing_items:
            if packing_item.fulfilled:
                invoice_item_kwargs = {
                    'invoice': invoice,
                    'packing_item': packing_item,
                    'invoice_weight': packing_item.fulfilment_weight,
                    'invoice_quantity': packing_item.fulfilment_quantity,
                    'invoice_unit_weight': packing_item.fulfilment_unit_weight,
                    'invoice_weight_price': packing_item.fulfilment_weight_price,
                    'invoice_unit_price': packing_item.fulfilment_unit_price,
                    'notes': packing_item.notes, }
                invoice_item = InvoiceItem(**invoice_item_kwargs)
                
                try:
                    invoice_item.full_clean()
                except ValidationError, e:
                    print e
                else:
                    invoice_item.save()
                    packing_item_count += 1
                    try:
                        print u'    %s' % invoice_item
                    except:
                        pass
            else:
                break

        if len(packing_items) == packing_item_count:
            packing_count += 1
Exemple #2
0
def process_packings(queryset):

    """
    Given a Packing and Packing Items that have been
    completed, process and generate Invoices
    """
    
    packings = queryset
    
    for packing in packings:
        
        packing_items = PackingItem.objects.filter(packing=packing)
        
        invoice_kwargs = {
            'packing': packing, }
            
        invoice = Invoice(**invoice_kwargs)
        invoice.save()
        print u'%s' % invoice
        
        for packing_item in packing_items:
            
            invoice_item_kwargs = {
                'invoice': invoice,
                'packing_item': packing_item,
                'invoice_weight': packing_item.fulfilment_weight,
                'invoice_quantity': packing_item.fulfilment_quantity,
                'invoice_unit_weight': packing_item.fulfilment_unit_weight,
                'invoice_weight_price': packing_item.fulfilment_weight_price,
                'invoice_unit_price': packing_item.fulfilment_unit_price,
                'notes': packing_item.notes, }
            invoice_item = InvoiceItem(**invoice_item_kwargs)
            
            try:
                invoice_item.full_clean()
            except ValidationError, e:
                print e
            else:
                invoice_item.save()
                print u'    %s' % invoice_item