Preparing for Module Development

Hi, I am working in an IT consultant company… and my boss asked me to explore Tryton ERP to be use as internal ERP system and to develop HR and Payroll, Accounting and Assets management.

My question are:

  1. How to deploy a Tryton server for development purpose, where my developers can deploy newly created modules?
  2. Which GIT repository that we can clone to start coding on top of it?
  3. What python framework to use to develop new modules?

To be honest, my devops already installed the docker version and I can open it in the browser. but the things I can find it there are Administrator features (I think)…

We really need your support.

Thanks

Docker is probably the easiest way. We have a dedicated howto on this forum:

We have a cookiecutter module which can be used as boilerplate for starting new modules.

Tryton itself its a framework for develop modules. You can learn how to do it using our module tutorial.

Probably you just activated the base modules so no other functionalities are available on your database. You should activate more modules to get more functionalities there.

1 Like

For local development, I think the easier (and what I do) is to use a virtual environment as described in the Module Tutorial — Tryton server.

Tryton publishes packages on https://pypi.org/ so it can be installed inside a virtual environment.

Tryton is the framework.

1 Like

Hi… I followed tutorial to setup a new module and below is my config

(.venv) root@DESKTOP-PRHGPAU:/home/bromo/new-module#** cookiecutter hg+https://code.tryton.org/tryton --directory cookiecutter-module
  [1/11] module_name (my_module): opportunity
  [2/11] prefix (): tuto
  [3/11] package_name (tuto_opportunity):
  [4/11] version (7.5.0): 7.5.0
  [5/11] description (): none
  [6/11] author (Tryton): 
  [7/11] author_email (foundation@tryton.org): *****@yahoo.com
  [8/11] fullname (): John Doe
  [9/11] url (http://www.tryton.org/): http://localhost:8000
  [10/11] keywords (): none
  [11/11] test_with_scenario (): none

And when I try to execute the next command (install module), I got error like below:

**(.venv) root@DESKTOP-PRHGPAU:/home/bromo/new-module#** python3 -m pip install --use-pep517 --editable opportunity
Obtaining file:///home/bromo/new-module/opportunity
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
ERROR: Could not find a version that satisfies the requirement trytond<7.6,>=7.5 (from tuto-opportunity) (from versions: 1.2.8, 1.2.9, 1.2.10, 1.4.8, 1.4.9, 1.4.10, 1.4.11, 1.4.12, 1.4.13, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.6.8, 1.6.9, 1.6.10, 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.8.10, 1.8.11, 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, 2.0.10, 2.0.11, 2.0.12, 2.0.13, 2.2.0, 2.2.1, 2.2.2, 2.2.3, 2.2.4, 2.2.5, 2.2.6, 2.2.7, 2.2.8, 2.2.9, 2.2.10, 2.2.11, 2.2.12, 2.2.13, 2.2.14, 2.4.0, 2.4.1, 2.4.2, 2.4.3, 2.4.4, 2.4.5, 2.4.6, 2.4.7, 2.4.8, 2.4.9, 2.4.10, 2.4.11, 2.4.12, 2.4.13, 
... 

ERROR: No matching distribution found for trytond<7.6,>=7.5

What did I do wrong?

Sorry I am not a python programmer basically… but Java & Rust… but my boss want to do this.
Thanks in advance.

Regards
Bromo

Using development version like 7.5.0, you will not find any published module.
You must use a publicly released version (with odd minor number).

Also it is better to use the template of the corresponding branch. For example with the last release 7.4:

$ cookiecutter hg+https://code.tryton.org/tryton --directory cookiecutter-module --checkout 7.4

I filled Add checkout option to cookiecutter command line in tutorial (!2298) · Merge requests · Tryton / Tryton · GitLab to be more explicit.

1 Like

Done… no more error, thanks alot Ced :slightly_smiling_face:

I suggest checking out the cookiecutter module provided by Tryton Community which provides some enhancements and default to the latest LTS release version).

cookiecutter --output-dir /path/to/your/modules \
    https://foss.heptapod.net/tryton-community/cookiecutter-module.git

Hi, so I bumped again .. I managed to Activate the opportunity module (see below screenshot)

But when I try to execute below command to persists the new model into DB

$ trytond-admin -d test -u opportunity --activate-dependencies

I got these errors:

(.venv) root@DESKTOP-PRHGPAU:/# trytond-admin -d test -u opportunity --activate-dependencies
Traceback (most recent call last):
  File "/home/bromo/new-module/.venv/bin/trytond-admin", line 33, in <module>
    admin.run(options)
  File "/home/bromo/new-module/.venv/lib/python3.10/site-packages/trytond/admin.py", line 59, in run
    pool.init(update=options.update, lang=list(lang),
  File "/home/bromo/new-module/.venv/lib/python3.10/site-packages/trytond/pool.py", line 139, in init
    self.start()
  File "/home/bromo/new-module/.venv/lib/python3.10/site-packages/trytond/pool.py", line 110, in start
    register_classes(with_test=cls.test)
  File "/home/bromo/new-module/.venv/lib/python3.10/site-packages/trytond/modules/__init__.py", line 322, in register_classes
    for node in create_graph(get_modules(with_test=with_test)):
  File "/home/bromo/new-module/.venv/lib/python3.10/site-packages/trytond/modules/__init__.py", line 95, in create_graph
    info = get_module_info(module)
  File "/home/bromo/new-module/.venv/lib/python3.10/site-packages/trytond/modules/__init__.py", line 34, in get_module_info
    with tools.file_open(os.path.join(name, 'tryton.cfg')) as fp:
  File "/home/bromo/new-module/.venv/lib/python3.10/site-packages/trytond/tools/misc.py", line 50, in file_open
    return io.open(path, mode, encoding=encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/home/bromo/new-module/.venv/lib/python3.10/site-packages/trytond/modules/opportunity/tryton.cfg'
(.venv) root@DESKTOP-PRHGPAU:/#

It seems that even thou the screen-shot says my activation was succeed.. but somehow it didn’t create the module folder inside the .venv/lib/python3.10/site-packages/trytond/modules/ folder

And when I search into that folder.. there is no opportunity folder.
I need further assistance.. and thank you in advance

Regards
Bromo

The name of the package must be the same as the name of your Tryton module. So it must be opportunity in both.

The name of the package must be the same as the name of your Tryton module

This statement is misleading: The “module package” (trytond.modules.xxx) needs to have the same name as the module. Anyhow the distribution package can have a different name, as packages named “m9s-…”, “nantic-…” or “virtualthings-…” show.

Also: The directory you are developing the module in must have the same name as the module. This is one of the sortcomings og trytond’s custom “import” mechanism.

[Edit: Distinguished between module an distribution.]

This might be an error in you module. trytond’s custom import mechanisms has some shortcomings, one of which is that it “converts” ImportErrors into “FileNotFoundError: …/trytond.conf”. I suggest adding a raise statement just behind the except ModuleNotFoundError in trytond.tools.misc.find_file().

Hi, are u saying that when I create the module project using cookiecutter .. I just set the prefix to none? so the package-name would only opportunity ??
Okay.. let me try that

I changed the package-name like below screenshot

But still the bug exists. The command

trytond-admin -d test -u opportunity --activate-dependencies

Still produce the same error as above.

Regards
Bromo

I re-create everything from zero, setup a new Ubuntu 22.04 in windows wsl2. So I follow again from the beginning:

  1. Create a new folder in Ubuntu called new-module
  2. Create a new venv inside new-module folder
  3. Upgrade pip
  4. Fresh install both cookiecutter & mercurial
  5. Perform: cookiecutter hg+https://code.tryton.org/tryton --directory cookiecutter-module --checkout 7.4, With both module and package-name similar: opportunity
  6. Then install the module using: python3 -m pip install --use-pep517 --editable opportunity
  7. Initializing the db → until I finished performing: trytond-admin -d test --all → I set admin password here
  8. Try to run the server by executing: trytond → the server runs
  9. Then using VsCode, I create the model (opportunity.py), update the __init__.py file and tryton.cfg following what the tutorial says (I did copy & paste).
  10. Executing: python3 -m pip install --use-pep517 --editable opportunity with no problem.
  11. Try to execute: trytond-admin -d test -u opportunity --activate-dependencies to create tables in DB, but now I got new error:
(.venv) root@DESKTOP-PRHGPAU:/new-module# trytond-admin -d test -u opportunity --activate-dependencies
Traceback (most recent call last):
  File "/new-module/.venv/bin/trytond-admin", line 33, in <module>
    admin.run(options)
  File "/new-module/.venv/lib/python3.10/site-packages/trytond/admin.py", line 59, in run
    pool.init(update=options.update, lang=list(lang),
  File "/new-module/.venv/lib/python3.10/site-packages/trytond/pool.py", line 144, in init
    restart = not load_modules(
  File "/new-module/.venv/lib/python3.10/site-packages/trytond/modules/__init__.py", line 402, in load_modules
    _load_modules(update)
  File "/new-module/.venv/lib/python3.10/site-packages/trytond/modules/__init__.py", line 372, in _load_modules
    load_module_graph(graph, pool, update, lang, indexes)
  File "/new-module/.venv/lib/python3.10/site-packages/trytond/modules/__init__.py", line 200, in load_module_graph
    cls.__register__(module)
  File "/new-module/.venv/lib/python3.10/site-packages/trytond/model/modelsql.py", line 439, in __register__
    super(ModelSQL, cls).__register__(module_name)
  File "/new-module/.venv/lib/python3.10/site-packages/trytond/model/model.py", line 127, in __register__
    model_id = Model_.register(cls, module_name)
  File "/new-module/.venv/lib/python3.10/site-packages/trytond/ir/model.py", line 107, in register
    model.__name__, model._get_name(), model.__doc__,
  File "/new-module/.venv/lib/python3.10/site-packages/trytond/model/model.py", line 109, in _get_name
    assert cls.__doc__, '%s has no docstring' % cls
AssertionError: <class 'trytond.modules.opportunity.opportunity.Opportunity'> has no docstring

Any clue what I did wrong? Should I create a new thread?

Regards,
Bromo

I think the error message is pretty explicit:

You need to set a docstring for this class.

Ok.. can u suggest how to add docstring? (really really sorry I am not python dev).. I already google it.. google said I need to add something like: __doc __

below is my code based on the tutorial:


from trytond.model import ModelSQL, fields

class Opportunity(ModelSQL):
    __name__ = 'training.opportunity'
    _rec_name = 'description'

    description = fields.Char("Description", required=True)
    start_date = fields.Date("Start Date", required=True)
    end_date = fields.Date("End Date")
    party = fields.Many2One('party.party', "Party", required=True)
    comment = fields.Text("Comment")

Where could I add docstring at my code??

Best regards
Bromo

You can take a look at PEP 257 – Docstring Conventions | peps.python.org

but mainly it is:

class Opportunity(ModelSQL):
   "Opportunity"
    __name__ = 'training.opportunity'

By the way if you are using the series 7.4, you must follow the tutorial of the same series Module Tutorial — Tryton server which include the docstring.

1 Like

Amazing :sweat_smile::
Its running I can see my sqlite db already have the table.. thanks

Hi @ced or @htgoebel

I managed to create all xml for viewing the model I created in Tryton webui.. and I reached to the point I executed

$ trytond-admin -d test --all

so all xmls that created and registered in opportunity.xml persisted to db.
The only problem now is.. everytime I executed:

$ trytond

To start the server.. when I open in the browser.. it seems that tryton SAO module not running (SOA is web ui project rite?)

How to make it run so I can view or show my boss that I already able to deploy this one module??

Best regards
Bromo

See sao/README.md · branch/7.4 · Tryton / Tryton · GitLab to setup the web client.

1 Like