import - sync_livestock/herd_rancher_sync/purchase_policy & service_area in organization
This commit is contained in:
@@ -31,7 +31,7 @@ class Command(BaseCommand):
|
||||
processed = 0
|
||||
start_time = time.time()
|
||||
|
||||
LOG_EVERY = 10_000 # هر چند رکورد لاگ بده
|
||||
LOG_EVERY = 10000
|
||||
|
||||
buffer = []
|
||||
for temp in qs.iterator(chunk_size=CHUNK_SIZE):
|
||||
@@ -63,8 +63,6 @@ class Command(BaseCommand):
|
||||
|
||||
self.stdout.write(self.style.SUCCESS("DONE ✅"))
|
||||
|
||||
# ----------------------------------------------------
|
||||
|
||||
def process_batch(self, temps):
|
||||
herd_codes = {t.herd_code for t in temps if t.herd_code}
|
||||
|
||||
@@ -103,7 +101,7 @@ class Command(BaseCommand):
|
||||
for temp in temps:
|
||||
herd = herds.get(temp.herd_code)
|
||||
if not herd:
|
||||
continue # گله باید وجود داشته باشد
|
||||
continue
|
||||
|
||||
birthdate = parse_birthdate(temp.birthdate)
|
||||
gender = 1 if temp.gender == 'M' else 2
|
||||
@@ -113,7 +111,6 @@ class Command(BaseCommand):
|
||||
key = (temp.herd_code, birthdate, gender)
|
||||
livestock = livestock_map.get(key)
|
||||
|
||||
# ---------- دام وجود ندارد ----------
|
||||
if not livestock:
|
||||
if not temp.tag:
|
||||
continue
|
||||
@@ -139,7 +136,6 @@ class Command(BaseCommand):
|
||||
temp.sync_status = 'S'
|
||||
continue
|
||||
|
||||
# ---------- دام وجود دارد ولی پلاک ندارد ----------
|
||||
if livestock.tag is None and temp.tag:
|
||||
tag = existing_tags.get(temp.tag)
|
||||
|
||||
@@ -153,7 +149,6 @@ class Command(BaseCommand):
|
||||
|
||||
temp.sync_status = 'S'
|
||||
|
||||
# ---------- BULK ----------
|
||||
with transaction.atomic():
|
||||
Tag.objects.bulk_create(new_tags, batch_size=BATCH_SIZE)
|
||||
LiveStock.objects.bulk_create(
|
||||
|
||||
Reference in New Issue
Block a user