Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
7199 Vizualizări

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?

Imagine profil
Abandonează
Cel mai bun răspuns

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.

Imagine profil
Abandonează
Autor

It works. Thank you so much Ibrahim

Great!

You're welcome.

Cel mai bun răspuns

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',
Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
dec. 23
1464
3
oct. 23
8796
1
sept. 23
3322
1
mai 23
2262
2
apr. 23
2823