Skip to content
New issue

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

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

Already on GitHub? # to your account

[IMP] simplify kanban archs #121

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
100 changes: 100 additions & 0 deletions odoo_module_migrate/migration_scripts/migrate_170_180.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,108 @@ def replace_user_has_groups(
logger.error(f"Error processing file {file}: {str(e)}")


def remove_deprecated_kanban_click_classes(
logger, module_path, module_name, manifest_path, migration_steps, tools
):
files_to_process = tools.get_files(module_path, (".xml",))

replaces = {
"oe_kanban_global_click_edit": "",
"oe_kanban_global_click": "",
}

for file in files_to_process:
try:
tools._replace_in_file(
file,
replaces,
log_message=f"Remove deprecated kanban click classes in file: {file}",
)
except Exception as e:
logger.error(f"Error processing file {file}: {str(e)}")


def replace_kanban_color_picker_widget(
logger, module_path, module_name, manifest_path, migration_steps, tools
):
files_to_process = tools.get_files(module_path, (".xml",))

replaces = {
# Case 1: Match any ul tag containing both oe_kanban_colorpicker class and data-field
# Example: <ul class="oe_kanban_colorpicker some-class" data-field="color" some-attr="value"/>
# Example: <ul data-field="color" t-if="condition" class="oe_kanban_colorpicker other-class"/>
r'<ul[^>]*?class="[^"]*?oe_kanban_colorpicker[^"]*?"[^>]*?data-field="([^"]+)"[^>]*?>(?:</ul>)?': r'<field name="\1" widget="kanban_color_picker"/>',
# Case 2: Same as Case 1 but with data-field appearing before class
# Example: <ul data-field="color" class="some-class oe_kanban_colorpicker" some-attr="value"/>
# Example: <ul some-attr="value" data-field="color" class="oe_kanban_colorpicker"/>
r'<ul[^>]*?data-field="([^"]+)"[^>]*?class="[^"]*?oe_kanban_colorpicker[^"]*?"[^>]*?>(?:</ul>)?': r'<field name="\1" widget="kanban_color_picker"/>',
}

for file in files_to_process:
try:
tools._replace_in_file(
file,
replaces,
log_message=f"Replace kanban colorpicker with field widget in file: {file}",
)
except Exception as e:
logger.error(f"Error processing file {file}: {str(e)}")


def remove_kanban_tooltip(
logger, module_path, module_name, manifest_path, migration_steps, tools
):
files_to_process = tools.get_files(module_path, (".xml",))
reg_tooltip_template = (
r"""<t\s+t-name=["']kanban-tooltip["'][^>]*>[\s\S]*?</t>\s*"""
)
reg_tooltip_attr = r"""\s+tooltip=["']kanban-tooltip["']"""

replaces = {
reg_tooltip_template: "",
reg_tooltip_attr: "",
}

for file in files_to_process:
try:
tools._replace_in_file(
file,
replaces,
log_message=f"Removed kanban tooltip feature in file: {file}",
)
except Exception as e:
logger.error(f"Error processing file {file}: {str(e)}")


def replace_type_edit(
logger, module_path, module_name, manifest_path, migration_steps, tools
):
"""Replace type='edit' with type='open' in elements."""
files_to_process = tools.get_files(module_path, (".xml",))

reg_type_edit = r"""type=["']edit["']"""

replaces = {
reg_type_edit: 'type="open"',
}

for file in files_to_process:
try:
tools._replace_in_file(
file,
replaces,
log_message=f"Replaced type='edit' with type='open' in file: {file}",
)
except Exception as e:
logger.error(f"Error processing file {file}: {str(e)}")


class MigrationScript(BaseMigrationScript):
_GLOBAL_FUNCTIONS = [
remove_deprecated_kanban_click_classes,
replace_kanban_color_picker_widget,
remove_kanban_tooltip,
replace_type_edit,
replace_tree_with_list_in_views,
replace_chatter_blocks,
replace_user_has_groups,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.xml:
(?:t-attf-class|class)="[^"]*(?:kanban_getcolor|kanban_color|kanban_getcolorname)\([^"]*"|class="[^"]*oe_kanban_color_\d+[^"]*": "[18.0] Kanban color methods (kanban_getcolor, kanban_color, kanban_getcolorname) and static color classes (oe_kanban_color_X) have been deprecated in favor of the highlight_color attribute on kanban root node. This attribute will properly color the left border of the kanban cards. No need to set color classes or use color methods anymore. These methods will be removed in 18.0. More details: https://github.com/odoo/odoo/pull/167751"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.xml:
kanban_image\(['"][^'"]+["']\s*,\s*['"][^'"]+["']\s*,\s*[^)]+\): "[18.0] The kanban_image helper is deprecated in favor of <field widget=\"image\"/>. More details: https://github.com/odoo/odoo/pull/167751/commits/6c5896724abee4cee0a26d0b41de9781c8e51621"
54 changes: 53 additions & 1 deletion tests/data_result/module_170_180/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</list>
</field>
</record>

<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.form</field>
<field name="model">res.partner</field>
Expand Down Expand Up @@ -62,4 +62,56 @@
<chatter/>
</field>
</record>

<record id="res_partner_view_kanban" model="ir.ui.view">
<field name="name">res.partner.view.kanban</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<kanban>
<templates>
<t t-name='card'>
<div t-attf-class="oe_kanban_card " style="width:100%">
<div>
<field name="partner_id"/>
</div>
<field name="color" widget="kanban_color_picker"/>
</div>
</t>
</templates>
</kanban>
</field>
</record>

<record id="res_partner_view_kanban" model="ir.ui.view">
<field name="name">res.partner.view.kanban</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<kanban>
<templates>
<t t-name='card'>
<div t-attf-class="oe_kanban_card " style="width:100%">
<div>
<p>
<strong>
<h4 class="oe_goal_name">
<field name="definition_id"/>
</h4>
</strong>
</p>
<field name="partner_id"/>
</div>
<field name="color" widget="kanban_color_picker"/>
<div role="menuitem" class="col-4">
<a
class="dropdown-item"
type="open"
role="menuitem"
>Configuration</a>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
</odoo>
65 changes: 64 additions & 1 deletion tests/data_template/module_170/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</tree>
</field>
</record>

<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.form</field>
<field name="model">res.partner</field>
Expand Down Expand Up @@ -69,4 +69,67 @@
</div>
</field>
</record>

<record id="res_partner_view_kanban" model="ir.ui.view">
<field name="name">res.partner.view.kanban</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<kanban>
<templates>
<t t-name='card'>
<div t-attf-class="oe_kanban_card oe_kanban_global_click" style="width:100%">
<div>
<field name="partner_id"/>
</div>
<ul data-field="color"
class="oe_kanban_colorpicker"
modifiers="{}"
/>
</div>
</t>
</templates>
</kanban>
</field>
</record>

<record id="res_partner_view_kanban" model="ir.ui.view">
<field name="name">res.partner.view.kanban</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<kanban>
<templates>
<t t-name="kanban-tooltip">
<ul class="oe_kanban_tooltip">
<li>kanban-tooltip test</li>
</ul>
</t>
<t t-name='card'>
<div t-attf-class="oe_kanban_card oe_kanban_global_click_edit" style="width:100%">
<div>
<p>
<strong>
<h4 tooltip="kanban-tooltip" class="oe_goal_name">
<field name="definition_id"/>
</h4>
</strong>
</p>
<field name="partner_id"/>
</div>
<ul class="oe_kanban_colorpicker"
data-field="color"
modifiers="{}"
/>
<div role="menuitem" class="col-4">
<a
class="dropdown-item"
type="edit"
role="menuitem"
>Configuration</a>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
</odoo>
Loading