[PRF] sale*: avoid useless recomputations

By default, a related field dependencies are the fields in his relation 
path.
But for non stored UX fields, the field should only be recomputed when
values editable in the view are edited.

Example:

On a given model:

product_id = fields.Many2one(...)
product_type = fields.Char(related='product_id.type')

The product_id field can be changed on the model view, but not the 
linked product,
so there is no need for the orm to search records whose product_type 
must be invalidated
when the type is changed on a product.

To avoid this 'useless' search, we can manually restrict the field 
dependencies:

product_type = fields.Char(related='product_id.type', 
depends=['product_id'])

Part-of: odoo/odoo#98068
This commit is contained in:
Victor Feyens
2022-09-01 19:16:49 +02:00
parent bf55e1a7ea
commit db9dd568bd
3 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ class SaleOrderLine(models.Model):
string="Product Template",
related='product_id.product_tmpl_id',
domain=[('sale_ok', '=', True)])
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id')
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id', depends=['product_id'])
product_custom_attribute_value_ids = fields.One2many(
comodel_name='product.attribute.custom.value', inverse_name='sale_order_line_id',
@@ -9,6 +9,8 @@ class SaleOrderLine(models.Model):
is_configurable_product = fields.Boolean(
string="Is the product configurable?",
related='product_template_id.has_configurable_attributes')
related='product_template_id.has_configurable_attributes',
depends=['product_id'])
product_template_attribute_value_ids = fields.Many2many(
related='product_id.product_template_attribute_value_ids')
related='product_id.product_template_attribute_value_ids',
depends=['product_id'])
+1 -1
View File
@@ -15,7 +15,7 @@ class SaleOrderLine(models.Model):
qty_delivered_method = fields.Selection(selection_add=[('stock_move', 'Stock Moves')])
route_id = fields.Many2one('stock.route', string='Route', domain=[('sale_selectable', '=', True)], ondelete='restrict', check_company=True)
move_ids = fields.One2many('stock.move', 'sale_line_id', string='Stock Moves')
product_type = fields.Selection(related='product_id.detailed_type')
product_type = fields.Selection(related='product_id.detailed_type', depends=['product_id'])
virtual_available_at_date = fields.Float(compute='_compute_qty_at_date', digits='Product Unit of Measure')
scheduled_date = fields.Datetime(compute='_compute_qty_at_date')
forecast_expected_date = fields.Datetime(compute='_compute_qty_at_date')