diff --git a/sixteen_in_fourteen/__init__.py b/sixteen_in_fourteen/__init__.py index 2d9a1d69..69621bde 100644 --- a/sixteen_in_fourteen/__init__.py +++ b/sixteen_in_fourteen/__init__.py @@ -1,7 +1,13 @@ +# Copyright 2024 Akretion (http://www.akretion.com). +# @author Florian Mounier +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + import sys import importlib from contextlib import contextmanager +from . import models # noqa: F401 + MOVED_MODULES = { "odoo.addons.sale.models.sale_order_line": "odoo.addons.sale.models.sale", "odoo.addons.sale.models.sale_order": "odoo.addons.sale.models.sale", diff --git a/sixteen_in_fourteen/models/__init__.py b/sixteen_in_fourteen/models/__init__.py new file mode 100644 index 00000000..0e444493 --- /dev/null +++ b/sixteen_in_fourteen/models/__init__.py @@ -0,0 +1 @@ +from . import base diff --git a/sixteen_in_fourteen/models/base.py b/sixteen_in_fourteen/models/base.py new file mode 100644 index 00000000..626ab7cb --- /dev/null +++ b/sixteen_in_fourteen/models/base.py @@ -0,0 +1,58 @@ +# Copyright 2024 Akretion (http://www.akretion.com). +# @author Florian Mounier +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# Backport is part of Odoo. See LICENSE file for full copyright and licensing details. + + +from odoo import api, models + + +class Base(models.AbstractModel): + _inherit = "base" + + def _add_precomputed_values(self, vals_list): + """PARTIAL BACKPORT FROM ODOO 16 + + It backports the precompute feature on create but does not + do all sanity checks that are done in Odoo 16. + It does not work with inverse fields yet. + + -- + + Add missing precomputed fields to ``vals_list`` values. + Only applies for precompute=True fields. + + :param dict vals_list: list(dict) of create values + """ + precomputable = { + fname: field + for fname, field in self._fields.items() + if getattr(field, "precompute", False) and not field.inverse + } + if not precomputable: + return + + # determine which vals must be completed + vals_list_todo = [ + vals + for vals in vals_list + if any(fname not in vals for fname in precomputable) + ] + if not vals_list_todo: + return + + # create new records for the vals that must be completed + records = self.browse().concat(*(self.new(vals) for vals in vals_list_todo)) + + for record, vals in zip(records, vals_list_todo): + for fname, field in precomputable.items(): + if fname not in vals: + # computed stored fields with a column + # have to be computed before create + # s.t. required and constraints can be applied on those fields. + vals[fname] = field.convert_to_write(record[fname], self) + + @api.model_create_multi + def create(self, vals_list): + self._add_precomputed_values(vals_list) + return super().create(vals_list) diff --git a/sixteen_in_fourteen/odoo/http.py b/sixteen_in_fourteen/odoo/http.py index 11f3ef56..e585ddc4 100644 --- a/sixteen_in_fourteen/odoo/http.py +++ b/sixteen_in_fourteen/odoo/http.py @@ -1,3 +1,5 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + import collections.abc from abc import ABC, abstractmethod diff --git a/sixteen_in_fourteen/odoo/tools/float_utils.py b/sixteen_in_fourteen/odoo/tools/float_utils.py index 1533645b..ea33e98f 100644 --- a/sixteen_in_fourteen/odoo/tools/float_utils.py +++ b/sixteen_in_fourteen/odoo/tools/float_utils.py @@ -1,3 +1,5 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + from odoo.tools.float_utils import float_repr, float_round