[FIX] product_expiry: fix MemoryError on module installation.
In large databases with > 2M stock_move_lines, installing the product_expiry module can raise a MemoryError because the field_cache is overfilled by the computation of the expiration_date computed stored field. Adding an _auto_init for this field prevent such errors from being raised by creating the column manually. closes odoo/odoo#116456 X-original-commit: 8b82d3154858582f6d321bd6473557fc192af25f Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
import datetime
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.tools.sql import column_exists, create_column
|
||||
|
||||
|
||||
class StockMoveLine(models.Model):
|
||||
@@ -17,6 +18,16 @@ class StockMoveLine(models.Model):
|
||||
use_expiration_date = fields.Boolean(
|
||||
string='Use Expiration Date', related='product_id.use_expiration_date')
|
||||
|
||||
def _auto_init(self):
|
||||
""" Create column for 'expiration_date' here to avoid MemoryError when letting
|
||||
the ORM compute it after module installation. Since both 'lot_id.expiration_date'
|
||||
and 'product_id.use_expiration_date' are new fields introduced in this module,
|
||||
there is no need for an UPDATE statement here.
|
||||
"""
|
||||
if not column_exists(self._cr, "stock_move_line", "expiration_date"):
|
||||
create_column(self._cr, "stock_move_line", "expiration_date", "timestamp")
|
||||
return super()._auto_init()
|
||||
|
||||
@api.depends('product_id', 'picking_type_use_create_lots', 'lot_id.expiration_date')
|
||||
def _compute_expiration_date(self):
|
||||
for move_line in self:
|
||||
|
||||
Reference in New Issue
Block a user