Reload country data in proteus

40 views
Skip to first unread message

Dr Praveen Bhatia

unread,
Jun 9, 2017, 3:15:06 AM6/9/17
to tryton
Hi
What is the proteus code to reload country list ?
I am getting empty country list.
Praveen

Sergi Almacellas Abellana

unread,
Jun 9, 2017, 3:26:30 AM6/9/17
to try...@googlegroups.com
El 09/06/17 a les 07:05, Dr Praveen Bhatia ha escrit:
There is no proteus code. The country list is included as static data of
the country module. You should update the module in order to make the
data available.

What I can not understand is how you made it to have and empty country
list :$


--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Dr. Praveen Bhatia

unread,
Jun 9, 2017, 5:43:50 AM6/9/17
to tryton
This is the code that I wrote:
import os
os.environ['DB_NAME']='mydb'

from trytond.tests.test_tryton import db_exist, drop_create,create_db,drop_db
from proteus import config, Model, Wizard

def activate_modules(modules):
    if isinstance(modules, basestring):
        modules = [modules]

    #drop_create()

    cfg = config.set_trytond('mydb')
    Module = Model.get('ir.module')
    modules = Module.find([
            ('name', 'in', modules),
            ])
    Module.click(modules, 'activate')
    Wizard('ir.module.activate_upgrade').execute('upgrade')

    return cfg

drop_create('mydb')
activate_modules(['company','country'])

Module = Model.get('ir.module')
mm = Module.find([])
print("Activated modules : " , [m.name
        for m in Module.find([('state', '=', 'activated')])])

print("Countries are : ", [m.name for m in Model.get('country.country').find([])])
print("Languages are : ", [m.name for m in Model.get('ir.lang').find([])])


================================
And here is the output showing Activated modules, Languages and Countries (Empty !). So I have missed some steps for loading the country file (data.xml in the country module)

('Activated modules : ', [u'company', u'country', u'currency', u'ir', u'party', u'res'])
('Countries are : ', []) 
('Languages are : ', [u'English', u'Bulgarian', u'Catal\xe0', u'Czech', u'German', u'Spanish', u'Spanish (Latin American)', u'French', u'Hungarian', u'Italian', u'Lao', u'Lithuanian', u'Dutch', u'Polish', u'Portuguese (Brazil)', u'Russian', u'Slovenian', u'Chinese Simplified']) 

Sergi Almacellas Abellana

unread,
Jun 9, 2017, 5:58:15 AM6/9/17
to try...@googlegroups.com
El 09/06/17 a les 11:43, Dr. Praveen Bhatia ha escrit:
>
> This is the code that I wrote:
> import os
> os.environ['DB_NAME']='mydb'
>
> from trytond.tests.test_tryton import db_exist,
> drop_create,create_db,drop_db

The problem is here. As you are using the tests functions, the country
data is not loaded as it's skiped for tests.

You should create de database using the backend tools.

Regards,

Dr. Praveen Bhatia

unread,
Jun 9, 2017, 6:37:24 AM6/9/17
to tryton


On Friday, June 9, 2017 at 6:58:15 PM UTC+9, Sergi Almacellas Abellana wrote:
El 09/06/17 a les 11:43, Dr. Praveen Bhatia ha escrit:
>
> This is the code that I wrote:
> import os
> os.environ['DB_NAME']='mydb'
>
> from trytond.tests.test_tryton import db_exist,
> drop_create,create_db,drop_db

The problem is here. As you are using the tests functions, the country
data is not loaded as it's skiped for tests.


Yes, country is not getting loaded. What should I call to load the countries?
 
You should create de database using the backend tools.


If I look at the create_db, it DOES use backend as given below in the copied code. So I am confused what different should I should ?

def create_db(name=DB_NAME, lang='en'):
    Database = backend.get('Database')
    if not db_exist(name):
        with Transaction().start(
                None, 0, close=True, autocommit=True, _nocache=True) \
                as transaction:
            transaction.database.create(transaction.connection, name)

        with Transaction().start(name, 0, _nocache=True) as transaction,\
                transaction.connection.cursor() as cursor:
            Database(name).init()
            ir_configuration = Table('ir_configuration')
            cursor.execute(*ir_configuration.insert(
                    [ir_configuration.language], [[lang]]))

        pool = Pool(name)
        pool.init(update=['res', 'ir'], lang=[lang])
        with Transaction().start(name, 0) as transaction:
            User = pool.get('res.user')
            Lang = pool.get('ir.lang')
            language, = Lang.search([('code', '=', lang)])
            language.translatable = True
            language.save()
            users = User.search([('login', '!=', 'root')])
            User.write(users, {
                    'language': language.id,
                    })
            Module = pool.get('ir.module') 
Module.update_list() 

Sergi Almacellas Abellana

unread,
Jun 9, 2017, 6:41:09 AM6/9/17
to try...@googlegroups.com
El 09/06/17 a les 12:37, Dr. Praveen Bhatia ha escrit:
>
>
> On Friday, June 9, 2017 at 6:58:15 PM UTC+9, Sergi Almacellas Abellana
> wrote:
>
> El 09/06/17 a les 11:43, Dr. Praveen Bhatia ha escrit:
> >
> > This is the code that I wrote:
> > import os
> > os.environ['DB_NAME']='mydb'
> >
> > from trytond.tests.test_tryton import db_exist,
> > drop_create,create_db,drop_db
>
> The problem is here. As you are using the tests functions, the country
> data is not loaded as it's skiped for tests.
>
>
> Yes, country is not getting loaded. What should I call to load the
> countries?
You should not import the test_tryton as it marks the Pool as testing [1]
which causes the skiptest [2] of country module to no import the country
data.

Updating the module on the database from the client will fix the issue.

[1]
http://hg.tryton.org/trytond/file/ecc6a9a0b7c1/trytond/tests/test_tryton.py#l38
[2] http://hg.tryton.org/modules/country/file/b5d61c215d91/data.xml#l3

Dr. Praveen Bhatia

unread,
Jun 9, 2017, 7:29:19 AM6/9/17
to tryton
Great! That explains the mystery. Removing the Pool.test mode, solved the problem. Countries appear now !
Reply all
Reply to author
Forward
0 new messages