Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
6714 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

It works. Thank you so much Ibrahim

Great!

You're welcome.

Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
1
Des 23
1060
3
Okt 23
7581
1
Sep 23
2722
1
Mei 23
1664
2
Apr 23
2139