Hi i want to know : is the empty value for a field linked with a Many2One relation on reports during printing is it a bug !!!
this is my code :
on the ClassA , i was called a field1:
My problem that when i When I leave the field1 blank (without fill it out)
there was an error :
File "/Genshi-0.7.5-py3.8.egg/genshi/template/eval.py", line 397, in undefined
raise UndefinedError(key, owner=owner)
genshi.template.eval.UndefinedError: None has no member named "code"
Well it is a bug but in your code. You can not access attribute if there is no record. You must define explicitly a fallback behavior if the record is empty.
Usually we use such expression in this case: class_a.field1.rec_name if class_a.field1 else ''
But you may want to display a different fallback value than an empty string.
thank you for the The quick answer , but i doesn’t also work with me , i try this yesterday but the same error shown
File "/Genshi-0.7.5-py3.8.egg/genshi/template/base.py", line 291, in _eval_expr
retval = expr.evaluate(ctxt)
File "/Genshi-0.7.5-py3.8.egg/genshi/template/eval.py", line 160, in evaluate
return eval(self.code, _globals, {'__data__': data})
File "<string>", line 390, in <Expression '__relatorio_escape_invalid_chars(class_a.field1.code)'>
File "/Genshi-0.7.5-py3.8.egg/genshi/template/eval.py", line 309, in lookup_attr
val = cls.undefined(key, owner=obj)
File "/Genshi-0.7.5-py3.8.egg/genshi/template/eval.py", line 397, in undefined
raise UndefinedError(key, owner=owner)
genshi.template.eval.UndefinedError: None has no member named "code"
i do no why it keeps talking in the error about code and me i register it class_a.field1.rec_name (no word "code)
this is the code i put it as u said : <table:table-cell table:style-name="Table1.D5" office:value-type="string"> <text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"><if test="class_a.field1.rec_name if class_a.field1 else "" "></text:placeholder></text:p> <text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"></if></text:placeholder></text:p> </table:table-cell>
is their another special step i should do it in the code python !
Look at your class SaleCode, you have a function get_rec_name there. This is called when you want to show the class_a.field1.rec_name. So it wants to return the contents of the field code, but it can’t. So you have to add the fallback their, rather then in your report.
but always the same error when i try to print the report .
File "<string>", line 390, in <Expression '__relatorio_escape_invalid_chars(class_a.field1.code)'>
genshi.template.eval.UndefinedError: None has no member named "code"
still have somewhere in your report a link to the code field
changing the wrong report
You can test this by removing basically everything from your report. If the errors still comes up, you are editing the wrong report or Tryton uses it’s cache (which I think can be cleared by restarting Tryton server)