Skip to content

Commit

Permalink
add offset and limit
Browse files Browse the repository at this point in the history
  • Loading branch information
kanda999 authored and AungKoKoLin1997 committed Oct 18, 2023
1 parent caba0bf commit 2c142b6
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions data_migration/models/partner_data_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,33 @@ def _run_partner_data_migration(self):
"gender",
]
instance, uid_v11, models_v11 = self._data_migration_authentication()
partners_v11 = models_v11.execute_kw(
instance.instance_db,
uid_v11,
instance.password,
"res.partner",
"search_read",
[],
{"fields": required_fields},
)
top_level_partners = [
partner for partner in partners_v11 if not partner.get("parent_id")
]
child_partners = [
partner for partner in partners_v11 if partner.get("parent_id")
]
offset = 0
limit = 1000
while True:
partners_v11 = models_v11.execute_kw(
instance.instance_db,
uid_v11,
instance.password,
"res.partner",
"search_read",
[],
{"fields": required_fields, "offset": offset, "limit": limit},
)
if not partners_v11:
break
top_level_partners = [
partner for partner in partners_v11 if not partner.get("parent_id")
]
child_partners = [
partner for partner in partners_v11 if partner.get("parent_id")
]
offset += limit

for partner in top_level_partners:
self.with_delay()._process_partner_migration(partner, is_child=False)
for partner in top_level_partners:
self.with_delay()._process_partner_migration(partner, is_child=False)

for partner in child_partners:
self.with_delay()._process_partner_migration(partner, is_child=True)
for partner in child_partners:
self.with_delay()._process_partner_migration(partner, is_child=True)

def _process_partner_migration(self, partner, is_child=False):
env = api.Environment(self.env.cr, SUPERUSER_ID, {})
Expand Down

0 comments on commit 2c142b6

Please sign in to comment.