Skip to content

Commit

Permalink
[IMP] replace toggle_button to boolean_toggle widget
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviedoanhduy committed Nov 15, 2024
1 parent 38e7a02 commit cf6533c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
28 changes: 28 additions & 0 deletions odoo_module_migrate/migration_scripts/migrate_150_allways.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo_module_migrate.base_migration_script import BaseMigrationScript


def replace_toggle_button(
logger, module_path, module_name, manifest_path, migration_steps, tools
):
files_to_process = tools.get_files(module_path, (".xml",))
replaces = {
r'widget="\s*toggle_button\s*"': 'widget="boolean_toggle"',
r"widget='\s*toggle_button\s*'": 'widget="boolean_toggle"',
r'<attribute\s+name=["\']widget["\']>\s*toggle_button\s*</attribute>': '<attribute name="widget">boolean_toggle</attribute>',
}

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


class MigrationScript(BaseMigrationScript):
_GLOBAL_FUNCTIONS = [replace_toggle_button]
1 change: 1 addition & 0 deletions tests/data_result/module_160_170/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<tree editable="bottom" delete="false">
<field name="id"/>
<field name="name"/>
<field name="active" widget="boolean_toggle" string="Still Active"/>
<button name="get_formview_action" type="object" title="Open Task" icon="fa-pencil-square-o"/>
</tree>
</field>
Expand Down
10 changes: 10 additions & 0 deletions tests/data_result/module_170_180/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<!-- This is a list view for partners -->
<list position="inside">
<field name="test_field_1"/>
<field name="active" widget="boolean_toggle"/>
</list>
</field>
</record>
Expand Down Expand Up @@ -36,6 +37,15 @@
<field name="name"/>
</list>
</xpath>
<xpath expr="//field[@name='active']" position="attributes">
<attribute name="widget">boolean_toggle</attribute>
</xpath>
<xpath expr="//field[@name='active']" position="attributes">
<attribute name="widget">boolean_toggle</attribute>
</xpath>
<xpath expr="//field[@name='active']" position="attributes">
<attribute name="widget">boolean_toggle</attribute>
</xpath>
</field>
</record>

Expand Down
1 change: 1 addition & 0 deletions tests/data_template/module_160/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<tree editable="bottom" delete="false">
<field name="id"/>
<field name="name"/>
<field name="active" widget="toggle_button" string="Still Active"/>
<button name="get_formview_action" type="object" title="Open Task" icon="fa-pencil-square-o"/>
</tree>
</field>
Expand Down
12 changes: 12 additions & 0 deletions tests/data_template/module_170/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<!-- This is a tree view for partners -->
<tree position="inside">
<field name="test_field_1"/>
<field name="active" widget='toggle_button'/>
</tree>
</field>
</record>
Expand Down Expand Up @@ -36,6 +37,17 @@
<field name="name"/>
</tree>
</xpath>
<xpath expr="//field[@name='active']" position="attributes">
<attribute name="widget">toggle_button</attribute>
</xpath>
<xpath expr="//field[@name='active']" position="attributes">
<attribute name="widget"> toggle_button</attribute>
</xpath>
<xpath expr="//field[@name='active']" position="attributes">
<attribute name="widget">
toggle_button
</attribute>
</xpath>
</field>
</record>

Expand Down

0 comments on commit cf6533c

Please sign in to comment.