Thanks @pokoli
I’m looking through the documentation and trying to find the trytond/modules folder as mentioned in the ‘Modules’ section
Module Structure
A module is a directory in trytond/modules which contains at least two files:
In my docker instance I can see /var/lib/trytond/www but no ‘module’ folder
Where do I copy my ‘cloned’ module?
Or does it get applied via a hg process?
An overview of the module creation workflow would certainly be appreciated.
I just have not had any luck getting a non-docker instance of Tryton installed. If that’s that’s the path I need to take I’m sure I’ll need coaching to get a development environment 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:
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:
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:
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)
That guide is a work in progress. I hope to get more time soon to improve the patch submitted to review, however I’ve good news for you:
You’re doing well so that warning messages are due to nature of sqlite database, if you would set up the environment on postgres database you will not see those warnings.
Hi Jose.
I think I’m getting close.
In your guide, when I get to the Test tryton client stage I get an error Namespace Gtk not available
I’m assuming because this Tryton client is a desktop GUI and I’m trying to set this up on a console server
Finally, test it setting localhost:8000 as the url in your browser.
Do I need an absolute path for the www in the ln command?
How do I set the listener from localhost to 0.0.0.0 so it’s available to browse from my network?
OK, I’ve gotten a workable system and can browse and log into the Tryton WebUI
Here’s what I diid:
I installed (apt) postgres & (pip) psycopg2,
created a postgres tryton role and DB,
‘primed’ the new DB,
and updated my trytond.conf as follows
[database]
uri = postgresql://tryton:tryton@localhost/
path = /var/lib/trytond
#path=~/db/test_db.sqlite
I suspect you where using the sqlite backend and which did not support all features so we raise a warning to notice that the feature is not supported on sqlite.
trytond/bin/trytond-admin -c trytond.conf -d tryton -u ir res account_invoice_stock party account account_invoice currency company product stock account_product country sale -v
Cookie cutter is a python package/script for create a folder with file based on a template. You need to install cookiecutter first via pip (pip install cookiecutter)
The hg+https://hg.tryton.org/cookiecutter Is the template that cookiecutter will download.
The result is a folder with your project name, and all the basic file pre-populated.
This is not necessary, but it helps speed the module, and eliminate the need to write the boilerplate manually.
Don’t need to be in a virtual environment. This will just setup the folder structure.
Thanks. I see now.
I needed to do this prior - obvious mistake on my part pip install cookiecutter
then the cookiecutter command works and prompts for the template values
After developing the module created by the above command, when I’m ready to deploy it, I would python setup.py install
and then use the trytond-admin with the -u to activate it in the WebGUI?
Yes, but when developing I recommend using python setup.py develop in order to install the module in development module so you don’t need to reinstall the package for every change you make on it.
yes, you will activate/update the module with the -u, but not forget to add all the dependecies. the better option is to add the --activate-dependecies:
I’m using the following script to automate this process. I’m also using this script to quickly set up some testing environment (just adjust which modules get installed and updated).
My directory-layout is:
project-root
+-- __init__.py
+-- … module files
+-- _venv # python virtual env
+-- <module-name>.sqlite # the database
+-- tryton.conf
+-- trytond.conf
+-- … other file created by virutalenv
As you can see, I’m storing the database and the config files in the virtual environment, too. This keeps all files at on place, while still keeping the project root tidy and eases clean-up when done.
The script creates all of these files if not existing, updates the module (even if not stricktly required) and starts the client as well a the server. This allows me to jsut re-run the script without taking care wich task is required exactly.
To restart with a clean database or a clean virtualenv, I just delete what should be rebuild and rerun the script.
Major steps are:
If not existing, create a virtualenv and install the requirement and the module to be developed in it
if not existing, create a client config file
if not existing, create a server config file
if not existing, create sqlite database and initialize it using trytond-admin