# SVN changeset patch # User fquino # Date 2017-12-12 22:47:51.121271 # Revision 278 reporte de fungibles bugs Index: projects/inventario2.0/trunk/django/django-inventory/django_inventory/apps/assets/models.py =================================================================== diff --git a/projects/inventario2.0/trunk/django/django-inventory/django_inventory/apps/assets/models.py b/projects/inventario2.0/trunk/django/django-inventory/django_inventory/apps/assets/models.py --- a/projects/inventario2.0/trunk/django/django-inventory/django_inventory/apps/assets/models.py (revision 277) +++ b/projects/inventario2.0/trunk/django/django-inventory/django_inventory/apps/assets/models.py (revision 278) @@ -304,7 +304,7 @@ output = transaction_output_total['sum'] count = count + transaction_output_total['count'] total_qty_transactions = input - output - total_count_transactions = len(inventory_transactions.all()) + total_count_transactions = inventory_transactions.all().count()#len(inventory_transactions.all()) if self.is_unit(): total_qty_transactions = int(total_qty_transactions) inventory_obj = {'inventory': inventory, 'inventory_transactions': total_count_transactions, 'inventory_total': total_qty_transactions} @@ -315,6 +315,32 @@ return (stock) else: return (stock['total_qty']) + + + @property + def stock(self): + """ + Devuelve solo el stock del fungible + """ + transactions = self.transactions.all() + stock = {'total_qty': 0} + input = Decimal(0.0) + output = Decimal(0.0) + + transaction_input_total = transactions.filter(direction='IN', state='COMPLETED').aggregate(sum=Sum('quantity'), count=Count('id')) + transaction_output_total = transactions.filter(direction='OUT', state='COMPLETED').aggregate(sum=Sum('quantity'), count=Count('id')) + if 'sum' in transaction_input_total and transaction_input_total['sum'] is not None: + input = transaction_input_total['sum'] + if 'sum' in transaction_output_total and transaction_output_total['sum'] is not None: + output = transaction_output_total['sum'] + total_qty_transactions = input - output + + if self.is_unit(): + total_qty_transactions = int(total_qty_transactions) + + stock['total_qty'] = stock['total_qty'] + total_qty_transactions + return (stock['total_qty']) + def get_price(self, detail=False, get_string=True): from movements.models import PurchaseOrderItem, PurchaseOrderFungibleItem Index: projects/inventario2.0/trunk/django/django-inventory/django_inventory/apps/assets/views.py =================================================================== diff --git a/projects/inventario2.0/trunk/django/django-inventory/django_inventory/apps/assets/views.py b/projects/inventario2.0/trunk/django/django-inventory/django_inventory/apps/assets/views.py --- a/projects/inventario2.0/trunk/django/django-inventory/django_inventory/apps/assets/views.py (revision 277) +++ b/projects/inventario2.0/trunk/django/django-inventory/django_inventory/apps/assets/views.py (revision 278) @@ -1468,17 +1468,14 @@ # Generate a sequence of rows. The range is based on the maximum number of # rows that can be handled by a single sheet in most spreadsheet # applications. - allfungibles = FungibleItem.objects.all() + allfungibles = FungibleItem.objects.all().select_related('unit', 'area') #rows = (["Row {}".format(idx), str(idx)] for idx in allfungibles) - rows = ([str(f.id), f.name.encode('utf-8'), f.unit.name.encode('utf-8'), f.area.name.encode('utf-8'), f.get_locations().encode('utf-8'), f.get_stock(), f.notes.encode('utf-8')] for f in allfungibles) - #rows = ([format(f.id), f.name.encode('utf-8'), f.unit.name.encode('utf-8'), f.area.name.encode('utf-8'), f.get_locations().encode('utf-8'), f.get_stock(),f.notes.encode('utf-8')] for f in allfungibles) #rows = ([]) - #print dir(rows) - #[('ID','Name','C','D','E','F','G')] - #rows.insert(0, ['ID','Name']) + rows = ([str(f.id), f.name.encode('utf-8'), f.unit.name.encode('utf-8'), f.area.name.encode('utf-8'), f.get_locations().encode('utf-8'), str(f.stock), f.notes.encode('utf-8')] for f in allfungibles) + #rows = ([f['id'], f['name'].encode('utf-8'), f['unit__name'], f['area__name'].encode('utf-8'), f['stock'], f['notes'].encode('utf-8')] for f in allfungibles) pseudo_buffer = Echo() writer = csv.writer(pseudo_buffer) response = StreamingHttpResponse((writer.writerow(row) for row in rows), content_type="text/csv") - response['Content-Disposition'] = 'attachment; filename="estedocumento.csv"' + response['Content-Disposition'] = 'attachment; filename="FungiblesReport.csv"' return response \ No newline at end of file