コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
7195 ビュー

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?

アバター
破棄
最善の回答

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.

アバター
破棄
著作者

It works. Thank you so much Ibrahim

Great!

You're welcome.

最善の回答

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',
アバター
破棄
関連投稿 返信 ビュー 活動
1
12月 23
1460
3
10月 23
8789
1
9月 23
3320
1
5月 23
2261
2
4月 23
2818