Basic setup
For creating the basic folder structure and setup.py you can use cookie-cutter (need to install cookiecutter first via pip/system packet manager)
then you can execute:
cookiecutter hg+https://hg.tryton.org/cookiecutter
cookiecutter will ask you some question (like the project name), then will create a folder with all the necessary thing to start developing with tryton
tryton.cfg
First you need to change the tryton.cfg; this file is responsible for:
- tell setup.py witch version of tryton this module support
- tell setup.py your tryton module dependecy
- tell the xml file to include (the one that define the database record, not the views)
how to install your module
I strongly suggest to use a virtual-environment for development. The you can simply python setup.py install
to install all your dependecy defined in the tryton.cfg
(you can install the dependency manually if you want).
Every time you make a change you need to reinstall the module, unless you use a workaround (python setup.py develop
doesn’t work unfortunally)
how install the module in editable mode (for developing it)
When developing, installing the module every time you modify it can be time consuming,
a sane way to solve this problem is to install it id editable mode:
python setup.py develop
This will not work if your module folder doesn’t match the module name!
This will create a simlink in the correct folder for you.
How to setup your playground/manual testing environment
Trytond needs a database, fortunately you can be lazy about it and use sqlite. For this you need create a config file, the minimum required is:
[database]
path=/path/where/sqlite/dbs/are/stored
or optionally set the environment variable
export TRYTOND_DATABASE__PATH=/path/where/sqlite/dbs/are/stored
[explained in https://trytond.readthedocs.io/en/latest/topics/configuration.html]
The only thing missing is to create a empty file in the /path/where/sqlite/dbs/are/stored
folder, don’t forget to ad the .sqlite
extention or tryton will not recognize it. You can have multiple sqlite db in the same folder.
example:
touch /path/where/sqlite/dbs/are/stored/testplzignore.sqlite
Prime the database
You need to prime your database, this can be accomplished with the trytond-admin
command.
This will create all the necessary table for tryton to work, and set the admin password.
The detail are explained in the documentation
# with the configfile
trytond-admin -c configfile.cfg -d dbfilename --all
#with the enviroment variable
#export TRYTOND_DATABASE__PATH=/path/where/sqlite/dbs/are/stored
trytond-admin -d dbfilename --all
where dbfilename
is the filename of the db without the .sqlite extention.
Activate your module
After “priming” you need to activate your module, this can be done via the client gui or via command line:
#with the enviroment variable
#export TRYTOND_DATABASE__PATH=/path/where/sqlite/dbs/are/stored
trytond-admin -d dbfilename -u moduletoactivate --activate-dependecies
Update your module
if you modify some xml file, you need to update the db and usually relaunch the client. this can be archived with:
#with the enviroment variable
#export TRYTOND_DATABASE__PATH=/path/where/sqlite/dbs/are/stored
trytond-admin -d dbfilename -u moduletoupdate
This isn’t necessary it you modify just your python code.
Execute the tryton server (trytond)
You can execute the tryton server with:
# with the configfile
trytond -c configfile.cfg
#with the enviroment variable
#export TRYTOND_DATABASE__PATH=/path/where/sqlite/dbs/are/stored
trytond
If you don’t want to reload the tryton server on every change, you can use the --dev
flag.
This flag will auto-reload your module every time tryton see a file-change in the trytond folder. If you created the simlink like above mentioned, trytond will reload changes every time you save your module. The command
#with the enviroment variable
#export TRYTOND_DATABASE__PATH=/path/where/sqlite/dbs/are/stored
trytond --dev
the tryton client
You can install the tryton clinet via pip, the only caviat is that you need to install pygobject first…
Thsi can be a problem inside a virtual enviroment, but just remember to install pygobject globally and make sure to create the virtualenviroment with the system-site-packages flag.
If you executed the tryton server locally, by default it will listen on 127.0.0.1:8000 (you can change it in the config file)
When starting the client, you need to specify:
- host (127.0.0.1:8000 if the server is executed locally)
- database name (The databse nabe is the filename of the sqlite db you primed before)
- user (the only one is
admin
for the moment, the password is the one you inputted in the db priming stage)
unit-testing
I suggest you read the guide here: https://trytond.readthedocs.io/en/latest/topics/testing.html