HowTo » History » Version 14

Alexander Blum, 02/16/2020 05:23 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 5 Thomas Mielke
        docker-compose run erpserver bash
49 1 Alexander Blum
50 6 Thomas Mielke
        execute pip-install tryton
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 1 Alexander Blum
If you want/need to change the database tests (`ado/etc/scenario_demo_data.txt`), you want to create and setup a new database template (e.g. `c3s_template`) and use a copy of it as the starting point for the test/demo setup.
103 1 Alexander Blum
104 1 Alexander Blum
1. Log into a tryton (only) service
105 1 Alexander Blum
106 5 Thomas Mielke
        docker-compose run erpserver bash
107 1 Alexander Blum
108 6 Thomas Mielke
        execute pip-install tryton
109 1 Alexander Blum
110 1 Alexander Blum
2. Delete and setup a clean database template (`scenario_master_data.txt` only), if not already available:
111 1 Alexander Blum
112 6 Thomas Mielke
        execute db-delete c3s_template && execute db-setup --master c3s_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 8 Thomas Mielke
        execute db-delete c3s && execute db-copy c3s_template c3s && execute db-setup --demo --force
117 1 Alexander Blum
118 1 Alexander Blum
    Start with `debug = 1` in the configuration section to set all configuration variables to 1.
119 1 Alexander Blum
    If that works, try `debug = 2` afterwards, as some objects might not be created due to the low sample size.
120 1 Alexander Blum
    Don't forget to set it back to `debug = False`, when you are finished.
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 1 Alexander Blum
5. To validate the test data, start a tryton (only) service on second terminal (to be able to rebuild the database on the first terminal, if neccessary):
129 1 Alexander Blum
130 1 Alexander Blum
        docker-compose up tryton
131 1 Alexander Blum
132 1 Alexander Blum
    Restart the tryton client with cache disabled:
133 1 Alexander Blum
134 1 Alexander Blum
        tryton -d
135 1 Alexander Blum
136 1 Alexander Blum
6. Set `debug = False` in the configuration section and do a final test run.
137 1 Alexander Blum
138 14 Alexander Blum
### Errors
139 1 Alexander Blum
140 14 Alexander Blum
#### Pyramid View
141 14 Alexander Blum
142 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:
143 1 Alexander Blum
144 1 Alexander Blum
1. Open an interactive console, where one of the following keywords are passed as parameter: fieldname, error_args
145 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.
146 1 Alexander Blum
147 14 Alexander Blum
#### Proteus
148 1 Alexander Blum
149 14 Alexander Blum
Errors in proteus are sometimes cryptic. See here for English and German translations:
150 1 Alexander Blum
151 1 Alexander Blum
http://hg.tryton.org/trytond/file/tip/trytond/ir/locale/de.po
152 13 Alexander Blum
153 14 Alexander Blum
#### Tryton Tests
154 13 Alexander Blum
155 13 Alexander Blum
~~~
156 13 Alexander Blum
======================================================================
157 13 Alexander Blum
ERROR: test0005views (trytond.modules.collecting_society.tests.test_collecting_society.CollectingSocietyTestCase)
158 13 Alexander Blum
----------------------------------------------------------------------
159 13 Alexander Blum
Traceback (most recent call last):
160 13 Alexander Blum
  File "/shared/src/collecting_society/tests/test_collecting_society.py", line 24, in test0005views
161 13 Alexander Blum
    test_view('collecting_society')
162 13 Alexander Blum
  File "/shared/src/trytond/trytond/tests/test_tryton.py", line 123, in test_view
163 13 Alexander Blum
    res = Model.fields_view_get(view_id)
164 13 Alexander Blum
  File "/shared/src/trytond/trytond/model/modelview.py", line 237, in fields_view_get
165 13 Alexander Blum
    tree = etree.fromstring(result['arch'], parser)
166 13 Alexander Blum
  File "lxml.etree.pyx", line 3092, in lxml.etree.fromstring (src/lxml/lxml.etree.c:70691)
167 13 Alexander Blum
  File "parser.pxi", line 1827, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:106678)
168 1 Alexander Blum
ValueError: can only parse strings
169 1 Alexander Blum
~~~
170 1 Alexander Blum
171 1 Alexander Blum
Probably some referenced view file in `./views/` is missing.
172 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).
173 14 Alexander Blum
174 14 Alexander Blum
#### Tryton Views
175 14 Alexander Blum
176 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`.
177 14 Alexander Blum
- If you change the model fields and are missing the changes, sometimes you need to
178 14 Alexander Blum
    1. cut out the `<field>`s within the view xml:
179 14 Alexander Blum
    2. close/open the view
180 14 Alexander Blum
    3. paste the `<field>`s again and
181 14 Alexander Blum
    4. close/open the view
182 13 Alexander Blum
183 3 Thomas Mielke
184 3 Thomas Mielke
## Pyramid
185 3 Thomas Mielke
186 3 Thomas Mielke
2DO