Skip to content

Instantly share code, notes, and snippets.

@moylop260
Last active May 9, 2024 01:35
Show Gist options
  • Save moylop260/c4ae432f2f8ae72b94fcc3bb1a3dc419 to your computer and use it in GitHub Desktop.
Save moylop260/c4ae432f2f8ae72b94fcc3bb1a3dc419 to your computer and use it in GitHub Desktop.
import threading
import odoo
def create_partner_batch(env, partner_parent_id, start_index, end_index):
for i in range(start_index, end_index):
value = {
"name": "test %d" % i,
"type": "delivery"
}
children = env["res.partner"].create(value)
env.cr.commit()
# total_partners = 555555
total_partners = 555555
# threads = 25
threads = 50
# Dividir el trabajo en lotes
batch_size = total_partners // threads
partner_parent = self.env["res.partner"].create({"name": "big family partner", "type": "contact"})
self.env.cr.commit()
thread_list = []
for i in range(threads):
start_index = i * batch_size
end_index = (i + 1) * batch_size
new_cr = self.env.registry.cursor()
new_env = odoo.api.Environment(new_cr, self.env.uid, self.env.context)
thread = threading.Thread(target=create_partner_batch, args=(new_env, partner_parent.id, start_index, end_index))
thread_list.append(thread)
thread.start()
for thread in thread_list:
thread.join()
self.env["res.partner"].search([("id", ">", partner_parent.id), ("parent_id", "=", False)]).write({"parent_id": partner_parent.id})
self.env.cr.commit()
# result = partner_parent.address_get(['delivery', 'invoice'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment