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

[ADD] changes in chatter v18 #97

Merged
merged 1 commit into from
Oct 2, 2024
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
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>
Loading