[FIX] mrp: avoid MemoryError in _get_orderpoint_products
`super()._get_orderpoint_products()` returns more than 1 million products. Applying _bom_find to all of them is too much. https://github.com/odoo/odoo/blob/55e327705deed2aa31c1fc9eca49a8a66135c020/addons/stock/models/stock_orderpoint.py#L567-L568 Issue observer on menu Inventory > Operations > Replenishment during upgrades to 16.0 closes odoo/odoo#109311 X-original-commit: 263cb8eafb3ac0db5cb950e66dba3c924e52f187 Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com> Signed-off-by: Alvaro Fuentes Suarez (afu) <afu@odoo.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
from odoo.tools import split_every
|
||||
|
||||
|
||||
class StockWarehouse(models.Model):
|
||||
@@ -308,6 +309,9 @@ class Orderpoint(models.Model):
|
||||
raise ValidationError(_("A product with a kit-type bill of materials can not have a reordering rule."))
|
||||
|
||||
def _get_orderpoint_products(self):
|
||||
products = super()._get_orderpoint_products()
|
||||
kit_products = self.env['mrp.bom']._bom_find(products, bom_type='phantom').keys()
|
||||
return products.filtered(lambda p: p not in kit_products)
|
||||
non_kit_ids = []
|
||||
for products in split_every(2000, super()._get_orderpoint_products().ids, self.env['product.product'].browse):
|
||||
kit_ids = set(k.id for k in self.env['mrp.bom']._bom_find(products, bom_type='phantom').keys())
|
||||
non_kit_ids.extend(id_ for id_ in products.ids if id_ not in kit_ids)
|
||||
products.invalidate_recordset()
|
||||
return self.env['product.product'].browse(non_kit_ids)
|
||||
|
||||
Reference in New Issue
Block a user