HowTo » History » Version 18

Thomas Mielke, 12/06/2020 09:10 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 1 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 4 Thomas Mielke
        docker-compose exec erpserver execute update -m collecting_society
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 13 Alexander Blum
        docker-compose exec erpserver python /shared/src/trytond/trytond/tests/run-tests.py -vvvm collecting_society
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 1 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 1 Alexander Blum
        docker-compose stop
48 16 Alexander Blum
        docker-compose run --rm erpserver bash
49 1 Alexander Blum
50 16 Alexander Blum
        execute pip-install erpserver
51 1 Alexander Blum
52 1 Alexander Blum
2. Delete and setup a new database (`scenario_master_data.txt` only):
53 1 Alexander Blum
54 10 Thomas Mielke
        execute db-delete && execute db-setup --master --force
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 1 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 1 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 1 Alexander Blum
    tryton -d
79 1 Alexander Blum
80 1 Alexander Blum
### Change XML Views
81 1 Alexander Blum
82 11 Udo Spallek
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,
83 1 Alexander Blum
84 1 Alexander Blum
    docker-compose exec erpserver execute update -m collecting_society
85 7 Thomas Mielke
86 11 Udo Spallek
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 11 Udo Spallek
do the following:
88 1 Alexander Blum
89 11 Udo Spallek
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 11 Udo Spallek
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 11 Udo Spallek
1. Update the database: `docker-compose exec erpserver execute update -m collecting_society`
92 11 Udo Spallek
1. Insert the corresponding definitions of the broken view again (undo the deletion)
93 11 Udo Spallek
1. Again update the database: `docker-compose exec erpserver execute update -m collecting_society`
94 12 Udo Spallek
1. Restart the Tryton Client
95 11 Udo Spallek
96 11 Udo Spallek
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:
97 11 Udo Spallek
98 11 Udo Spallek
    tryton --dev
99 1 Alexander Blum
100 1 Alexander Blum
### Change DB Tests
101 1 Alexander Blum
102 15 Alexander Blum
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.
103 1 Alexander Blum
104 15 Alexander Blum
1. Log into a test_erpserver service
105 1 Alexander Blum
106 17 Thomas Mielke
        docker-compose run --rm --service-ports erpserver bash
107 1 Alexander Blum
108 15 Alexander Blum
        execute pip-install erpserver
109 1 Alexander Blum
110 15 Alexander Blum
2. Delete and setup a clean database template (`master.txt` only):
111 1 Alexander Blum
112 15 Alexander Blum
        execute db-delete test_template && execute db-setup --master test_template
113 1 Alexander Blum
114 1 Alexander Blum
3. Delete the database, copy the database template and setup the data to test, pipe the output into a logfile:
115 1 Alexander Blum
116 15 Alexander Blum
        export TRYTON_DEMODATA_DEBUG=1
117 15 Alexander Blum
        execute db-delete test && execute db-copy test_template test && execute db-setup --demo --force test
118 1 Alexander Blum
119 15 Alexander Blum
    Start with `TRYTON_DEMODATA_DEBUG=1` to set all configuration variables to 1.
120 15 Alexander Blum
    If that works, try `TRYTON_DEMODATA_DEBUG=2` afterwards, as some objects might not be created due to the low sample size.
121 1 Alexander Blum
122 1 Alexander Blum
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:
123 1 Alexander Blum
124 1 Alexander Blum
        import interlude; interlude.interact(locals())
125 1 Alexander Blum
126 1 Alexander Blum
    You can always find that command in the import section at the top of the scenario files, if you want to copy & paste it.
127 1 Alexander Blum
128 15 Alexander Blum
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):
129 1 Alexander Blum
130 17 Thomas Mielke
        docker exec -it $(docker ps -a | grep ":8000" | cut -d' ' -f1) bash
131 1 Alexander Blum
132 15 Alexander Blum
        execute deploy-erpserver
133 1 Alexander Blum
134 15 Alexander Blum
    Restart the tryton client with cache disabled and connect to the `test` database:
135 15 Alexander Blum
136 1 Alexander Blum
        tryton -d
137 1 Alexander Blum
138 15 Alexander Blum
6. Do a final test run via `./scripts/test` (ensure `TRYTON_DEMODATA_DEBUG=0`).
139 1 Alexander Blum
140 18 Thomas Mielke
*Note:*
141 18 Thomas Mielke
142 18 Thomas Mielke
In the future (year > 2020) we will move from doctests to a new database import script that handles dependencies. The workflow will differ slightly from the doctests import script. To give you a glimpse of the new import script, see below...
143 18 Thomas Mielke
144 18 Thomas Mielke
The followint entry is for debugging demo data generation in volumes/shared/data. To create all dependencies for a so called 'leaf' dataset, for example 'sales' enter:
145 18 Thomas Mielke
146 18 Thomas Mielke
    $ execute db-rebuild --dataset sales
147 18 Thomas Mielke
148 18 Thomas Mielke
which will create a Postgres template with a snapshot from before sales is applied. To debug sales and apply it again to the stored template use the --cache option:
149 18 Thomas Mielke
150 18 Thomas Mielke
    $ execute db-rebuild --dataset collecting_societies --cache
151 18 Thomas Mielke
152 18 Thomas Mielke
if satisfied with sales, you may want to move on to a new dataset that depends on sales, e.g. sales_statistics, you could enter:
153 18 Thomas Mielke
154 18 Thomas Mielke
    $ execute db-copy --force collecting_society collecting_society_template
155 18 Thomas Mielke
156 14 Alexander Blum
### Errors
157 1 Alexander Blum
158 14 Alexander Blum
#### Pyramid View
159 14 Alexander Blum
160 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:
161 1 Alexander Blum
162 1 Alexander Blum
1. Open an interactive console, where one of the following keywords are passed as parameter: fieldname, error_args
163 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.
164 1 Alexander Blum
165 14 Alexander Blum
#### Proteus
166 1 Alexander Blum
167 14 Alexander Blum
Errors in proteus are sometimes cryptic. See here for English and German translations:
168 1 Alexander Blum
169 1 Alexander Blum
http://hg.tryton.org/trytond/file/tip/trytond/ir/locale/de.po
170 13 Alexander Blum
171 14 Alexander Blum
#### Tryton Tests
172 13 Alexander Blum
173 13 Alexander Blum
~~~
174 13 Alexander Blum
======================================================================
175 13 Alexander Blum
ERROR: test0005views (trytond.modules.collecting_society.tests.test_collecting_society.CollectingSocietyTestCase)
176 13 Alexander Blum
----------------------------------------------------------------------
177 13 Alexander Blum
Traceback (most recent call last):
178 13 Alexander Blum
  File "/shared/src/collecting_society/tests/test_collecting_society.py", line 24, in test0005views
179 13 Alexander Blum
    test_view('collecting_society')
180 13 Alexander Blum
  File "/shared/src/trytond/trytond/tests/test_tryton.py", line 123, in test_view
181 13 Alexander Blum
    res = Model.fields_view_get(view_id)
182 13 Alexander Blum
  File "/shared/src/trytond/trytond/model/modelview.py", line 237, in fields_view_get
183 13 Alexander Blum
    tree = etree.fromstring(result['arch'], parser)
184 13 Alexander Blum
  File "lxml.etree.pyx", line 3092, in lxml.etree.fromstring (src/lxml/lxml.etree.c:70691)
185 13 Alexander Blum
  File "parser.pxi", line 1827, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:106678)
186 1 Alexander Blum
ValueError: can only parse strings
187 1 Alexander Blum
~~~
188 1 Alexander Blum
189 1 Alexander Blum
Probably some referenced view file in `./views/` is missing.
190 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).
191 14 Alexander Blum
192 14 Alexander Blum
#### Tryton Views
193 14 Alexander Blum
194 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`.
195 14 Alexander Blum
- If you change the model fields and are missing the changes, sometimes you need to
196 14 Alexander Blum
    1. cut out the `<field>`s within the view xml:
197 14 Alexander Blum
    2. close/open the view
198 14 Alexander Blum
    3. paste the `<field>`s again and
199 14 Alexander Blum
    4. close/open the view
200 13 Alexander Blum
201 3 Thomas Mielke
202 3 Thomas Mielke
## Pyramid
203 3 Thomas Mielke
204 3 Thomas Mielke
2DO