Skip to Content
Menu
This question has been flagged
1 Reply
495 Views

"post_init_hook" not working - Odoo 17

I'm trying to initialize the signature for base.user_root by creating a post_init_hook.

In the __init__.py file, I wrote the following code:


def update_odoo_bot_signature(env):
    user = env.ref('base.user_root')
    print(">>> Running post_init_hook to update OdooBot signature >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    signature = '''
        <div style="font-family: Arial; font-size: 14px;">
            <p>Trân trọng,</p>
            <p><strong>Odoo Bot</strong></p>
            <p>Công ty TNHH ABC 12344444</p>
            <p><a href="https://yourcompany.com">https://yourcompany.com</a></p>
        </div>
    '''
    user.write({'signature': signature})

And in the __manifest__.py file, I configured it like this: "post_init_hook": "update_odoo_bot_signature",


However, when I upgrade the module, the signature for the OdooBot record is not updated.
Avatar
Discard
Best Answer

Your issue should be "when I upgrade the module" because "post_init_hook takes a cursor and a registry as its arguments, this function is executed right after the module’s installation."

https://www.odoo.com/documentation/18.0/developer/reference/backend/module.html


If you can't re-install your module or create a new one for whatever reason, you can also create a data file.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="base.user_root" model="res.users">
<field name="signature">...</field>
</record>
</data>
<odoo>

You should also consider defining

noupdate="1" 

on the data node to prevent signatures from resetting upon upgrading your module.

See https://www.odoo.com/documentation/18.0/developer/reference/backend/data.html

Avatar
Discard
Author

So is there a way for me to customize the signature field from code, instead of having to edit it on the website?

Related Posts Replies Views Activity
3
Jul 25
1414
1
Jun 25
1352
2
May 25
1390
1
May 25
730
1
Feb 25
38