forked from erp-dev/erp
feat: added product info to statements api
This commit is contained in:
@@ -16,6 +16,7 @@ class StatementRecordSerializer(serializers.Serializer):
|
||||
cumulative_amount = serializers.CharField()
|
||||
current_balance = serializers.CharField()
|
||||
arrears_amount = serializers.CharField()
|
||||
items = serializers.ListField(child=serializers.DictField())
|
||||
extra = serializers.DictField(required=False)
|
||||
|
||||
|
||||
|
||||
@@ -63,8 +63,11 @@ class StatementViewBase(StockChangeViewMixin, views.APIView):
|
||||
status_label: str,
|
||||
positive_amount,
|
||||
negative_amount,
|
||||
items: List[dict] | None = None,
|
||||
extra: dict | None = None,
|
||||
) -> dict:
|
||||
items = items or []
|
||||
print(items)
|
||||
record = {
|
||||
'counterparty': counterparty_id,
|
||||
'counterparty_name': counterparty_name,
|
||||
@@ -77,6 +80,7 @@ class StatementViewBase(StockChangeViewMixin, views.APIView):
|
||||
'status_label': status_label,
|
||||
'positive_amount': self._normalize_amount(positive_amount),
|
||||
'negative_amount': self._normalize_amount(negative_amount),
|
||||
'items': items,
|
||||
}
|
||||
if extra:
|
||||
record['extra'] = extra
|
||||
@@ -160,9 +164,21 @@ class CustomerStatementView(StatementViewBase):
|
||||
status=business_models.SalesOrderStatusEnum.APPROVED,
|
||||
)
|
||||
.select_related('customer')
|
||||
.prefetch_related('items__product')
|
||||
)
|
||||
records = []
|
||||
for order in qs:
|
||||
items = [
|
||||
{
|
||||
'product_id': item.product_id,
|
||||
'product_name': item.product.name,
|
||||
'quantity': item.quantity,
|
||||
'price': item.price,
|
||||
'unit': item.unit,
|
||||
}
|
||||
for item in order.items.all()
|
||||
]
|
||||
print(items)
|
||||
records.append(
|
||||
self._build_record(
|
||||
counterparty_id=order.customer_id,
|
||||
@@ -176,6 +192,7 @@ class CustomerStatementView(StatementViewBase):
|
||||
status_label=order.get_status_display(),
|
||||
positive_amount=order.get_total_amount(),
|
||||
negative_amount=ZERO,
|
||||
items=items,
|
||||
)
|
||||
)
|
||||
return records
|
||||
@@ -188,9 +205,20 @@ class CustomerStatementView(StatementViewBase):
|
||||
status=business_models.SalesReturnStatusEnum.APPROVED,
|
||||
)
|
||||
.select_related('customer')
|
||||
.prefetch_related('items__product')
|
||||
)
|
||||
records = []
|
||||
for order in qs:
|
||||
items = [
|
||||
{
|
||||
'product_id': item.product_id,
|
||||
'product_name': item.product.name,
|
||||
'quantity': item.quantity,
|
||||
'price': item.price,
|
||||
'unit': item.unit,
|
||||
}
|
||||
for item in order.items.all()
|
||||
]
|
||||
records.append(
|
||||
self._build_record(
|
||||
counterparty_id=order.customer_id,
|
||||
@@ -204,6 +232,7 @@ class CustomerStatementView(StatementViewBase):
|
||||
status_label=order.get_status_display(),
|
||||
positive_amount=ZERO,
|
||||
negative_amount=order.get_total_amount(),
|
||||
items=items,
|
||||
)
|
||||
)
|
||||
return records
|
||||
@@ -283,6 +312,16 @@ class SupplierStatementView(StatementViewBase):
|
||||
)
|
||||
records = []
|
||||
for order in qs:
|
||||
items = [
|
||||
{
|
||||
'product_id': item.product_id,
|
||||
'product_name': item.product.name,
|
||||
'quantity': item.quantity,
|
||||
'price': item.price,
|
||||
'unit': item.unit,
|
||||
}
|
||||
for item in order.items.all()
|
||||
]
|
||||
records.append(
|
||||
self._build_record(
|
||||
counterparty_id=order.supplier_id,
|
||||
@@ -296,6 +335,7 @@ class SupplierStatementView(StatementViewBase):
|
||||
status_label=order.get_status_display(),
|
||||
positive_amount=order.get_total_amount(),
|
||||
negative_amount=ZERO,
|
||||
items=items,
|
||||
)
|
||||
)
|
||||
return records
|
||||
@@ -311,6 +351,16 @@ class SupplierStatementView(StatementViewBase):
|
||||
)
|
||||
records = []
|
||||
for order in qs:
|
||||
items = [
|
||||
{
|
||||
'product_id': item.product_id,
|
||||
'product_name': item.product.name,
|
||||
'quantity': item.quantity,
|
||||
'price': item.price,
|
||||
'unit': item.unit,
|
||||
}
|
||||
for item in order.items.all()
|
||||
]
|
||||
records.append(
|
||||
self._build_record(
|
||||
counterparty_id=order.supplier_id,
|
||||
@@ -324,6 +374,7 @@ class SupplierStatementView(StatementViewBase):
|
||||
status_label=order.get_status_display(),
|
||||
positive_amount=ZERO,
|
||||
negative_amount=order.get_total_amount(),
|
||||
items=items,
|
||||
)
|
||||
)
|
||||
return records
|
||||
|
||||
Reference in New Issue
Block a user