What is the fields_child and context_model

28 views
Skip to first unread message

Markus Bala

unread,
Sep 30, 2018, 12:56:12 PM9/30/18
to tryton-dev
Line 01) <record model="ir.ui.view" id="account_balance_sheet_view_tree">
Line 02) <field name="model">account.account.type</field>
Line 03) <field name="type">tree</field>
Line 04) <field name="field_childs">childs</field>
Line 05) <field name="name">account_balance_sheet_tree</field>
Line 06) </record>
Line 07) <record model="ir.action.act_window" id="act_account_balance_sheet_tree">
Line 08) <field name="name">Balance Sheet</field>
Line 09) <field name="res_model">account.account.type</field>
Line 10) <field name="context_model">account.balance_sheet.context</field>
Line 11) <field name="context_domain"
Line 12) eval="[('company', '=', Eval('company', -1))]"
Line 13) pyson="1"/>
Line 14) <field name="domain"
Line 15) eval="[('balance_sheet', '=', True), ['OR', ('parent', '=', None), ('parent.balance_sheet', '=', False)]]"
Line 16) pyson="1"/>
Line 17) <field name="context" eval="{'cumulate': True}" pyson="1"/>
Line 18) </record>

I found the balance_sheet reporting.
But I do not undertstand what is the field_childs at the line 04.
And what is the "context_model" at the line 10.?

Especially the context_model? because it already has res_model

Cédric Krier

unread,
Oct 1, 2018, 3:35:05 AM10/1/18
to tryton-dev
On 2018-09-30 09:56, Markus Bala wrote:
> I found the balance_sheet reporting.
> But I do not undertstand what is the field_childs at the line 04.

It is to define a tree:
https://tryton-readthedocs.readthedocs.io/projects/server/en/latest/topics/views/index.html?highlight=field_childs#tree-view

> And what is the "context_model" at the line 10.?

It is the model to display on top of the list to alter the context of
the view.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Markus Bala

unread,
Oct 1, 2018, 4:04:16 AM10/1/18
to tryton-dev
Noted.

the context_model --> is almost similar with wizard.
But when I try using context_model, i am going to do some "save" to model.
It prompt error psycopg2, cannot execute INSERT because is readonly-transaction

is it normal?

Cédric Krier

unread,
Oct 1, 2018, 4:30:04 AM10/1/18
to tryton-dev
On 2018-10-01 01:04, Markus Bala wrote:
> But when I try using context_model, i am going to do some "save" to model.

I do not understand. the context model is only used by the client.

> It prompt error psycopg2, cannot execute INSERT because is readonly-transaction

On which kind of RPC call are you doing a save?

Markus Bala

unread,
Oct 1, 2018, 4:55:01 AM10/1/18
to tryton-dev
Traceback (most recent call last):
File "/trytond/wsgi.py", line 71, in dispatch_request
return endpoint(request, **request.view_args)
File "/trytond/protocols/dispatcher.py", line 41, in rpc
request, database_name, *request.rpc_params)
File "/trytond/wsgi.py", line 42, in auth_required
return wrapped(*args, **kwargs)
File "/trytond/protocols/wrappers.py", line 122, in wrapper
return func(request, pool, *args, **kwargs)
File "/trytond/protocols/dispatcher.py", line 172, in _dispatch
result = rpc.result(meth(inst, *c_args, **c_kwargs))
File "/trytond/model/modelview.py", line 677, in on_change
method()
File "/trytond/model/modelview.py", line 84, in wrapper
result = func(self, *args, **kwargs)
File "/trytond/model/fields/field.py", line 114, in wrapper
return func(self, *args, **kwargs)
File "/trytond/modules/tri_jda/jda.py", line 189, in on_change_lodnum
rec.save(recs)
File "/trytond/model/descriptors.py", line 33, in newfunc
return self.func(owner, *args, **kwargs)
File "/trytond/model/modelstorage.py", line 1532, in save
news = cls.create([save_values[r] for r in to_create])
File "/trytond/model/modelsql.py", line 580, in create
[insert_values], [table.id]))
File "/trytond/backend/postgresql/database.py", line 61, in execute
cursor.execute(self, sql, args)
psycopg2.InternalError: cannot execute INSERT in a read-only transaction


---------------------------------
Above is my stacktrace.

I am going to integrate with some WMS system for receiving. When user input the PO number which is "Lodnum" then tryton "on_change" and will display the WMS data to the list (MS SQL Server).

Background, after "on_change", I will read data from MSSQL. And insert to Tryton postgres.
But when inserted, above error occurred.

Cédric Krier

unread,
Oct 1, 2018, 5:16:05 AM10/1/18
to tryton-dev
On 2018-10-01 01:55, Markus Bala wrote:
> > > It prompt error psycopg2, cannot execute INSERT because is readonly-transaction
> >
> > On which kind of RPC call are you doing a save?
>
on_change calls are always read-only to enforce good design and
practice. You can not save in the database something that the user did
not save yet. Instead you must just send modification to the client by
setting fields (without saving).

Markus Bala

unread,
Oct 1, 2018, 5:52:40 AM10/1/18
to tryton-dev
for ModelSQL , we can set by "self.field = value".
But how to setting the fields for context_model?

Cédric Krier

unread,
Oct 1, 2018, 6:21:04 AM10/1/18
to tryton-dev
On 2018-10-01 02:52, Markus Bala wrote:
> > > I am going to integrate with some WMS system for receiving. When user input the PO number which is "Lodnum" then tryton "on_change" and will display the WMS data to the list (MS SQL Server).
> > >
> > > Background, after "on_change", I will read data from MSSQL. And insert to Tryton postgres.
> > > But when inserted, above error occurred.
> >
> > on_change calls are always read-only to enforce good design and
> > practice. You can not save in the database something that the user did
> > not save yet. Instead you must just send modification to the client by
> > setting fields (without saving).
>
> for ModelSQL , we can set by "self.field = value".
> But how to setting the fields for context_model?

It is set by the context. Otherwise, it is a model like the others, you
can define on_change on it etc.
Reply all
Reply to author
Forward
0 new messages