mirror of
https://gitlab.com/flectra-community/server-ux.git
synced 2024-11-23 22:52:07 +00:00
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
# Copyright 2020 ForgeFlow S.L.
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
|
|
import json
|
|
|
|
from flectra import api, tools
|
|
|
|
from flectra.addons.base.models.ir_default import IrDefault
|
|
|
|
|
|
def post_load_hook():
|
|
@api.model
|
|
@tools.ormcache("self.env.uid", "model_name", "condition")
|
|
def new_get_model_defaults(self, model_name, condition=False):
|
|
if not hasattr(self, "_get_model_defaults_query_and_params"):
|
|
return self.get_model_defaults_original(model_name, condition=condition)
|
|
cr = self.env.cr
|
|
# START OF CHANGES
|
|
query, params = self._get_model_defaults_query_and_params(model_name, condition)
|
|
# END OF CHANGES
|
|
cr.execute(query, params)
|
|
result = {}
|
|
for row in cr.fetchall():
|
|
# keep the highest priority default for each field
|
|
if row[0] not in result:
|
|
result[row[0]] = json.loads(row[1])
|
|
return result
|
|
|
|
if not hasattr(IrDefault, "get_model_defaults_original"):
|
|
IrDefault.get_model_defaults_original = IrDefault.get_model_defaults
|
|
|
|
IrDefault._patch_method("get_model_defaults", new_get_model_defaults)
|