Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] [IMP] sixteen_in_fourteen: Partial backport of field precompute #316

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sixteen_in_fourteen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Copyright 2024 Akretion (http://www.akretion.com).
# @author Florian Mounier <florian.mounier@akretion.com>
# 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",
Expand Down
1 change: 1 addition & 0 deletions sixteen_in_fourteen/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import base
58 changes: 58 additions & 0 deletions sixteen_in_fourteen/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2024 Akretion (http://www.akretion.com).
# @author Florian Mounier <florian.mounier@akretion.com>
# 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)
2 changes: 2 additions & 0 deletions sixteen_in_fourteen/odoo/http.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import collections.abc
from abc import ABC, abstractmethod

Expand Down
2 changes: 2 additions & 0 deletions sixteen_in_fourteen/odoo/tools/float_utils.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
Loading