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