This branch is the combination of several optimizations in the ORM: * store field values once in the cache: the cache reflects more faithfully the database, only fields that explicitly depend on the context have an extra indirection in the cache; * delay recomputations by default: use method `recompute` to explicitly flush out pending recomputations; * delay updates in method `write`: updates are stored in a data structure that can be flushed efficiently to the database with method `flush` (which also flush out recomputations); * make method `modified` take advantage of inverse fields to inverse dependencies; * filter records by evaluating a domain on records in Python; * a computed field with `readonly=False` behaves like a normal field with an onchange method; * computed fields are computed in superuser mode by default. Work done by Toufik Ben Jaa, Raphael Collet, Denis Ledoux and Fabien Pinckaers. closes odoo/odoo#35659 Signed-off-by: Denis Ledoux <beledouxdenis@users.noreply.github.com>
24 lines
1.0 KiB
Python
24 lines
1.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import fields, models, api, SUPERUSER_ID
|
|
|
|
|
|
class UtmCampaign(models.Model):
|
|
_inherit = ['utm.campaign']
|
|
_description = 'UTM Campaign'
|
|
|
|
items_total = fields.Integer(string="Number of items that are part of the campaign", compute="_compute_items_total")
|
|
clicked_total = fields.Integer(string="Number of items that are part of the campaign who generated a click", compute="_compute_items_total")
|
|
clicks_ratio = fields.Integer(string="Global Clicks Ratio for the campaign", compute="_compute_clicks_ratio")
|
|
|
|
def _compute_items_total(self):
|
|
"""Empty method that will be implemented by inheriting classes"""
|
|
self.clicked_total = False
|
|
self.items_total = False
|
|
|
|
@api.depends('items_total', 'clicked_total')
|
|
def _compute_clicks_ratio(self):
|
|
for campaign in self:
|
|
campaign.clicks_ratio = campaign.clicked_total / campaign.items_total * 100 if campaign.items_total > 0 else 0
|