I need to fix an issue where a lot of products don't have reordering rules. I just need the default values on all the rules. I wrote this server action to automatically create a reordering rule for any product that didn't already have one:
products = env['product.product'].search([('type','!=','consu')])
loop_count = len(products)
count = 0
to_create = []
for product in products:
product._compute_nbr_reordering_rules() # we have to do this manually here because it won't calculate on it's own
if product.nbr_reordering_rules == 0:
to_create.append({'product_id':product.id})
count += 1
env['stock.warehouse.orderpoint'].create(to_create)
log('Created ' + str(count) + ' new reorder rules. Searched ' +str(loop_count) +' records', level='info')
It works perfectly on my test database with only a few products. However, when I ran the same thing on a copy of the production data, it loaded for ~15 minutes (expected with how many records there are and the complexity of my loop), then no records were created. I checked the log after running and this was the message:
Created 28622 new reorder rules. Searched 30883 records
So it looks like it at least tried to make all the records, but ultimately failed as nothing ended up in the database. Is there anything that I missed when working with such a large amount of records?