Skip to content

Commit

Permalink
[ADD] changes in chatter v18
Browse files Browse the repository at this point in the history
  • Loading branch information
lef-adhoc authored and legalsylvain committed Oct 2, 2024
1 parent 175901f commit a4251d1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
38 changes: 37 additions & 1 deletion odoo_module_migrate/migration_scripts/migrate_170_180.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,41 @@ def replace_tree_with_list_in_views(
logger.error(f"Error processing file {file}: {str(e)}")


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

reg_chatter_block = r"""<div class=["']oe_chatter["'](?![^>]*position=["'][^"']+["'])[^>]*>[\s\S]*?</div>"""
reg_xpath_chatter = r"""//div\[hasclass\(['"]oe_chatter['"]\)\]"""
reg_chatter_with_position_self_closing = (
r"""<div class=["']oe_chatter["']\s*(position=["'][^"']+["'])\s*/>"""
)

replacement_div = "<chatter/>"
replacement_xpath = "//chatter"

def replace_chatter_self_closing(match):
position = match.group(1)
return f"<chatter {position}/>"

replaces = {
reg_chatter_block: replacement_div,
reg_xpath_chatter: replacement_xpath,
reg_chatter_with_position_self_closing: replace_chatter_self_closing,
}

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


class MigrationScript(BaseMigrationScript):
_GLOBAL_FUNCTIONS = [replace_tree_with_list_in_views]
_GLOBAL_FUNCTIONS = [
replace_tree_with_list_in_views,
replace_chatter_blocks,
]
20 changes: 20 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 @@ -42,4 +42,24 @@
<record id="view_partner_ref" model="ir.ui.view">
<field name="view_ref">list_view_ref</field>
</record>

<record id="chatter_form" model="ir.ui.view">
<field name="name">res.partner.chatter.form</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<chatter/>

<xpath expr="//chatter" position="replace"/>

<xpath expr="//chatter" position="after">
<div>
<field name="test"/>
</div>
</xpath>

<chatter position="replace"/>

<chatter/>
</field>
</record>
</odoo>
27 changes: 27 additions & 0 deletions tests/data_template/module_170/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,31 @@
<record id="view_partner_ref" model="ir.ui.view">
<field name="view_ref">tree_view_ref</field>
</record>

<record id="chatter_form" model="ir.ui.view">
<field name="name">res.partner.chatter.form</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
<field name="message_ids" widget="mail_thread"/>
<field name="activity_ids" widget="mail_activity"/>
</div>

<xpath expr="//div[hasclass('oe_chatter')]" position="replace"/>

<xpath expr="//div[hasclass('oe_chatter')]" position="after">
<div>
<field name="test"/>
</div>
</xpath>

<div class="oe_chatter" position="replace"/>

<div class="oe_chatter">
<field name="message_follower_ids"/>
<field name="message_ids"/>
</div>
</field>
</record>
</odoo>

0 comments on commit a4251d1

Please sign in to comment.