From 9804c54634cc9a30c6f40fed55c0f0ee32af3c65 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 4 Mar 2016 19:15:27 +0100 Subject: [PATCH] [FIX] product_expiry: performance issues due to extra write() call When creating thousands of production lots in batch, the extra call to write() cuts performance in 2, and can be replaced by an appropriate context when calling super(), as all the default values are computed correctly. The only case that could possibly fail is when the product_id is not passed to the create() call but comes instead from defaut values (ir.values). This case is very rare and considered a manual exception where the expiry dates can be input manually. --- addons/product_expiry/product_expiry.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/addons/product_expiry/product_expiry.py b/addons/product_expiry/product_expiry.py index 4b52d9bf3b6..d24640f85ed 100644 --- a/addons/product_expiry/product_expiry.py +++ b/addons/product_expiry/product_expiry.py @@ -57,16 +57,9 @@ class stock_production_lot(osv.osv): } # Assign dates according to products data def create(self, cr, uid, vals, context=None): - newid = super(stock_production_lot, self).create(cr, uid, vals, context=context) - obj = self.browse(cr, uid, newid, context=context) - towrite = [] - for f in ('life_date', 'use_date', 'removal_date', 'alert_date'): - if not getattr(obj, f): - towrite.append(f) context = dict(context or {}) - context['product_id'] = obj.product_id.id - self.write(cr, uid, [obj.id], self.default_get(cr, uid, towrite, context=context)) - return newid + context['product_id'] = vals.get('product_id', context.get('default_product_id')) + return super(stock_production_lot, self).create(cr, uid, vals, context=context) _defaults = { 'life_date': _get_date('life_time'),