Custom Button Throws Error at compile

I want to create a button, so I look at tutorial, but the tutorial it requires Workflow which I don’t.. I just wanna create a button that invoke a classmethod, and print “HELLO WORLD” in console.

So I search and found this , so I follow his steps and I my code became like below:

In a form:

<form>
   <!-- codes here -->
   <button colspan="6" name="add_valuation_item" string=" Add New" icon="tryton-add"/>
   <!-- codes there -->
</form>

In module xml:

        <record model="ir.action.act_window" id="act_proposal_window">
            <field name="name">Proposals</field>
            <field name="res_model">ltl.proposal</field>
            <field name="order" eval="[('create_at','DESC')]" pyson="1"/>
        </record>
        <record model="ir.action.act_window.view" id="act_proposal_window_form">
            <field name="sequence" eval="20"/>
            <field name="view" ref="proposal_view_form"/>
            <field name="act_window" ref="act_proposal_window"/>
        </record>
        <record model="ir.action.act_window.view" id="act_proposal_window_list">
            <field name="sequence" eval="10"/>
            <field name="view" ref="proposal_view_list"/>
            <field name="act_window" ref="act_proposal_window"/>
        </record>
        <!-- ADD VALUATION BUTTON -->
        <record model="ir.model.button" id="add_valuation_button">
            <field name="name">add_valuation_item</field>
            <field name="string">Add New</field>
            <field name="model" search="[('model', '=', 'ltl.proposal')]"/>
        </record>

In Proposal class:

    @classmethod
    def __setup__(cls):
        super(Proposal, cls).__setup__()
        cls._buttons.update({
            'add_valuation_item': {}
        })

    @classmethod
    @ModelView.button
    def add_valuation_item(cls, attribute):
        log.info('>>'*40)
        log.info(f'>>>>>>>>>>>>>>>>>>>> HELLO WORLD')
        log.info('>>'*40)
        return True

Compile time error:

Traceback (most recent call last):
  File "/home/tryton/project/.env/lib/python3.10/site-packages/trytond/convert.py", line 414, in parse_xmlstream
    self.sax_parser.parse(source)
  File "/usr/lib/python3.10/xml/sax/expatreader.py", line 111, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib/python3.10/xml/sax/xmlreader.py", line 125, in parse
    self.feed(buffer)
  File "/usr/lib/python3.10/xml/sax/expatreader.py", line 217, in feed
    self._parser.Parse(data, isFinal)
  File "../Modules/pyexpat.c", line 416, in StartElement
  File "/usr/lib/python3.10/xml/sax/expatreader.py", line 333, in start_element
    self._cont_handler.startElement(name, AttributesImpl(attrs))
  File "/home/tryton/project/.env/lib/python3.10/site-packages/trytond/convert.py", line 446, in startElement
    self.taghandler.startElement(name, attributes)
  File "/home/tryton/project/.env/lib/python3.10/site-packages/trytond/convert.py", line 255, in startElement
    search_model = field.model_name
AttributeError: 'Char' object has no attribute 'model_name'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tryton/project/.env/bin/trytond-admin", line 33, in <module>
    admin.run(options)
  File "/home/tryton/project/.env/lib/python3.10/site-packages/trytond/admin.py", line 59, in run
    pool.init(update=options.update, lang=list(lang),
  File "/home/tryton/project/.env/lib/python3.10/site-packages/trytond/pool.py", line 143, in init
    restart = not load_modules(
  File "/home/tryton/project/.env/lib/python3.10/site-packages/trytond/modules/__init__.py", line 425, in load_modules
    _load_modules(update)
  File "/home/tryton/project/.env/lib/python3.10/site-packages/trytond/modules/__init__.py", line 395, in _load_modules
    load_module_graph(graph, pool, update, lang, indexes)
  File "/home/tryton/project/.env/lib/python3.10/site-packages/trytond/modules/__init__.py", line 238, in load_module_graph
    tryton_parser.parse_xmlstream(fp)
  File "/home/tryton/project/.env/lib/python3.10/site-packages/trytond/convert.py", line 416, in parse_xmlstream
    raise ParsingError("in %s" % self.current_state()) from e
trytond.convert.ParsingError: in record 'ltl_proposal.add_valuation_button'

What to do?.. really need help here

Bromo

Which tryton version are you using?
It seems you are using 7.6 series but your are using the button defintion from older series:

In 7.6 series model is now a char field, so your button should be something like:

Hope this helps!

1 Like

Yes.. it worked @pokoli thanks a lot bro :rofl:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.