why doesn' t this field get assigned ?

41 views
Skip to first unread message

Cato Nano

unread,
Jan 10, 2018, 12:03:15 PM1/10/18
to tryton
I have these 2 fields

numeroGiorni = fields.Function(fields.Integer('Numero Giorni'),'on_change_with_numeroGiorni')
@fields.depends('dataInizio', 'dataFine')
def on_change_with_numeroGiorni(self, name=None):
if self.dataInizio and self.dataFine:
return abs((self.dataFine - self.dataInizio).days) + 1
return 0

[...]

fattoreGiorni = fields.Function(fields.Numeric('fattoreGiorni'), 'on_change_with_fattoreGiorni')

@fields.depends('numeroGiorni')
def on_change_with_fattoreGiorni(self, name=None):
return (self.numeroGiorni - 10) / 5


fattoreGiorni DOESN'T get assigned
I can't see why

Cédric Krier

unread,
Jan 12, 2018, 5:45:06 PM1/12/18
to tryton
It is difficult to answer without having more information about the
scenario you are following.

But already there are some potential issues like using the value of a
field without checking if it is not 'None'.
Also be aware that Function fields does not trigger other on_change*,
indeed you must make the other one depending on the first one. It should
look like that:

@fields.depends(methods='numeroGiorni')
def on_change_with_fattoreGiorni(self, name=None):
numeroGiorni = self.on_change_with_numeroGiorni()
return (numeroGiorni - 10) / 5

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

Cato Nano

unread,
Jan 13, 2018, 4:31:26 AM1/13/18
to tryton
So with this variant of yours, when I issue

trytond-admin -c ./trytond.conf -d tryton -u tributi


I get these errors

Traceback (most recent call last):
File "/home/catonano/tributi/env/bin/trytond-admin", line 21, in <module>
admin.run(options)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/admin.py", line 54, in run
installdeps=options.installdeps)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/pool.py", line 153, in init
lang=lang, installdeps=installdeps)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 462, in load_modules
_load_modules(update)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 432, in _load_modules
load_module_graph(graph, pool, update, lang)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 229, in load_module_graph
pool.setup(classes)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/pool.py", line 227, in setup
cls.__post_setup__()
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/model/modelview.py", line 195, in __post_setup__
other_field = getattr(cls, other)
AttributeError: type object 'tributi.affissione' has no attribute 'i'



and


Traceback (most recent call last):
File "/home/catonano/tributi/env/bin/trytond-admin", line 21, in <module>
admin.run(options)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/admin.py", line 54, in run
installdeps=options.installdeps)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/pool.py", line 153, in init
lang=lang, installdeps=installdeps)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 462, in load_modules
_load_modules(update)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 432, in _load_modules
load_module_graph(graph, pool, update, lang)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 229, in load_module_graph
pool.setup(classes)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/pool.py", line 227, in setup
cls.__post_setup__()
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/model/modelview.py", line 195, in __post_setup__
other_field = getattr(cls, other)
AttributeError: type object 'tributi.affissione' has no attribute 'n'



and

Traceback (most recent call last):
File "/home/catonano/tributi/env/bin/trytond-admin", line 21, in <module>
admin.run(options)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/admin.py", line 54, in run
installdeps=options.installdeps)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/pool.py", line 153, in init
lang=lang, installdeps=installdeps)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 462, in load_modules
_load_modules(update)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 432, in _load_modules
load_module_graph(graph, pool, update, lang)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 229, in load_module_graph
pool.setup(classes)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/pool.py", line 227, in setup
cls.__post_setup__()
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/model/modelview.py", line 195, in __post_setup__
other_field = getattr(cls, other)
AttributeError: type object 'tributi.affissione' has no attribute 'G'


and


Traceback (most recent call last):
File "/home/catonano/tributi/env/bin/trytond-admin", line 21, in <module>
admin.run(options)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/admin.py", line 54, in run
installdeps=options.installdeps)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/pool.py", line 153, in init
lang=lang, installdeps=installdeps)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 462, in load_modules
_load_modules(update)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 432, in _load_modules
load_module_graph(graph, pool, update, lang)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 229, in load_module_graph
pool.setup(classes)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/pool.py", line 227, in setup
cls.__post_setup__()
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/model/modelview.py", line 195, in __post_setup__
other_field = getattr(cls, other)
AttributeError: type object 'tributi.affissione' has no attribute 'u'


and

Traceback (most recent call last):
File "/home/catonano/tributi/env/bin/trytond-admin", line 21, in <module>
admin.run(options)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/admin.py", line 54, in run
installdeps=options.installdeps)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/pool.py", line 153, in init
lang=lang, installdeps=installdeps)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 462, in load_modules
_load_modules(update)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 432, in _load_modules
load_module_graph(graph, pool, update, lang)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 229, in load_module_graph
pool.setup(classes)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/pool.py", line 227, in setup
cls.__post_setup__()
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/model/modelview.py", line 195, in __post_setup__
other_field = getattr(cls, other)
AttributeError: type object 'tributi.affissione' has no attribute 'o'



and


Traceback (most recent call last):
File "/home/catonano/tributi/env/bin/trytond-admin", line 21, in <module>
admin.run(options)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/admin.py", line 54, in run
installdeps=options.installdeps)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/pool.py", line 153, in init
lang=lang, installdeps=installdeps)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 462, in load_modules
_load_modules(update)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 432, in _load_modules
load_module_graph(graph, pool, update, lang)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py", line 229, in load_module_graph
pool.setup(classes)
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/pool.py", line 227, in setup
cls.__post_setup__()
File "/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/model/modelview.py", line 195, in __post_setup__
other_field = getattr(cls, other)
AttributeError: type object 'tributi.affissione' has no attribute 'e'


So, wrapping up, type object 'tributi.affissione' has no attribute

e
o
u
G
n
i

they seem the letters composing "numeroGiorni" but I might be wrong

I remind you that the code is here
https://gitlab.com/humanitiesNerd/tributi

Cédric Krier

unread,
Jan 13, 2018, 5:05:07 AM1/13/18
to tryton
See correction above.

Cato Nano

unread,
Jan 16, 2018, 4:17:09 AM1/16/18
to tryton
I think it could be

@fields.depends(methods=['numeroGiorni'])
def on_change_with_fattoreGiorni(self, name=None):
numeroGiorni = self.on_change_with_numeroGiorni()
return (numeroGiorni - 10) / 5

with square brackets around 'numeroGiorni'

I can' t try right now, but I will. Soon
Reply all
Reply to author
Forward
0 new messages