This commit is contained in:
2026-01-28 16:24:05 +03:30
parent 3b34441efc
commit e646bb88a9
3 changed files with 285 additions and 14 deletions

View File

@@ -63,7 +63,6 @@ import hashlib
# 1232, 1232, 1273, 1273, 1240,
# 1240, 1240, 1240, 1240, 1234, 1234, 1200, 1200, 1247, 1186, 1085, 1098, 1251, 1251, 1251, 1251, 1251,
# 1336, 1336, 1113, 1113, 1253, 1253, 1113]
#
@api_view(["GET"])
@@ -2661,6 +2660,21 @@ def accept_bar_difference_request_pending_cron_job():
bar_request.hatching.save()
bar_request.save()
def accept_bar_difference_request_pending_manual(request):
date = datetime.now().date() - timedelta(days=2)
bar_requests = BarDifferenceRequest.objects.filter(trash=False,
state='pending', create_date__date__lt=date).order_by('id')
for bar_request in bar_requests:
bar_request.state = 'accepted'
bar_request.acceptor_fullname = 'سیستمی'
bar_request.acceptor_mobile = '00000000000'
bar_request.acceptor_date = datetime.now()
bar_request.hatching.bar_difference_request_quantity += bar_request.quantity
bar_request.hatching.bar_difference_request_weight += bar_request.weight
bar_request.hatching.save()
bar_request.save()
return HttpResponse('ok')
@api_view(["POST"])
@permission_classes([AllowAny])
@@ -4290,7 +4304,7 @@ def fix_kill_house_archive_warehousing(request):
@csrf_exempt
@permission_classes([AllowAny])
def fix_steward_free_buying_product_warehousing_for_limitation(request):
stewards = Guilds.objects.filter(trash=False, steward=True, active=True)
stewards = Guilds.objects.filter(trash=False)
for steward in stewards:
product = RolesProducts.objects.get(parent_product__name='مرغ گرم', guild=steward)
guild_steward_free_buying_product_warehousing(product)
@@ -4301,7 +4315,7 @@ def fix_steward_free_buying_product_warehousing_for_limitation(request):
@csrf_exempt
@permission_classes([AllowAny])
def fix_steward_guild_steward_allocations_warehousing_for_limitation(request):
stewards = Guilds.objects.filter(trash=False, steward=True, active=True)
stewards = Guilds.objects.filter(trash=False)
for steward in stewards:
product = RolesProducts.objects.get(parent_product__name='مرغ گرم', guild=steward)
guild_steward_allocations_product_warehousing(product)
@@ -4312,7 +4326,7 @@ def fix_steward_guild_steward_allocations_warehousing_for_limitation(request):
@csrf_exempt
@permission_classes([AllowAny])
def fix_guild_steward_free_sale_warehousing_for_limitation(request):
stewards = Guilds.objects.filter(trash=False, steward=True, active=True)
stewards = Guilds.objects.filter(trash=False)
for steward in stewards:
product = RolesProducts.objects.get(parent_product__name='مرغ گرم', guild=steward)
guild_steward_free_sale_product_warehousing(product)
@@ -4323,7 +4337,7 @@ def fix_guild_steward_free_sale_warehousing_for_limitation(request):
@csrf_exempt
@permission_classes([AllowAny])
def fix_guild_steward_product_segmentation_warehousing_for_limitation(request):
stewards = Guilds.objects.filter(trash=False, steward=True, active=True)
stewards = Guilds.objects.filter(trash=False)
for steward in stewards:
product = RolesProducts.objects.get(parent_product__name='مرغ گرم', guild=steward)
guild_steward_product_segmentation(product)
@@ -4334,7 +4348,7 @@ def fix_guild_steward_product_segmentation_warehousing_for_limitation(request):
@csrf_exempt
@permission_classes([AllowAny])
def fix_steward_guild_pos_allocations_warehousing_for_limitation(request):
stewards = Guilds.objects.filter(trash=False, steward=True, active=True)
stewards = Guilds.objects.filter(trash=False)
for steward in stewards:
product = RolesProducts.objects.get(parent_product__name='مرغ گرم', guild=steward)
product.pos_allocated_weight = 0
@@ -4346,7 +4360,7 @@ def fix_steward_guild_pos_allocations_warehousing_for_limitation(request):
@csrf_exempt
@permission_classes([AllowAny])
def fix_guild_steward_archive_warehousing(request):
stewards = Guilds.objects.filter(trash=False, steward=True, active=True)
stewards = Guilds.objects.filter(trash=False)
for steward in stewards:
product = RolesProducts.objects.filter(guild=steward, trash=False, name='مرغ گرم').first()
@@ -4375,7 +4389,7 @@ def fix_guild_steward_archive_warehousing(request):
@csrf_exempt
@permission_classes([AllowAny])
def fix_guild_steward_pos_allocation_weight_for_product(request):
stewards = Guilds.objects.filter(trash=False, steward=True, active=True)
stewards = Guilds.objects.filter(trash=False)
for steward in stewards:
product = RolesProducts.objects.filter(guild=steward, trash=False, name='مرغ گرم').first()
transactions = ProductsTransactions.objects.filter(product=product, transaction__paid=True, trash=False,
@@ -4398,7 +4412,7 @@ def fix_guild_steward_pos_allocation_weight_for_product(request):
@csrf_exempt
@permission_classes([AllowAny])
def fix_steward_warehouse_for_limitation(request):
stewards = Guilds.objects.filter(trash=False, steward=True, active=True)
stewards = Guilds.objects.filter(trash=False)
guild_steward_allocations = StewardAllocation.objects.filter(
Q(guilds__in=stewards) | Q(to_guilds__in=stewards) | Q(steward__in=stewards) | Q(to_steward__in=stewards),
trash=False, calculate_status=True, warehouse=True, steward_warehouse=True)
@@ -4443,3 +4457,32 @@ def fix_pos_owner(request):
transaction.save()
return Response("done!")
def canceled_out_province_request_manual(request):
province_requests = PoultryRequest.objects.filter(state_process__in=('accepted', 'pending'),
province_state__in=('accepted', 'pending'), trash=False,
archive=False,
out_province_request_cancel=False, out=True, wage_pay=False,
has_wage=True)
data = {"date": str(datetime.now()), "role": "SuperAdmin", "mobile": "-",
"fullname": "کنسل شده توسط سیستم به دلیل عدم پرداخت"}
for province_request in province_requests:
if province_request.state_process == 'accepted' and province_request.province_state == 'accepted':
hatching = PoultryHatching.objects.get(key=province_request.hatching.key, trash=False)
hatching.out_province_killed_weight -= int(province_request.quantity * province_request.Index_weight)
hatching.out_province_killed_quantity -= province_request.quantity
hatching.save()
province_request.out_province_request_cancel = True
province_request.out_province_request_canceller = data
province_request.archive = True
province_request.state_process = 'rejected'
province_request.province_state = 'rejected'
province_request.save()
message = f'بار خارج از استان به شماره {province_request.order_code} به علت عدم پرداخت کنسل شد.' \
f'\n' \
f'(سامانه رصدیار)'
req = send_sms_request(
f"http://webservice.sahandsms.com/newsmswebservice.asmx/SendPostUrl?username={USERNAME_SMS_FINANCIAL}&password={PASSWORD_SMS_FINANCIAL}&from=30002501&to={UNION_NUMBER}&message={message}")
return HttpResponse('ok')

View File

@@ -5243,6 +5243,27 @@ def delete_kill_req_cron():
market_poultry_request_remain_quantity(kill_request.poultry_request)
def delete_kill_req_manual(request):
current_time = datetime.datetime.now()
kill_requests = KillRequest.objects.filter(Q(market_final_accept=True, market_code_status=True,
input_market_code__isnull=True) | Q(market_final_accept=False),
trash=False,
market=True,
market_state='pending',
market_expire_date_time__lt=current_time
).select_related('poultry_request')
for kill_request in kill_requests:
kill_request.trash = True
kill_request.market_state_message = {
"fullname": "سیستمی",
"mobile": "سیستمی",
"date": str(datetime.datetime.now())
}
kill_request.market_state = 'deleted'
kill_request.save()
market_poultry_request_remain_quantity(kill_request.poultry_request)
return HttpResponse('ok')
def delete_steward_allocation_cron():
current_time = datetime.datetime.now().date()
# allow=AllowRegisterCodeForStewardAllocation.objects.filter(trash=False,active=True).first()
@@ -5891,8 +5912,9 @@ def periodic_performance_report_dashboard(request):
top_poultry_req_stats_total_quantity = to_locale_str(top_poultry_req_stats['total_quantity'] or 0)
poultry_hatching_gt_60 = poultry_hatching.filter(chicken_age__gt=60)
poultry_request_ids = kill_house_request.values_list('province_request__poultry_request__id', flat=True).distinct()
poultry_hatching_has_killed = PoultryRequest.objects.filter(id__in=poultry_request_ids)
poultry_hatching_has_killed = PoultryRequest.objects.filter(state_process__in=('pending', 'accepted'),
province_state__in=('pending', 'accepted'),
trash=False, out=False, hatching__in=poultry_hatching)
if poultry_hatching_has_killed:
max_age_poultry = poultry_hatching_has_killed.order_by('-killing_age').first()
min_age_poultry = poultry_hatching_has_killed.order_by('killing_age').first()
@@ -9335,4 +9357,200 @@ def poultry_science_for_bazresi(request):
)
serializer = PoultryScienceReportSerializer(query, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.data, status=status.HTTP_200_OK)
def archive_kill_house_remain_limitation_weight_manual(request):
production_date = (datetime.datetime.now() - datetime.timedelta(days=3)).date()
archive_date = (datetime.datetime.now() - datetime.timedelta(days=3))
kill_houses = KillHouse.objects.filter(trash=False, out_province=False)
for kill_house in kill_houses:
kill_house_requests = KillHouseRequest.objects.filter(input_warehouse=kill_house,
province_request__poultry_request__free_sale_in_province=False,
kill_request__recive_date__date=production_date,
ware_house_confirmation=True, trash=False,
calculate_status=True, warehouse=True)
kill_house_allocations = StewardAllocation.objects.filter(
kill_house=kill_house, trash=False, calculate_status=True, warehouse=True, system_registration_code=True,
receiver_state__in=('pending', 'accepted'), production_date__date=production_date, quota='governmental')
kill_house_free_sale_bars = KillHouseFreeSaleBarInformation.objects.filter(kill_house=kill_house,
quota='governmental',
production_date__date=production_date,
trash=False,
calculate_status=True,
warehouse=True)
segmentations = PosSegmentation.objects.filter(kill_house=kill_house, production_date__date=production_date,
trash=False, warehouse=True,
quota='governmental')
kill_house_requests_weight = kill_house_requests.aggregate(total=Sum('ware_house_accepted_real_weight'))[
'total'] or 0
kill_house_allocations_weight = \
kill_house_allocations.aggregate(total=Sum('real_weight_of_carcasses'))['total'] or 0
kill_house_free_sale_bars_weight = kill_house_free_sale_bars.aggregate(total=Sum('real_weight_of_carcasses'))[
'total'] or 0
segmentation_weight = \
segmentations.aggregate(total=Sum('weight'))[
'total'] or 0
archives = WarehouseArchive.objects.filter(kill_house=kill_house, date__date=production_date,
quota='governmental',
trash=False)
archives_governmental_weight = \
archives.aggregate(total=Sum('weight'))[
'total'] or 0
total_input = kill_house_requests_weight
total_output = kill_house_allocations_weight + kill_house_free_sale_bars_weight + segmentation_weight + archives_governmental_weight
total_remain = total_input - total_output
if total_remain > 0:
if kill_house.ware_house_remaining_weight_archive_percent > 0:
percent_limitation_weight = total_input * (kill_house.ware_house_remaining_weight_archive_percent / 100)
if percent_limitation_weight >= total_remain:
archive = WarehouseArchive(
kill_house=kill_house,
date=archive_date,
quota='governmental',
weight=total_remain,
registerer='سیستم',
registerer_mobile='سیستم',
registerer_role='سیستم',
description='مانده کمتر از استاندارد تعیین شده',
)
archive.save()
kill_house_archive_warehousing(archive.kill_house)
return HttpResponse('ok')
def delete_steward_allocation_manual(request):
current_time = datetime.datetime.now().date()
# allow=AllowRegisterCodeForStewardAllocation.objects.filter(trash=False,active=True).first()
# if allow:
steward_allocation = StewardAllocation.objects.filter(trash=False,
date__date=current_time,
receiver_state='pending',
active_expire_date_time=True,
logged_registration_code__isnull=True,
kill_house__isnull=False,
return_trash=False).order_by('id')
for allocation in steward_allocation:
product = allocation.product
seller_type = allocation.seller_type
to_cold_house = allocation.to_cold_house
other_cold_house = allocation.other_cold_house if allocation.other_cold_house else None
allocation.trash = True
allocation.save()
if seller_type == 'KillHouse':
kill_house_allocations_product_warehousing(product)
if to_cold_house and to_cold_house.kill_house == product.kill_house:
kill_house_cold_house_allocations(to_cold_house)
elif seller_type == 'ColdHouse':
cold_house_warehousing(to_cold_house)
if other_cold_house:
cold_house_warehousing(other_cold_house)
else:
guild_steward_allocations_product_warehousing(product)
return HttpResponse('ok')
def delete_sale_bar_manual(request):
steward_sale_bar = StewardFreeSaleBarInformation.objects.filter(trash=False, logged_registration_code__isnull=True,
system_registration_code=True,
active_expire_date_time=True,
registration_code__isnull=False)
for free_sale_bar in steward_sale_bar:
free_sale_bar.trash = True
free_sale_bar.save()
guild_steward_free_sale_product_warehousing(free_sale_bar.product)
kill_house_sale_bar = KillHouseFreeSaleBarInformation.objects.filter(trash=False,
logged_registration_code__isnull=True,
system_registration_code=True,
active_expire_date_time=True,
registration_code__isnull=False)
for free_sale_bar_kill_house in kill_house_sale_bar:
product = free_sale_bar_kill_house.product
free_sale_bar_kill_house.trash = True
free_sale_bar_kill_house.save()
kill_house_free_sale_product_warehousing(product)
def send_credit_sahandsms_sms_manual(request):
filters = {}
if base_url_for_sms_report == 'ha':
filters['username'] = 'hamedan'
elif base_url_for_sms_report == 'ku':
filters['username'] = 'kurdistan'
elif base_url_for_sms_report == 'ma':
filters['username__in'] = ['markazi', 'senfmarkazi']
managements = ManagementSendSms.objects.filter(**filters) \
.values('username') \
.annotate(min_id=Min('id')) \
.values_list('min_id', flat=True)
managements = ManagementSendSms.objects.filter(id__in=managements)
for management in managements:
r = requests.get(
f"http://webservice.sahandsms.com/newsmswebservice.asmx/GetUserCredit?username={management.username}"
f"&password={management.password}")
url = f'https://eitaayar.ir/api/{token}/sendMessage'
date = datetime.datetime.now().date()
if base_url_for_sms_report == 'ma':
province = 'مرکزی'
elif base_url_for_sms_report == 'ha':
province = 'همدان'
elif base_url_for_sms_report == 'ku':
province = 'کردستان'
elif base_url_for_sms_report == 'bu':
province = 'بوشهر'
else:
province = 'تست'
date_shamsi = shamsi_date(date).replace('-', '_')
base_message = '🗓📢❗ سامانه رصدیار، زنجیره تامین،تولید و توزیع مرغ گوشتی📢❗\n'
base_message += f' #گزارش_مانده_حساب_پنل_پیامکی #{date_shamsi}\n'
base_message += f' #استان_{province}\n\n'
base_message += f'\n'
messages = []
current_message = base_message
root = ET.fromstring(r.content)
credit_amount = int(root.text)
amount = "{:,}".format(credit_amount)
new_message_part = "🔸 نام کاربری پنل : {0} \n".format(management.username)
new_message_part += "🔸 مانده حساب پنل : {0} ریال \n".format(amount)
# new_message_part = "🔸 نام کاربری پنل {0}: {1} ریال \n".format(management.username, amount)
if credit_amount < 1000000:
new_message_part += "‼توجه: لطفا برای شارژ پنل پیامکی خود اقدام فرمایید‼"
new_message_part += '\n\n'
if len(current_message) + len(new_message_part) > 4000:
messages.append(current_message)
current_message = base_message
current_message += new_message_part
if current_message and current_message != base_message:
messages.append(current_message)
for message in messages:
data = {
'chat_id': chat_id_mali,
'text': message,
}
response = requests.post(url, data=data, verify=False)
return HttpResponse('ok')

View File

@@ -1,4 +1,5 @@
from authentication.register import add_zero_for_user_mobile
from authentication.register import add_zero_for_user_mobile, accept_bar_difference_request_pending_manual, \
canceled_out_province_request_manual
from authentication.sms_management import send_daily_slaughter_statistics_sms_manual, \
send_daily_distribution_report_sms_manual
from pdf.views import kill_request_pdf, management_all_poultry_and_warehouse_pdf, summary_report_pdf, \
@@ -57,7 +58,9 @@ from .ReportingPanel.views import check_excel, find_gid_code, fix_duplicate_guil
report_guilds_without_national_or_pos_transactions, get_guilds_for_update_or_create, \
update_all_active_guilds_from_api, find_users_with_duplicate_national_id, fix_duplicate_national_id_users, \
get_legal_person_unit_info, upload_image_to_server_for_poultry_science, poultry_science_for_bazresi, \
fetch_evacuation_details_for_unknown_hatchings
fetch_evacuation_details_for_unknown_hatchings, delete_kill_req_manual, \
archive_kill_house_remain_limitation_weight_manual, delete_steward_allocation_manual, delete_sale_bar_manual, \
send_credit_sahandsms_sms_manual
from .VetFarm.excel_processing import technical_responsible_performance_excel, \
totoal_technical_responsible_performance_excel
from .excel_processing import user_excel_update, user_excel, vet_check_excel, kill_house_request_excel, \
@@ -1392,5 +1395,12 @@ urlpatterns = [
path('fetch_evacuation_details_for_unknown_hatchings/', fetch_evacuation_details_for_unknown_hatchings),
path('kill_house_debt_report_pdf/', kill_house_debt_report_pdf),
path('send_all_bar_to_eitaa_ticket/', send_all_bar_to_eitaa_ticket),
path('delete_kill_req_manual/', delete_kill_req_manual),
path('accept_bar_difference_request_pending_manual/', accept_bar_difference_request_pending_manual),
path('archive_kill_house_remain_limitation_weight_manual/', archive_kill_house_remain_limitation_weight_manual),
path('canceled_out_province_request_manual/', canceled_out_province_request_manual),
path('delete_steward_allocation_manual/', delete_steward_allocation_manual),
path('delete_sale_bar_manual/', delete_sale_bar_manual),
path('send_credit_sahandsms_sms_manual/', send_credit_sahandsms_sms_manual),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)