Did you check our previous blog Comprehensive Guide on Upgrading to Odoo 17? As Odoo evolves, developers often find themselves adapting to new changes and features.
One such significant shift occurred in odoo17 is the modifications in traditional use of attrs in XML files.In this blog, we’ll together explore a python script that facilitates transition by replacing attrs with corresponding attributes directly in XML files.
Upon running the modules with attrs while migration to odoo17,it will throw an error,
We’re grateful for the contribution from Pierrelocus on GitHub, which played a crucial role in resolving the issue.Feel free to check out the repository by following the link provided below.
https://github.com/pierrelocus/odoo-attrs-replace
Follow the steps outlined below to resolve the issue.
Dependencies:
Prior to executing the Python command, ensure you install the required dependencies by using the following command:
pip install beautifulsoup4 lxml
ORpip install -r requirements.txt
The python script:
1. Clone or download the python script replace_attrs.py
2. Navigate to the script using cd command
3. Launch the script using the following command:
python3 replace_attrs.py
Usage:
2. The script will ask if you want to auto-replace without asking for confirmation for each file. Choosing ‘y’ for auto-replace will skip the confirmation step for each file.
3. If the directory doesn’t include xml file with attrs or states , it will throw an error.
4. Else,for each XML file found, the script will replace all instances of attrs= and states= with related attributes (invisible, readonly, required, column_invisible) directly in the XML tag.
5.
Take a look at the below example:
Here,attrs="{'invisible': [('web_visible','=',False)] ,'required':[('web_visible', '=', True)]}"
is converted to invisible="web_visible == False" name="pricelist_id" required="web_visible == True"
Hence, multiple files can be updated by just one python script.
Conclusion
This script can be a time-saving solution for developers dealing with the transition to Odoo v17. The main advantage is when working with files having more attrs.Ensure you have backups before making changes to critical code, and test the script in a controlled environment to ensure it works as expected
: ".
Leave a Reply