HowTo » History » Version 21

Alexander Blum, 10/15/2021 08:42 PM

1 1 Alexander Blum
# HowTo
2 1 Alexander Blum
3 1 Alexander Blum
{{toc}}
4 1 Alexander Blum
5 1 Alexander Blum
## Tryton
6 1 Alexander Blum
7 1 Alexander Blum
### Change Model Fields
8 1 Alexander Blum
9 1 Alexander Blum
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.
10 1 Alexander Blum
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.
11 1 Alexander Blum
12 1 Alexander Blum
#### Update database
13 1 Alexander Blum
14 1 Alexander Blum
1. Start the services once:
15 1 Alexander Blum
16 20 Alexander Blum
        $ docker-compose up
17 1 Alexander Blum
18 1 Alexander Blum
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):
19 1 Alexander Blum
20 20 Alexander Blum
        $ docker-compose exec erpserver db-update
21 1 Alexander Blum
22 1 Alexander Blum
3. Fix all update/init errors until the update runs successfully.
23 1 Alexander Blum
24 1 Alexander Blum
    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,
25 1 Alexander Blum
    the database will still contain that table/column and you won't notice the error until a complete rebuild of the database.
26 1 Alexander Blum
27 13 Alexander Blum
4. Run the tryton tests for the collecting_society model to test the views and depends:
28 1 Alexander Blum
29 20 Alexander Blum
        $ docker-compose exec erpserver service-test
30 13 Alexander Blum
31 13 Alexander Blum
    1. Create/Fix all XML views of that model, until everything works as expected, see [[HowTo#Change XML Views]].
32 13 Alexander Blum
33 13 Alexander Blum
    2. Fix all model functions of that model, until everything works as expected, see [[HowTo#Change Model Functions]].
34 13 Alexander Blum
35 13 Alexander Blum
5. Restart the tryton client with cache disabled and test the views and fields of the model (read/write):
36 13 Alexander Blum
37 20 Alexander Blum
        $ tryton -d
38 1 Alexander Blum
39 1 Alexander Blum
    1. Create/Fix all XML views of that model, until everything works as expected, see [[HowTo#Change XML Views]].
40 1 Alexander Blum
41 1 Alexander Blum
    2. Fix all model functions of that model, until everything works as expected, see [[HowTo#Change Model Functions]].
42 1 Alexander Blum
43 1 Alexander Blum
#### Rebuild database
44 1 Alexander Blum
45 1 Alexander Blum
1. Stop the services and log into the tryton service:
46 1 Alexander Blum
47 20 Alexander Blum
        $ docker-compose stop
48 20 Alexander Blum
        $ docker-compose run --rm --service-ports erpserver bash
49 1 Alexander Blum
50 20 Alexander Blum
        > pip-install
51 1 Alexander Blum
52 20 Alexander Blum
2. Delete and setup a new database (`production` dataset only):
53 1 Alexander Blum
54 20 Alexander Blum
        > db-rebuild --no-template -d production
55 1 Alexander Blum
56 1 Alexander Blum
3. Check the log, fix all update/init errors, until the update runs successfully.
57 1 Alexander Blum
58 1 Alexander Blum
4. Start a tryton (only) service on second terminal (to be able to rebuild the database on the first terminal, if neccessary):
59 1 Alexander Blum
60 20 Alexander Blum
        $ docker-compose up tryton
61 1 Alexander Blum
62 1 Alexander Blum
5. Restart the tryton client with cache disabled (you might want to create an alias for that):
63 1 Alexander Blum
64 20 Alexander Blum
        $ tryton -d
65 1 Alexander Blum
66 1 Alexander Blum
    1. Create/Fix all XML views of that model, until everything works as expected, see [[HowTo#Change XML Views]].
67 1 Alexander Blum
68 1 Alexander Blum
    2. Fix all model functions of that model, until everything works as expected, see [[HowTo#Change Model Functions]].
69 1 Alexander Blum
70 1 Alexander Blum
11. Create/Fix the tests, see [[HowTo#Change DB Tests]]
71 1 Alexander Blum
72 1 Alexander Blum
12. Commit
73 1 Alexander Blum
74 1 Alexander Blum
### Change Model Functions
75 1 Alexander Blum
76 1 Alexander Blum
If you change some code within a model function, you just need to restart the tryton service for trytond to reread the function definitions:
77 1 Alexander Blum
78 20 Alexander Blum
    $ tryton -d
79 1 Alexander Blum
80 1 Alexander Blum
### Change XML Views
81 1 Alexander Blum
82 20 Alexander Blum
If you change the **main XML** (e.g. `./code/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,
83 1 Alexander Blum
84 20 Alexander Blum
    $ docker-compose exec erpserver db-update
85 1 Alexander Blum
86 15 Alexander Blum
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,
87 1 Alexander Blum
do the following:
88 18 Thomas Mielke
89 18 Thomas Mielke
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".
90 18 Thomas Mielke
1. 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`)
91 20 Alexander Blum
1. Update the database: `docker-compose exec erpserver db-update`
92 18 Thomas Mielke
1. Insert the corresponding definitions of the broken view again (undo the deletion)
93 20 Alexander Blum
1. Again update the database: `docker-compose exec erpserver db-update`
94 18 Thomas Mielke
1. Restart the Tryton Client
95 18 Thomas Mielke
96 20 Alexander Blum
If you change the **XML views** for a model (e.g. `./code/collecting_society/view/creation_list.xml`), it is sufficient to close and reopen the view in the tryton client, if cache is disabled:
97 18 Thomas Mielke
98 20 Alexander Blum
    $ tryton -d
99 18 Thomas Mielke
100 18 Thomas Mielke
### Change DB Tests
101 18 Thomas Mielke
102 21 Alexander Blum
If you want/need to change the datasets (`./volumes/shared/data/datasets`), see [documentation](https://files.c3s.cc/collecting_society/development/generated/collecting_society_docker_README.html#demodata)
103 18 Thomas Mielke
104 14 Alexander Blum
### Errors
105 1 Alexander Blum
106 14 Alexander Blum
#### Pyramid View
107 14 Alexander Blum
108 1 Alexander Blum
If you encounter tryton errors in a pyramid error feedback view, you might be able to get more specific information on the error:
109 1 Alexander Blum
110 1 Alexander Blum
1. Open an interactive console, where one of the following keywords are passed as parameter: fieldname, error_args
111 1 Alexander Blum
2. Type that variable name into the console to find out its value, which could point towards the source of the error.
112 1 Alexander Blum
113 14 Alexander Blum
#### Proteus
114 1 Alexander Blum
115 14 Alexander Blum
Errors in proteus are sometimes cryptic. See here for English and German translations:
116 1 Alexander Blum
117 1 Alexander Blum
http://hg.tryton.org/trytond/file/tip/trytond/ir/locale/de.po
118 13 Alexander Blum
119 14 Alexander Blum
#### Tryton Tests
120 13 Alexander Blum
121 13 Alexander Blum
~~~
122 13 Alexander Blum
======================================================================
123 13 Alexander Blum
ERROR: test0005views (trytond.modules.collecting_society.tests.test_collecting_society.CollectingSocietyTestCase)
124 13 Alexander Blum
----------------------------------------------------------------------
125 13 Alexander Blum
Traceback (most recent call last):
126 13 Alexander Blum
  File "/shared/src/collecting_society/tests/test_collecting_society.py", line 24, in test0005views
127 13 Alexander Blum
    test_view('collecting_society')
128 13 Alexander Blum
  File "/shared/src/trytond/trytond/tests/test_tryton.py", line 123, in test_view
129 13 Alexander Blum
    res = Model.fields_view_get(view_id)
130 13 Alexander Blum
  File "/shared/src/trytond/trytond/model/modelview.py", line 237, in fields_view_get
131 13 Alexander Blum
    tree = etree.fromstring(result['arch'], parser)
132 13 Alexander Blum
  File "lxml.etree.pyx", line 3092, in lxml.etree.fromstring (src/lxml/lxml.etree.c:70691)
133 13 Alexander Blum
  File "parser.pxi", line 1827, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:106678)
134 1 Alexander Blum
ValueError: can only parse strings
135 1 Alexander Blum
~~~
136 1 Alexander Blum
137 1 Alexander Blum
Probably some referenced view file in `./views/` is missing.
138 1 Alexander Blum
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).
139 14 Alexander Blum
140 14 Alexander Blum
#### Tryton Views
141 14 Alexander Blum
142 14 Alexander Blum
- 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`.
143 14 Alexander Blum
- If you change the model fields and are missing the changes, sometimes you need to
144 14 Alexander Blum
    1. cut out the `<field>`s within the view xml:
145 14 Alexander Blum
    2. close/open the view
146 14 Alexander Blum
    3. paste the `<field>`s again and
147 14 Alexander Blum
    4. close/open the view
148 13 Alexander Blum
149 3 Thomas Mielke
150 3 Thomas Mielke
## Pyramid
151 3 Thomas Mielke
152 3 Thomas Mielke
2DO