[IMP] mrp, stock, stock_account: compute stored fields trigger
This is a performance revision. Some stored functions field were recomputed uselessly. In mrp, `hour_total` and `cycle_total` were recomputed at each write on `mrp.production`, while they should be recomputed only when there is a change on the `workcenter_lines` field, or when there is a change in the `hour` or `cycle` field of these `workcenter_lines`. In stock, `min_date`, `max_date` and `priority` of `stock.picking` were recomputed each time a new move was added to the picking, wether or not the 'expected_date' of this move was between the `stock.picking` `min_date` and `max_date`, and the priority not greater. In stock, `product_qty` of `stock.move` was recomputed at each write on the `stock.move`, while it should be recomputed only when there is a change in `product_id`, `product_uom` or `product_uom_qty`, as the computation method only depends on these three fields. In stock_account, the `invoice_state` of `stock.picking` was recomputed each time a new `stock.move` was associated to the picking, wether or not the `invoice_state` of the move was already the same than the `invoice_state` of the picking. opw-643560
This commit is contained in:
parent
95f49eadc1
commit
279f225cf0
|
@ -497,6 +497,12 @@ class mrp_production(osv.osv):
|
|||
result[prod.id]['cycle_total'] += wc.cycle
|
||||
return result
|
||||
|
||||
def _get_workcenter_line(self, cr, uid, ids, context=None):
|
||||
result = {}
|
||||
for line in self.pool['mrp.production.workcenter.line'].browse(cr, uid, ids, context=context):
|
||||
result[line.production_id.id] = True
|
||||
return result.keys()
|
||||
|
||||
def _src_id_default(self, cr, uid, ids, context=None):
|
||||
try:
|
||||
location_model, location_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_stock')
|
||||
|
@ -595,8 +601,14 @@ class mrp_production(osv.osv):
|
|||
If the stock is available then the status is set to 'Ready to Produce'.\n\
|
||||
When the production gets started then the status is set to 'In Production'.\n\
|
||||
When the production is over, the status is set to 'Done'."),
|
||||
'hour_total': fields.function(_production_calc, type='float', string='Total Hours', multi='workorder', store=True),
|
||||
'cycle_total': fields.function(_production_calc, type='float', string='Total Cycles', multi='workorder', store=True),
|
||||
'hour_total': fields.function(_production_calc, type='float', string='Total Hours', multi='workorder', store={
|
||||
_name: (lambda self, cr, uid, ids, c={}: ids, ['workcenter_lines'], 40),
|
||||
'mrp.production.workcenter.line': (_get_workcenter_line, ['hour', 'cycle'], 40),
|
||||
}),
|
||||
'cycle_total': fields.function(_production_calc, type='float', string='Total Cycles', multi='workorder', store={
|
||||
_name: (lambda self, cr, uid, ids, c={}: ids, ['workcenter_lines'], 40),
|
||||
'mrp.production.workcenter.line': (_get_workcenter_line, ['hour', 'cycle'], 40),
|
||||
}),
|
||||
'user_id': fields.many2one('res.users', 'Responsible'),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
'ready_production': fields.function(_moves_assigned, type='boolean', store={'stock.move': (_mrp_from_move, ['state'], 10)}),
|
||||
|
|
|
@ -752,7 +752,7 @@ class stock_picking(osv.osv):
|
|||
def _get_pickings(self, cr, uid, ids, context=None):
|
||||
res = set()
|
||||
for move in self.browse(cr, uid, ids, context=context):
|
||||
if move.picking_id:
|
||||
if move.picking_id and (not (move.picking_id.min_date < move.date_expected < move.picking_id.max_date) or move.priority > move.picking_id.priority):
|
||||
res.add(move.picking_id.id)
|
||||
return list(res)
|
||||
|
||||
|
@ -1739,7 +1739,9 @@ class stock_move(osv.osv):
|
|||
'date': fields.datetime('Date', required=True, select=True, help="Move date: scheduled date until move is done, then date of actual move processing", states={'done': [('readonly', True)]}),
|
||||
'date_expected': fields.datetime('Expected Date', states={'done': [('readonly', True)]}, required=True, select=True, help="Scheduled date for the processing of this move"),
|
||||
'product_id': fields.many2one('product.product', 'Product', required=True, select=True, domain=[('type', '<>', 'service')], states={'done': [('readonly', True)]}),
|
||||
'product_qty': fields.function(_quantity_normalize, fnct_inv=_set_product_qty, type='float', digits=0, store=True, string='Quantity',
|
||||
'product_qty': fields.function(_quantity_normalize, fnct_inv=_set_product_qty, type='float', digits=0, store={
|
||||
_name: (lambda self, cr, uid, ids, c={}: ids, ['product_id', 'product_uom', 'product_uom_qty'], 40),
|
||||
}, string='Quantity',
|
||||
help='Quantity in the default UoM of the product'),
|
||||
'product_uom_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'),
|
||||
required=True, states={'done': [('readonly', True)]},
|
||||
|
|
|
@ -200,7 +200,7 @@ class stock_picking(osv.osv):
|
|||
def __get_picking_move(self, cr, uid, ids, context={}):
|
||||
res = []
|
||||
for move in self.pool.get('stock.move').browse(cr, uid, ids, context=context):
|
||||
if move.picking_id:
|
||||
if move.picking_id and move.invoice_state != move.picking_id.invoice_state:
|
||||
res.append(move.picking_id.id)
|
||||
return res
|
||||
|
||||
|
|
Loading…
Reference in New Issue