fix - link ranchers repeatedly on every cooperative on one city
This commit is contained in:
@@ -38,30 +38,32 @@ class Command(BaseCommand):
|
||||
|
||||
processed += 1
|
||||
|
||||
# اگر قبلاً لینک داره
|
||||
if RancherOrganizationLink.objects.filter(rancher=rancher).exists():
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
orgs = Organization.objects.filter(
|
||||
city=rancher.city,
|
||||
type__key='CO' # ⚠️ کد type تعاونی خودت
|
||||
orgs = list(
|
||||
Organization.objects.filter(
|
||||
city=rancher.city,
|
||||
type__key='CO'
|
||||
)
|
||||
)
|
||||
|
||||
if not orgs.exists():
|
||||
if not orgs:
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
if orgs.count() > 1:
|
||||
ambiguous += 1
|
||||
continue
|
||||
|
||||
buffer.append(
|
||||
RancherOrganizationLink(
|
||||
rancher=rancher,
|
||||
organization=orgs.first()
|
||||
for org in orgs:
|
||||
buffer.append(
|
||||
RancherOrganizationLink(
|
||||
rancher=rancher,
|
||||
organization=org
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if len(orgs) > 1:
|
||||
ambiguous += 1
|
||||
|
||||
print(len(buffer))
|
||||
if len(buffer) >= self.BATCH_SIZE:
|
||||
created += self.bulk_create(buffer)
|
||||
|
||||
Reference in New Issue
Block a user