Skip to content

Commit

Permalink
Merge pull request #316 from akretion/14.0-imp-sixteen_in_fourteen-pr…
Browse files Browse the repository at this point in the history
…ecompute

[14.0] [IMP] sixteen_in_fourteen: Partial backport of field precompute
  • Loading branch information
paradoxxxzero authored Oct 18, 2024
2 parents 1e3e5f2 + a26fe18 commit b0d261d
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
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 <[email protected]>
# 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 <[email protected]>
# 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

0 comments on commit b0d261d

Please sign in to comment.