Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
7194 Widoki

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?

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Autor

It works. Thank you so much Ibrahim

Great!

You're welcome.

Najlepsza odpowiedź

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',
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
gru 23
1460
3
paź 23
8788
1
wrz 23
3320
1
maj 23
2261
2
kwi 23
2818