Hi,
When I add the button declaration in .xml file like this:
<record model="ir.model.button" id="position_cancel_button">
<field name="model">trade.position</field>
<field name="name">cancel</field>
<field name="string">Cancel</field>
</record>
I get this error:
File “/usr/local/lib/python3.9/dist-packages/trytond/model/fields/many2one.py”, line 126, in sql_format
value = int(value)
ValueError: invalid literal for int() with base 10: ‘trade.position’
cancel button is also added in .py file like that:
cls._buttons.update({
‘cancel’: {},})
Tks in advance,
Laurent
ced
(Cédric Krier)
June 8, 2024, 2:08pm
2
Depending on the Tryton version the model of ir.model.button is a Char (which is your XML version) or a Many2One (which should use search attribute).
Ok it’s a Many2One I see it in model.py in ModelButton class:
model = fields.Many2One(‘ir.model’, ‘Model’, required=True, readonly=True,
ondelete=‘CASCADE’)
So in this case I should manage it only in .py file not in xml, is it what you call “using search attribute” ?
ced
(Cédric Krier)
June 8, 2024, 2:40pm
4
It is the search attribute of the XML data like
<field name="model" search="[('model', '=', 'trade.position')]"/>
I did 2 things but still same error:
1: adding last line with "search_value" on the form containing the button
<record model="ir.action.act_window" id="act_position_form">
<field name="name">Positions</field>
<field name="order"
eval="[('position_id', 'DESC')]"
pyson="1"/>
<field name="res_model">trade.position</field>
<field name="context_model">trade.position.context</field>
<field name="search_value"></field>
</record>
2: Adding search attribute:
<record model="ir.model.button" id="position_cancel_button">
<field name="model" search="[('model', '=', 'trade.position')]"/>
<field name="name">cancel</field>
<field name="string">Cancel</field>
</record>
in my version of Tryton 6.8.0 I see in sales.py :
<record model="ir.model.button" id="sale_cancel_button">
<field name="model">sale.sale</field>
<field name="name">cancel</field>
<field name="string">Cancel</field>
</record>
Ah no sorry my bad I see :
<record model="ir.model.button" id="sale_cancel_button">
<field name="name">cancel</field>
<field name="string">Cancel</field>
<field name="model" search="[('model', '=', 'sale.sale')]"/>
</record>
And I also see this part for all the button:
<record model="ir.model.button-res.group" id="sale_cancel_button_group_sale">
<field name="button" ref="sale_cancel_button"/>
<field name="group" ref="group_sale"/>
</record>
Is it mandatory to add ?
ced
(Cédric Krier)
June 8, 2024, 3:28pm
9
lb1975:
Is it mandatory to add ?
See Access Rights — Tryton server
lb1975
June 8, 2024, 3:44pm
10
Ok but I think it’s not the cause of the compilation error no ?
What is strange is that even if I search by id I have against the same error:
<record model="ir.model.button" id="position_cancel_button">
<field name="name">cancel</field>
<field name="string">Cancel</field>
<field name="model" search="[('id', '=', 142)]"/>
</record>
File “/usr/local/lib/python3.9/dist-packages/trytond/model/fields/many2one.py”, line 126, in sql_format
value = int(value)
ValueError: invalid literal for int() with base 10: ‘trade.position’
lb1975
June 8, 2024, 3:48pm
11
I see that the field model in ir_model table is type: “character varying”
It should be integer ?
lb1975
June 8, 2024, 7:22pm
12
Ok problem solved tks Cedric for assistance in weekend search attribute was enough