From 7b3fc15efdbd9802460505714115d2a1cd7bd623 Mon Sep 17 00:00:00 2001 From: ismail Date: Sun, 22 Jun 2025 20:06:26 +0300 Subject: [PATCH] update on the po and bill --- inventory/templatetags/custom_filters.py | 4 ++ inventory/views.py | 47 ++++++++++++++----- .../includes/po_item_formset.html | 4 +- templates/purchase_orders/po_update.html | 2 +- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/inventory/templatetags/custom_filters.py b/inventory/templatetags/custom_filters.py index a0377f2f..e10334a9 100644 --- a/inventory/templatetags/custom_filters.py +++ b/inventory/templatetags/custom_filters.py @@ -449,6 +449,10 @@ def po_item_table1(context, queryset): "purchase_orders/includes/po_item_formset.html", takes_context=True ) def po_item_formset_table(context, po_model, itemtxs_formset): + # print(len(itemtxs_formset.forms)) + + for form in itemtxs_formset.forms: + form.fields['item_model'].queryset = form.fields['item_model'].queryset.filter(item_role="inventory") return { "entity_slug": context["view"].kwargs["entity_slug"], "po_model": po_model, diff --git a/inventory/views.py b/inventory/views.py index fd027787..e87d8b7d 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -9100,14 +9100,31 @@ class PurchaseOrderUpdateView(PurchaseOrderModelUpdateViewBase): template_name = "purchase_orders/po_update.html" context_object_name = "po_model" - def get_context_data(self, **kwargs): + def get_context_data(self, itemtxs_formset=None, **kwargs): dealer = get_user_type(self.request) context = super().get_context_data(**kwargs) context["entity_slug"] = dealer.entity.slug - context["make_data"] = models.CarMake.objects.all() - context["model_data"] = models.CarModel.objects.none() - context["serie_data"] = models.CarSerie.objects.none() - context["trim_data"] = models.CarTrim.objects.none() + po_model: PurchaseOrderModel = self.object + # context["make_data"] = models.CarMake.objects.all() + # context["model_data"] = models.CarModel.objects.none() + # context["serie_data"] = models.CarSerie.objects.none() + # context["trim_data"] = models.CarTrim.objects.none() + # itemtxs_qs = dealer.entity.get_items_inventory().filter(item_role="inventory") + if not itemtxs_formset: + itemtxs_qs = self.get_po_itemtxs_qs(po_model) + itemtxs_qs, itemtxs_agg = po_model.get_itemtxs_data(queryset=itemtxs_qs) + po_itemtxs_formset_class = get_po_itemtxs_formset_class(po_model) + itemtxs_formset = po_itemtxs_formset_class( + entity_slug=dealer.entity.slug, + user_model=dealer.entity.admin, + po_model=po_model, + queryset=itemtxs_qs, + ) + else: + itemtxs_qs, itemtxs_agg = po_model.get_itemtxs_data() + + context['itemtxs_qs'] = itemtxs_qs + context['itemtxs_formset'] = itemtxs_formset return context def get_success_url(self): @@ -9127,7 +9144,7 @@ class PurchaseOrderUpdateView(PurchaseOrderModelUpdateViewBase): kwargs={"entity_slug": entity_slug, "po_pk": po_pk}, ) ) - return super(PurchaseOrderModelUpdateViewBase, self).get( + return super(PurchaseOrderUpdateView, self).get( request, entity_slug, po_pk, *args, **kwargs ) @@ -9227,7 +9244,9 @@ class BasePurchaseOrderActionActionView(BasePurchaseOrderActionActionViewBase): ) def get(self, request, *args, **kwargs): - kwargs["user_model"] = self.request.user + # kwargs["user_model"] = self.request.user + dealer = get_user_type(request) + kwargs["user_model"] = dealer.entity.admin if not self.action_name: raise ImproperlyConfigured("View attribute action_name is required.") response = super(BasePurchaseOrderActionActionView, self).get( @@ -9236,13 +9255,19 @@ class BasePurchaseOrderActionActionView(BasePurchaseOrderActionActionViewBase): po_model: PurchaseOrderModel = self.get_object() try: - getattr(po_model, self.action_name)(commit=self.commit, **kwargs) - except ValidationError as e: + getattr(po_model, self.action_name)(commit=self.commit,**kwargs) messages.add_message( request, - message=e.message, - level=messages.ERROR, + message="PO updated successfully.", + level=messages.SUCCESS, ) + except ValidationError as e: + print(e) + # messages.add_message( + # request, + # message=e.message, + # level=messages.ERROR, + # ) return response diff --git a/templates/purchase_orders/includes/po_item_formset.html b/templates/purchase_orders/includes/po_item_formset.html index 23e9218f..32c3ffbd 100644 --- a/templates/purchase_orders/includes/po_item_formset.html +++ b/templates/purchase_orders/includes/po_item_formset.html @@ -1,5 +1,7 @@ {% load trans from i18n %} -{% load django_ledger %} +{% load currency_symbol from django_ledger %} +{% load icon from django_ledger %} +{% load custom_filters %} {% load widget_tweaks %}