diff --git a/inventory/utils.py b/inventory/utils.py index 70721d61..10234d5a 100644 --- a/inventory/utils.py +++ b/inventory/utils.py @@ -22,6 +22,7 @@ from django_ledger.models import ( BillModel, VendorModel, CustomerModel, + ItemTransactionModel ) from decimal import Decimal @@ -815,3 +816,23 @@ class CarFinanceCalculator: +def get_item_transactions(txs): + transactions = [] + for tx in txs: + data = {} + if tx.item_model.additional_info.get('car_info'): + data["info"] = tx.item_model.additional_info.get('car_info') + if tx.item_model.additional_info.get('car_finance'): + data["finance"] = tx.item_model.additional_info.get('car_finance') + if tx.has_estimate(): + data["estimate"] = tx.ce_model + data["has_estimate"] = True + data["customer"] = tx.ce_model.customer + if tx.has_invoice(): + data["invoice"] = tx.invoice_model + data["has_invoice"] = True + data["customer"] = tx.invoice_model.customer + if bool(data): + transactions.append(data) + print(data) + return transactions \ No newline at end of file diff --git a/inventory/views.py b/inventory/views.py index c6c7cf92..8bbd6223 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -14,6 +14,7 @@ from django_ledger.forms.bill import ( from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_exempt from django_ledger.models import ( + ItemTransactionModel, EntityModel, InvoiceModel, BankAccountModel, @@ -94,6 +95,7 @@ from .utils import ( get_calculations, get_car_finance_data, get_financial_values, + get_item_transactions, reserve_car, send_email, get_user_type, @@ -2348,10 +2350,9 @@ def account_delete(request, pk): # Sales list def sales_list_view(request): - items = ItemModel.objects.all() - context = { - "items":items - } + transactions = ItemTransactionModel.objects.all()[:10] + txs = get_item_transactions(transactions) + context = {"txs":txs} return render(request, "sales/sales_list.html",context) # Estimates diff --git a/scripts/run.py b/scripts/run.py index 8a642de8..207a2e85 100644 --- a/scripts/run.py +++ b/scripts/run.py @@ -1,7 +1,7 @@ from django_ledger.models.invoice import InvoiceModel from django_ledger.utils import accruable_net_summary from decimal import Decimal -from django_ledger.models import EstimateModel,EntityModel,ItemModel +from django_ledger.models import EstimateModel,EntityModel,ItemModel,ItemTransactionModel from rich import print from datetime import date from inventory.models import Car, Dealer, VatRate,Lead,CarMake,CarModel,Schedule @@ -93,10 +93,26 @@ def run(): # hash_object.update(f"{i.id_car_make.name}{i.id_car_model.name}".encode('utf-8')) # print(hash_object.hexdigest() , i.id_car_make.name, i.id_car_model.name) - - items = ItemModel.objects.all() - for item in items: - pass + + def get_item(tx:ItemTransactionModel): + data = {"data": {}} + data["data"]["info"] = tx.item_model.additional_info.get('car_info') + data["data"]["finance"] = tx.item_model.additional_info.get('car_finance') + if tx.has_estimate(): + data["data"]["estimate"] = tx.ce_model + data["data"]["has_estimate"] = True + data["data"]["customer"] = tx.ce_model.customer + if tx.has_invoice(): + data["data"]["invoice"] = tx.invoice_model + data["data"]["has_invoice"] = True + data["data"]["customer"] = tx.invoice_model.customer + return data + + transactions = ItemTransactionModel.objects.all() + output = [] + for transaction in transactions: + output.append(get_item(transaction)) + print(output) # info = item.additional_info["car_info"] # finance = item.additional_info["car_finance"] # print({"vin":info["make"],"mode":info["model"],"year":info["year"],"trim":info["trim"],"mileage":info["mileage"],"cost_price":finance["cost_price"],"selling_price":finance["selling_price"]}) \ No newline at end of file diff --git a/templates/header.html b/templates/header.html index 13eaefd0..a835dfe5 100644 --- a/templates/header.html +++ b/templates/header.html @@ -136,6 +136,14 @@ +
| Make | -Model | -Year | -Trim | -VIN | -Receiving Date | - -STATUS | +Customer Name | +Customer Address | +Customer Phone | +Make | +Model | +VIN | +Trim | +Selling Price | +Estimate | +Invoice | +Sales Staff | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{car.id_car_make}} | +
+ {{tx.customer.customer_name}} + |
+
+ {{tx.customer.address_1}} + |
+
+ {{tx.customer.phone}} + |
+ {{tx.info.make}} |
- {{car.id_car_model}} +{{tx.info.model}} |
- {{car.year}} +{{tx.info.vin}} |
- {{car.id_car_trim}} +{{tx.info.trim}} |
- {{car.vin}} +{{tx.finance.total}} |
- {{car.receiving_date}} + {% if tx.has_estimate %} +
+
+ {{tx.estimate.estimate_number}}
+ |
+
+ {% if tx.has_invoice %}
+
+
+ {{tx.invoice.invoice_number}}
+ |
@@ -186,7 +237,7 @@ |