fix - link ranchers repeatedly on every cooperative on one city

This commit is contained in:
2026-01-04 09:09:01 +03:30
parent ddbd3aa6d4
commit 43b0d0b4ea

View File

@@ -38,30 +38,32 @@ class Command(BaseCommand):
processed += 1 processed += 1
# اگر قبلاً لینک داره
if RancherOrganizationLink.objects.filter(rancher=rancher).exists(): if RancherOrganizationLink.objects.filter(rancher=rancher).exists():
skipped += 1 skipped += 1
continue continue
orgs = Organization.objects.filter( orgs = list(
city=rancher.city, Organization.objects.filter(
type__key='CO' # ⚠️ کد type تعاونی خودت city=rancher.city,
type__key='CO'
)
) )
if not orgs.exists(): if not orgs:
skipped += 1 skipped += 1
continue continue
if orgs.count() > 1: for org in orgs:
ambiguous += 1 buffer.append(
continue RancherOrganizationLink(
rancher=rancher,
buffer.append( organization=org
RancherOrganizationLink( )
rancher=rancher,
organization=orgs.first()
) )
)
if len(orgs) > 1:
ambiguous += 1
print(len(buffer)) print(len(buffer))
if len(buffer) >= self.BATCH_SIZE: if len(buffer) >= self.BATCH_SIZE:
created += self.bulk_create(buffer) created += self.bulk_create(buffer)