[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.
This commit is contained in:
Olivier Dony 2016-03-04 19:15:27 +01:00
parent 40fdb841ae
commit 9804c54634
1 changed files with 2 additions and 9 deletions

View File

@ -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'),