HowTo » History » Version 17

« Previous - Version 17/22 (diff) - Next » - Current version
Thomas Mielke, 10/25/2020 02:14 AM


HowTo

Tryton

Change Model Fields

If the fields of a model need some changes, you first might want to try to update the current database (if possible) until you are satisfied.
Nevertheless, always test a rebuild from scratch before a commit. Of course you could also skip the updating part, but a complete db setup needs more time.

Update database

  1. Start the services once:

    docker-compose up
    
  2. While you are coding, apply changes to the database with exec (exec executes the command on the running container instead of starting a new one, so it is faster):

    docker-compose exec erpserver execute update -m collecting_society
    
  3. Fix all update/init errors until the update runs successfully.

    Watch the logs for warnings, but be aware, that sometimes there is none - e.g. if you deleted a field/relation but still use it somewhere else,
    the database will still contain that table/column and you won't notice the error until a complete rebuild of the database.

  4. Run the tryton tests for the collecting_society model to test the views and depends:

    docker-compose exec erpserver python /shared/src/trytond/trytond/tests/run-tests.py -vvvm collecting_society
    
    1. Create/Fix all XML views of that model, until everything works as expected, see HowTo.
    2. Fix all model functions of that model, until everything works as expected, see HowTo.
  5. Restart the tryton client with cache disabled and test the views and fields of the model (read/write):

    tryton -d
    
    1. Create/Fix all XML views of that model, until everything works as expected, see HowTo.
    2. Fix all model functions of that model, until everything works as expected, see HowTo.

Rebuild database

  1. Stop the services and log into the tryton service:

    docker-compose stop
    docker-compose run --rm erpserver bash
    
    execute pip-install erpserver
    
  2. Delete and setup a new database (scenario_master_data.txt only):

    execute db-delete && execute db-setup --master --force
    
  3. Check the log, fix all update/init errors, until the update runs successfully.

  4. Start a tryton (only) service on second terminal (to be able to rebuild the database on the first terminal, if neccessary):

    docker-compose up tryton
    
  5. Restart the tryton client with cache disabled (you might want to create an alias for that):

    tryton -d
    
    1. Create/Fix all XML views of that model, until everything works as expected, see HowTo.
    2. Fix all model functions of that model, until everything works as expected, see HowTo.
  6. Create/Fix the tests, see HowTo

  7. Commit

Change Model Functions

If you change some code within a model function, you just need to restart the tryton service for trytond to reread the function definitions:

tryton -d

Change XML Views

If you change the main XML (e.g. ado/src/collecting_society/collecting_society.xml), you need to update the database (best with exec on a running container) and restart the client. A restart of the tryton server is usually not neccessary,

docker-compose exec erpserver execute update -m collecting_society

WARNING: If you have fixed view errors in the XML and it seems that the view cache is not cleared or the changes in the XML definitions are not propagated to the application,
do the following:

  1. Check the name tag in the corresponding ir.ui.view record model entries in the main XML. The name must correspond to a file name in the view path, but plus ".xml".
  2. Temporarily delete the corresponding definitions of the broken view (usually at least the record models ir.ui.view, ir.action.act_window, ir.action.act_window.view and menuitem)
  3. Update the database: docker-compose exec erpserver execute update -m collecting_society
  4. Insert the corresponding definitions of the broken view again (undo the deletion)
  5. Again update the database: docker-compose exec erpserver execute update -m collecting_society
  6. Restart the Tryton Client

If you change the XML views for a model (e.g. ado/src/collecting_society/view/creation_list.xml), it is sufficient to close and reopen the view in the tryton client, if cache is disabled:

tryton --dev

Change DB Tests

If you want/need to change the database tests (shared/data/demo.txt), you want to create and setup a new database template (e.g. collecting_society_template) and use a copy of it as the starting point for the test/demo setup.

  1. Log into a test_erpserver service

    docker-compose run --rm --service-ports erpserver bash
    
    execute pip-install erpserver
    
  2. Delete and setup a clean database template (master.txt only):

    execute db-delete test_template && execute db-setup --master test_template
    
  3. Delete the database, copy the database template and setup the data to test, pipe the output into a logfile:

    export TRYTON_DEMODATA_DEBUG=1
    execute db-delete test && execute db-copy test_template test && execute db-setup --demo --force test
    

    Start with TRYTON_DEMODATA_DEBUG=1 to set all configuration variables to 1.
    If that works, try TRYTON_DEMODATA_DEBUG=2 afterwards, as some objects might not be created due to the low sample size.

  4. Check the log, fix all errors, until the setup runs successfully. If you get stuck, fire up an interactive console with interlude within your tests:

    import interlude; interlude.interact(locals())
    

    You can always find that command in the import section at the top of the scenario files, if you want to copy & paste it.

  5. To validate the test data, start a erpserver service on a second terminal (to be able to rebuild the database on the first terminal, if neccessary):

    docker exec -it $(docker ps -a | grep ":8000" | cut -d' ' -f1) bash
    
    execute deploy-erpserver
    

    Restart the tryton client with cache disabled and connect to the test database:

    tryton -d
    
  6. Do a final test run via ./scripts/test (ensure TRYTON_DEMODATA_DEBUG=0).

Errors

Pyramid View

If you encounter tryton errors in a pyramid error feedback view, you might be able to get more specific information on the error:

  1. Open an interactive console, where one of the following keywords are passed as parameter: fieldname, error_args
  2. Type that variable name into the console to find out its value, which could point towards the source of the error.

Proteus

Errors in proteus are sometimes cryptic. See here for English and German translations:

http://hg.tryton.org/trytond/file/tip/trytond/ir/locale/de.po

Tryton Tests

======================================================================
ERROR: test0005views (trytond.modules.collecting_society.tests.test_collecting_society.CollectingSocietyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/shared/src/collecting_society/tests/test_collecting_society.py", line 24, in test0005views
    test_view('collecting_society')
  File "/shared/src/trytond/trytond/tests/test_tryton.py", line 123, in test_view
    res = Model.fields_view_get(view_id)
  File "/shared/src/trytond/trytond/model/modelview.py", line 237, in fields_view_get
    tree = etree.fromstring(result['arch'], parser)
  File "lxml.etree.pyx", line 3092, in lxml.etree.fromstring (src/lxml/lxml.etree.c:70691)
  File "parser.pxi", line 1827, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:106678)
ValueError: can only parse strings

Probably some referenced view file in ./views/ is missing.
To get the view name, open up /shared/src/trytond/trytond/tests/test_tryton.py", line 123 and add print(model) before the call of fields_view_get (around Line 123).

Tryton Views

  • If you are not able to open several views due to errors about not finding the model name in the _pool, try docker-compose down.
  • If you change the model fields and are missing the changes, sometimes you need to
    1. cut out the <field>s within the view xml:
    2. close/open the view
    3. paste the <field>s again and
    4. close/open the view

Pyramid

2DO