From 387b7b099c9816ac52e6fede367aaa428fe2d953 Mon Sep 17 00:00:00 2001 From: gitea Date: Tue, 11 Feb 2025 14:19:51 +0000 Subject: [PATCH] add sales list --- inventory/utils.py | 21 ++++++++ inventory/views.py | 9 ++-- scripts/run.py | 26 ++++++++-- templates/header.html | 8 +++ templates/sales/sales_list.html | 87 ++++++++++++++++++++++++++------- 5 files changed, 124 insertions(+), 27 deletions(-) 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 @@ + diff --git a/templates/sales/sales_list.html b/templates/sales/sales_list.html index 71b14b1e..18ed8ae9 100644 --- a/templates/sales/sales_list.html +++ b/templates/sales/sales_list.html @@ -29,7 +29,7 @@
- + {% endcomment %}
@@ -129,35 +129,86 @@ - - - - - - - - + + + + + + + + + + + - {% for car in cars %} + {% for tx in txs %} - + + + + +
MakeModelYearTrimVINReceiving DateSTATUSCustomer NameCustomer AddressCustomer PhoneMakeModelVINTrimSelling PriceEstimateInvoiceSales 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.estimate.status == "draft" %} + {{tx.estimate.status}} + {% elif tx.estimate.status == "in_review" %} + {{tx.estimate.status}} + {% elif tx.estimate.status == "approved" %} + {{tx.estimate.status}} + {% elif tx.estimate.status == "completed" %} + {{tx.estimate.status}} + {% endif %} +

+ {% endif %} +
+ {% if tx.has_invoice %} +

+ + {{tx.invoice.invoice_number}} +
+ {% if tx.invoice.is_draft %} + {{tx.invoice.invoice_status}} + {% elif tx.invoice.is_review %} + {{tx.invoice.invoice_status}} + {% elif tx.invoice.is_approved %} + {{tx.invoice.invoice_status}} + {% elif tx.invoice.is_completed %} + {{tx.invoice.invoice_status}} + {% elif tx.invoice.is_paid %} + {{tx.invoice.invoice_status}} + {% elif tx.invoice.is_canceled %} + {{tx.invoice.invoice_status}} + {% elif tx.invoice.is_past_due %} + Past Due + {% endif %} +

+ {% endif %}
@@ -186,7 +237,7 @@