Merge branch 'development' of https://github.com/MNPC-IR/Rasaddam_Backend into development
This commit is contained in:
2
.idea/Rasaddam_Backend.iml
generated
2
.idea/Rasaddam_Backend.iml
generated
@@ -14,7 +14,7 @@
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (env)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (dam_env)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -3,5 +3,5 @@
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.10 (env)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (env)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (dam_env)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
@@ -236,44 +236,41 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
|
||||
|
||||
ser_data = warehouse_serializers.InventoryQuotaSaleTransactionSerializer(queryset, many=True).data
|
||||
|
||||
# جمعآوری تمام آیتمها برای پیدا کردن سهمهای یونیک
|
||||
all_items = []
|
||||
for data in ser_data:
|
||||
all_items.extend(data.get('items', []))
|
||||
|
||||
# محاسبه سهمهای یونیک (برای ستونهای داینامیک)
|
||||
all_share_totals = calculate_share_totals(all_items)
|
||||
share_names = [share['name'] for share in all_share_totals]
|
||||
|
||||
excel_options = [
|
||||
"ردیف",
|
||||
"تعاونی دامدار",
|
||||
"کد ملی دامدار",
|
||||
"شهر تعاونی",
|
||||
"نام و نام خانوادگی دامدار",
|
||||
"کد ملی دامدار",
|
||||
"شهر دامدار",
|
||||
"تاریخ",
|
||||
"محصولات",
|
||||
"شناسه تراکنش",
|
||||
"شماره کارت",
|
||||
"مبلغ",
|
||||
"ماهیت وزن",
|
||||
"وضعیت",
|
||||
]
|
||||
# اضافه کردن ستونهای داینامیک سهمها
|
||||
excel_options.extend(share_names)
|
||||
|
||||
header_list = [
|
||||
"مبلغ کل",
|
||||
"تعداد تراکنشها",
|
||||
]
|
||||
# اضافه کردن سهمها به هدر
|
||||
header_list.extend(share_names)
|
||||
|
||||
# محاسبه height داینامیک بر اساس تعداد آیتمها
|
||||
header_height = max(25, 15 + len(header_list) * 3)
|
||||
options_height = max(25, 15 + len(excel_options) * 2)
|
||||
|
||||
create_header(worksheet, header_list, 5, 2, height=header_height, border_style='thin')
|
||||
|
||||
# ساخت عنوان با بازه تاریخ
|
||||
start_date = request.query_params.get('start')
|
||||
end_date = request.query_params.get('end')
|
||||
|
||||
@@ -294,9 +291,8 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
|
||||
|
||||
l = 6
|
||||
m = 1
|
||||
# دیکشنری برای نگهداری جمع سهمها
|
||||
share_column_totals = {name: 0 for name in share_names}
|
||||
|
||||
all_weight = 0
|
||||
if ser_data:
|
||||
for data in ser_data:
|
||||
items = data.get('items', [])
|
||||
@@ -308,15 +304,16 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
|
||||
products_str = '، '.join(products_list) if products_list else '-'
|
||||
|
||||
rancher_data = data.get('rancher')
|
||||
rancher_city = rancher_data.get('city', '-') if rancher_data else '-'
|
||||
national_code = rancher_data.get('national_code', '-') if rancher_data else '-'
|
||||
rancher_name = data.get('rancher_fullname', '-') if rancher_data else '-'
|
||||
|
||||
seller_org = data.get('seller_organization')
|
||||
org_name = seller_org.get('name', '-') if seller_org else '-'
|
||||
org_city = seller_org.get('city', '-') if seller_org else '-'
|
||||
|
||||
status = TRANSACTION_STATUS_MAP.get(data.get('transaction_status'), '-')
|
||||
|
||||
# محاسبه سهمهای این تراکنش
|
||||
transaction_shares = calculate_share_totals(items)
|
||||
share_values = []
|
||||
for share_name in share_names:
|
||||
@@ -326,21 +323,41 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
|
||||
)
|
||||
share_values.append(share_value)
|
||||
share_column_totals[share_name] += share_value
|
||||
items = data.get('items', [])
|
||||
|
||||
quota_sale_units = [
|
||||
item.get('quota_sale_unit')
|
||||
for item in items
|
||||
if item.get('quota_sale_unit')
|
||||
]
|
||||
|
||||
total_weight = sum(item.get('weight', 0) for item in items)
|
||||
all_weight += total_weight
|
||||
if quota_sale_units:
|
||||
all_equal = (
|
||||
len(items) > 0 and len(quota_sale_units) == len(items) and len(set(quota_sale_units)) == 1)
|
||||
if all_equal:
|
||||
weight_nature = f"{total_weight:,} {quota_sale_units[0] or ''}"
|
||||
else:
|
||||
weight_nature = "ترکیبی"
|
||||
else:
|
||||
weight_nature = f"{total_weight:,} کیلوگرم"
|
||||
list1 = [
|
||||
m,
|
||||
org_name,
|
||||
national_code,
|
||||
org_city,
|
||||
rancher_name,
|
||||
national_code,
|
||||
rancher_city,
|
||||
str(shamsi_date(convert_str_to_date(data['transaction_date']), in_value=True)) if data.get(
|
||||
'transaction_date') else '',
|
||||
products_str,
|
||||
data.get('transaction_id') or '-',
|
||||
data.get('payer_cart') or '-',
|
||||
data.get('price_paid') or 0,
|
||||
weight_nature,
|
||||
status,
|
||||
]
|
||||
# اضافه کردن مقادیر سهمها
|
||||
list1.extend(share_values)
|
||||
|
||||
create_value(worksheet, list1, l + 1, 1, height=23, m=m)
|
||||
@@ -354,7 +371,6 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
|
||||
total_price,
|
||||
transaction_count,
|
||||
]
|
||||
# اضافه کردن جمع سهمها به مقادیر هدر
|
||||
value_list.extend([share_column_totals[name] for name in share_names])
|
||||
|
||||
create_value(worksheet, value_list, 3, 5, border_style='thin')
|
||||
@@ -368,10 +384,12 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
total_price,
|
||||
all_weight,
|
||||
'',
|
||||
]
|
||||
# اضافه کردن جمع سهمها به ردیف مجموع
|
||||
list2.extend([share_column_totals[name] for name in share_names])
|
||||
|
||||
create_value(worksheet, list2, l + 3, 1, color='gray', height=23)
|
||||
|
||||
Reference in New Issue
Block a user