Skip to Content
Menu
This question has been flagged
2 Replies
6145 Views

I have module and CSV data for the Philippine States. I have called it to manifest.

I want to load it when MODULE INSTALLATION only and no update. How can I do it?

Treatment should be like in base location states for the US and other countries. Is there something to do on its init?

Avatar
Discard
Best Answer

Hi, 

For that, you're going to use the post_init_hook procedure. 

How? 
Follow these steps : 

1- Register the hook in the __manifest__.py file with the post_init_hook
key:

'demo': [
'data/mrp_demo.xml',
],
'test': [],
'application': True,
...

'post_init_hook': 'add_philippines_states',

2- Add the add_philippines_states() method in the __init__.py file:

from odoo import api, fields, tools
def add_philippines_states(cr, registry):
tools.convert_file(cr, 'Your_MODULE', PATH, None, mode='init', noupdate=True, kind='init', report=None)

where path is the path to your scv file. EX : data/philipine_states.scv

It means that after the installation of your module, Odoo will check for the add_philippines_states method in your  __init__.py .

Upvote if this helps,
If not, you can write back for further analysis.

Regards.

Avatar
Discard
Author

It works. Thank you so much Ibrahim

Great!

You're welcome.

Best Answer

You can do it same as the below module:

https://github.com/OCA/l10n-switzerland/tree/12.0/l10n_ch_zip

They create hooks.py to import from csv and remember the below:

 1- Change the path and file name (data/res.city.csv) of your csv file 

 2- Change module name instead of "l10n_ch_zip" in convert method.

from odoo.tools import convert_file

def import_csv_data(cr, registry):
"""Import CSV data as it is faster than xml and because we can't use
noupdate anymore with csv"""
filenames = ['data/res.city.csv']
for filename in filenames:
convert_file(
cr, 'l10n_ch_zip',
filename, None, mode='init', noupdate=True,
kind='init', report=None,
)
def post_init(cr, registry):
import_csv_data(cr, registry)


 then in __init__.py call the post_init as below:

from .hooks import post_init

then in __manifest__.py added the below:

 'post_init_hook': 'post_init',
Avatar
Discard
Related Posts Replies Views Activity
1
Dec 23
439
3
Oct 23
5984
1
Sep 23
1975
1
May 23
1007
2
Apr 23
1379