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

[15.0][MIG] base_field_deprecated #585

Merged
merged 2 commits into from
Jul 2, 2023
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
Empty file.
2 changes: 2 additions & 0 deletions base_field_deprecated/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_init_hook
17 changes: 17 additions & 0 deletions base_field_deprecated/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Base Field Deprecated",
"summary": "Adds the deprecated attribute to the Odoo field model.",
"version": "15.0.1.0.0",
"category": "Usability",
"license": "AGPL-3",
"website": "https://github.com/OCA/server-ux",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"depends": ["base"],
"data": ["views/ir_model_fields_views.xml"],
"maintainers": ["GuillemCForgeFlow"],
"installable": True,
"application": False,
"post_init_hook": "post_init_hook",
}
22 changes: 22 additions & 0 deletions base_field_deprecated/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from odoo import SUPERUSER_ID, api


def post_init_hook(cr, registry):
"""
Set deprecated value for all existing fields
"""
env = api.Environment(cr, SUPERUSER_ID, {})

model_obj = env["ir.model"]
field_obj = env["ir.model.fields"]
for model in model_obj.search([]):
all_fields = model._fields.items()
for field_name, field in all_fields:
# Only assign for deprecated fields to avoid too many useless searches
to_assign = bool(field.deprecated)
if to_assign:
odoo_field = field_obj.search(
[("name", "=", field_name), ("model", "=", model._name)], limit=1
)
if odoo_field:
odoo_field.write({"deprecated": to_assign})
1 change: 1 addition & 0 deletions base_field_deprecated/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import ir_model_fields
12 changes: 12 additions & 0 deletions base_field_deprecated/models/ir_model_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import fields, models


class IrModelFields(models.Model):
_inherit = "ir.model.fields"

deprecated = fields.Boolean(help="Whether the field is deprecated or not.")

def _reflect_field_params(self, field, model_id):
result = super()._reflect_field_params(field, model_id)
result["deprecated"] = bool(field.deprecated)
return result
3 changes: 3 additions & 0 deletions base_field_deprecated/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `ForgeFlow S.L. <https://www.forgeflow.com>`_:

* Guillem Casassas <guillem.casassas@forgeflow.com>
2 changes: 2 additions & 0 deletions base_field_deprecated/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module adds the deprecated field to the Odoo field itself based on the value set to the Python field.
This can be useful to determine which are the declared deprecated fields in a fast way.
4 changes: 4 additions & 0 deletions base_field_deprecated/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#. By setting **deprecated=True** to a declared field, the Odoo field will inherit the value and it will be stored at the database level.
#. For instance:
#. If we have the following field: test_field = fields.Boolean(deprecated=True).
#. By looking at the instance that saves the information of the Python field on the **ir.model.fields** model, the deprecated attribute will be set there, just like copied, store, computed, among others.
37 changes: 37 additions & 0 deletions base_field_deprecated/views/ir_model_fields_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_model_fields_tree" model="ir.ui.view">
<field name="name">ir.model.fields.tree - base_field_deprecated</field>
<field name="model">ir.model.fields</field>
<field name="inherit_id" ref="base.view_model_fields_tree" />
<field name="arch" type="xml">
<field name="readonly" position="after">
<field name="deprecated" />
</field>
</field>
</record>
<record id="view_model_fields_form" model="ir.ui.view">
<field name="name">ir.model.fields.form - base_field_deprecated</field>
<field name="model">ir.model.fields</field>
<field name="inherit_id" ref="base.view_model_fields_form" />
<field name="arch" type="xml">
<field name="copied" position="after">
<field name="deprecated" groups="base.group_no_one" />
</field>
</field>
</record>
<record id="view_model_fields_search" model="ir.ui.view">
<field name="name">ir.model.fields.search - base_field_deprecated</field>
<field name="model">ir.model.fields</field>
<field name="inherit_id" ref="base.view_model_fields_search" />
<field name="arch" type="xml">
<filter name="readonly" position="after">
<filter
string="Deprecated"
name="deprecated"
domain="[('deprecated', '=', True)]"
/>
</filter>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/base_field_deprecated/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)