🚨 format python code using black
This commit is contained in:
1 parent
9c4a5b3d84
commit
a052397990
24 files changed
+643
-407
No files matched your search
+55
-47
@@ -16,58 +16,66 @@ def report(request):
|
||||
# end of day
|
||||
end_time = datetime.now().replace(hour=23, minute=59, second=59, microsecond=999)
|
||||
|
||||
if request.GET.get('start_time', False) or request.GET.get('end_time', False):
|
||||
if request.GET.get("start_time", False) or request.GET.get("end_time", False):
|
||||
form = DateRangeForm(request.GET)
|
||||
if form.is_valid():
|
||||
start_time = form.cleaned_data['start_time']
|
||||
start_time = form.cleaned_data["start_time"]
|
||||
# end of day
|
||||
end_time = form.cleaned_data['end_time'].replace(hour=23, minute=59, second=59, microsecond=999)
|
||||
end_time = form.cleaned_data["end_time"].replace(hour=23, minute=59, second=59, microsecond=999)
|
||||
|
||||
else:
|
||||
form = DateRangeForm(initial={
|
||||
'start_time': start_time.strftime("%Y-%m-%d"),
|
||||
'end_time': end_time.strftime("%Y-%m-%d")
|
||||
})
|
||||
form = DateRangeForm(
|
||||
initial={
|
||||
"start_time": start_time.strftime("%Y-%m-%d"),
|
||||
"end_time": end_time.strftime("%Y-%m-%d"),
|
||||
}
|
||||
)
|
||||
|
||||
# Inventory
|
||||
products = Product.objects\
|
||||
.filter(transactions__created__range=[start_time, end_time])\
|
||||
.values('name', 'transactions__unit_price', 'transactions__amount')\
|
||||
.order_by('name')
|
||||
products = (
|
||||
Product.objects.filter(transactions__created__range=[start_time, end_time])
|
||||
.values("name", "transactions__unit_price", "transactions__amount")
|
||||
.order_by("name")
|
||||
)
|
||||
# group by name and sum
|
||||
inventory_products = {}
|
||||
for k, g in groupby(products, lambda x: x['name']):
|
||||
for k, g in groupby(products, lambda x: x["name"]):
|
||||
group = []
|
||||
for el in g:
|
||||
el['transactions__price'] = el['transactions__amount'] * el['transactions__unit_price']
|
||||
el["transactions__price"] = el["transactions__amount"] * el["transactions__unit_price"]
|
||||
group.append(el)
|
||||
inventory_products.update({k: {
|
||||
'name': k,
|
||||
"transactions": group,
|
||||
"transactions_sum": sum(map(lambda x: x['transactions__price'], group)),
|
||||
"transactions_units": sum(map(lambda x: x['transactions__amount'], group))
|
||||
}})
|
||||
inventory_products.update(
|
||||
{
|
||||
k: {
|
||||
"name": k,
|
||||
"transactions": group,
|
||||
"transactions_sum": sum(map(lambda x: x["transactions__price"], group)),
|
||||
"transactions_units": sum(map(lambda x: x["transactions__amount"], group)),
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
itrans = InventoryTransaction.objects.filter(created__range=[start_time, end_time])
|
||||
inv_in = sum(map(lambda x: x[1].get('transactions_sum', 0), inventory_products.items()))
|
||||
inv_in = sum(map(lambda x: x[1].get("transactions_sum", 0), inventory_products.items()))
|
||||
|
||||
# out
|
||||
out_products = Product.objects\
|
||||
.filter(orderlines__order__created__range=[start_time, end_time])\
|
||||
.values('name', 'orderlines__unit_price', 'orderlines__amount')\
|
||||
.order_by('name')
|
||||
out_products = (
|
||||
Product.objects.filter(orderlines__order__created__range=[start_time, end_time])
|
||||
.values("name", "orderlines__unit_price", "orderlines__amount")
|
||||
.order_by("name")
|
||||
)
|
||||
# group by name and sum
|
||||
for k, g in groupby(out_products, lambda x: x['name']):
|
||||
for k, g in groupby(out_products, lambda x: x["name"]):
|
||||
group = []
|
||||
for el in g:
|
||||
el['orderlines__price'] = el['orderlines__amount'] * el['orderlines__unit_price']
|
||||
el["orderlines__price"] = el["orderlines__amount"] * el["orderlines__unit_price"]
|
||||
group.append(el)
|
||||
|
||||
product = {
|
||||
'name': k,
|
||||
"name": k,
|
||||
"orderlines": group,
|
||||
"orderlines_sum": sum(map(lambda x: x['orderlines__price'], group)),
|
||||
"orderlines_units": sum(map(lambda x: x['orderlines__amount'], group))
|
||||
"orderlines_sum": sum(map(lambda x: x["orderlines__price"], group)),
|
||||
"orderlines_units": sum(map(lambda x: x["orderlines__amount"], group)),
|
||||
}
|
||||
if k in inventory_products:
|
||||
# add diff
|
||||
@@ -76,42 +84,42 @@ def report(request):
|
||||
inventory_products.update({k: product})
|
||||
|
||||
for p in inventory_products.items():
|
||||
p[1]['value_diff'] = p[1].get('transactions_sum', 0) - p[1].get('orderlines_sum', 0)
|
||||
p[1]['units_diff'] = p[1].get('transactions_units', 0) - p[1].get('orderlines_units', 0)
|
||||
p[1]["value_diff"] = p[1].get("transactions_sum", 0) - p[1].get("orderlines_sum", 0)
|
||||
p[1]["units_diff"] = p[1].get("transactions_units", 0) - p[1].get("orderlines_units", 0)
|
||||
|
||||
inv_out = sum(map(lambda x: x[1].get('orderlines_sum', 0), inventory_products.items()))
|
||||
inv_out = sum(map(lambda x: x[1].get("orderlines_sum", 0), inventory_products.items()))
|
||||
|
||||
inv_diff = inv_in - inv_out
|
||||
|
||||
# Deposits and sales
|
||||
saldo_profiles = sum(UserProfile.objects.all().values_list('balance', flat=True))
|
||||
deposits = sum(Transaction.objects.all().values_list('amount', flat=True))
|
||||
purchases = sum(Order.objects.all().values_list('order_sum', flat=True))
|
||||
saldo_profiles = sum(UserProfile.objects.all().values_list("balance", flat=True))
|
||||
deposits = sum(Transaction.objects.all().values_list("amount", flat=True))
|
||||
purchases = sum(Order.objects.all().values_list("order_sum", flat=True))
|
||||
saldo = deposits - purchases
|
||||
|
||||
deposits_start = sum(Transaction.objects.filter(created__lt=start_time).values_list('amount', flat=True))
|
||||
purchases_start = sum(Order.objects.filter(created__lt=start_time).values_list('order_sum', flat=True))
|
||||
deposits_start = sum(Transaction.objects.filter(created__lt=start_time).values_list("amount", flat=True))
|
||||
purchases_start = sum(Order.objects.filter(created__lt=start_time).values_list("order_sum", flat=True))
|
||||
saldo_start = deposits_start - purchases_start
|
||||
|
||||
deposits_end = sum(Transaction.objects.filter(created__lt=end_time).values_list('amount', flat=True))
|
||||
purchases_end = sum(Order.objects.filter(created__lt=end_time).values_list('order_sum', flat=True))
|
||||
deposits_end = sum(Transaction.objects.filter(created__lt=end_time).values_list("amount", flat=True))
|
||||
purchases_end = sum(Order.objects.filter(created__lt=end_time).values_list("order_sum", flat=True))
|
||||
saldo_end = deposits_end - purchases_end
|
||||
|
||||
deposits_diff = deposits_end - deposits_start
|
||||
purchases_diff = purchases_end - purchases_start
|
||||
saldo_diff = saldo_end - saldo_start
|
||||
|
||||
return render(request, 'report.html', locals())
|
||||
return render(request, "report.html", locals())
|
||||
|
||||
|
||||
def inventory(request):
|
||||
products = Product.objects.all().order_by('-active', 'inventory_amount', 'name')
|
||||
transactions = InventoryTransaction.objects.all().order_by('-created')
|
||||
products = Product.objects.all().order_by("-active", "inventory_amount", "name")
|
||||
transactions = InventoryTransaction.objects.all().order_by("-created")
|
||||
products_active = products.filter(active=True)
|
||||
wholesale_value = sum([p.wholesale_value for p in products_active])
|
||||
num_products = sum(products_active.values_list('inventory_amount', flat=True))
|
||||
num_products = sum(products_active.values_list("inventory_amount", flat=True))
|
||||
|
||||
return render(request, 'inventory.html', locals())
|
||||
return render(request, "inventory.html", locals())
|
||||
|
||||
|
||||
def inventory_add(request):
|
||||
@@ -125,12 +133,12 @@ def inventory_add(request):
|
||||
itrans.product.save()
|
||||
itrans.save()
|
||||
messages.success(request, "Satt inn {0} stk {1}.".format(itrans.amount, itrans.product))
|
||||
return redirect('inventory-add')
|
||||
return redirect("inventory-add")
|
||||
|
||||
else:
|
||||
messages.error(request, 'Feil med skjemaet, se under.')
|
||||
messages.error(request, "Feil med skjemaet, se under.")
|
||||
form = InventoryTransactionForm(data=request.POST)
|
||||
else:
|
||||
form = InventoryTransactionForm()
|
||||
|
||||
return render(request, 'inventory_add.html', locals())
|
||||
return render(request, "inventory_add.html", locals())
|
||||
Reference in new issue
Block a user