[IMP] purchase_stock: add ir_config_parameter to on_time_rate comp.
On-time-rate is a non-stored computed fields that can take some time to load because some partners may have lots of related purchase_orders. The compute function in itself is relatively difficult to optimize further. This commit introduces a new system parameter to reduce the timerange of orders to consider when computing On-Time Delivery Rate. That way, if for some customers the on_time_rate computation takes too much time (leading to a slow FormView loading), they can reduce the accuracy of the estimation to speedup the field's computation. closes odoo/odoo#128199 X-original-commit: 2e766f11024e9bb905f8e98d7218cf924c43a0c9 Signed-off-by: William Henrotin (whe) <whe@odoo.com> Signed-off-by: Aurélien van Delft (avd) <avd@odoo.com>
This commit is contained in:
@@ -13,13 +13,15 @@ class ResPartner(models.Model):
|
||||
purchase_line_ids = fields.One2many('purchase.order.line', 'partner_id', string="Purchase Lines")
|
||||
on_time_rate = fields.Float(
|
||||
"On-Time Delivery Rate", compute='_compute_on_time_rate',
|
||||
help="Over the past 12 months; the number of products received on time divided by the number of ordered products.")
|
||||
help="Over the past x days; the number of products received on time divided by the number of ordered products."\
|
||||
"x is either the System Parameter purchase_stock.on_time_delivery_days or the default 365")
|
||||
|
||||
@api.depends('purchase_line_ids')
|
||||
def _compute_on_time_rate(self):
|
||||
date_order_days_delta = int(self.env['ir.config_parameter'].sudo().get_param('purchase_stock.on_time_delivery_days', default='365'))
|
||||
order_lines = self.env['purchase.order.line'].search([
|
||||
('partner_id', 'in', self.ids),
|
||||
('date_order', '>', fields.Date.today() - timedelta(365)),
|
||||
('date_order', '>', fields.Date.today() - timedelta(date_order_days_delta)),
|
||||
('qty_received', '!=', 0),
|
||||
('order_id.state', 'in', ['done', 'purchase']),
|
||||
('product_id', 'in', self.env['product.product'].sudo()._search([('type', '!=', 'service')]))
|
||||
|
||||
Reference in New Issue
Block a user