Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

External command inside a Button?

By
Cezar Jr
on 1/9/16, 8:36 PM 419 views

It is possible to add a external python method?

I am writing a code to send a package, through my network, this package command a lock and was wondering  if it is possible to import that code inside a Button, so I can active that lock from a FORM VIEW.

This is the command: conn.sendall(vd_comms.setGateOpen(_tid))

Thanks

Cezar




Thanks!


This solve my problem!

Cezar Jr
on 1/10/16, 8:28 AM

No problem Cezar! Don't forget to upvote / accept an answer if it has helped you. :)

Yenthe
on 1/10/16, 10:06 AM
1

Yenthe

--Yenthe--
6676
| 7 7 8
Turnhout, Belgium
--Yenthe--

My Odoo blog: http://www.odoo.yenthevg.com/

My Twitter: https://twitter.com/Yenthe666

Yenthe
On 1/10/16, 4:02 AM

Hi Cezar Jr,

Ofcourse this is possible! Just add the code inside your function that is triggered by a button. Don't forget to import your external Python library though! Let me show you an example. A new form with a button (xml):

<openerp> <data> <record model="ir.ui.view" id="view_buttons_form"> <field name="name">Buttons</field> <field name="model">button.demo</field> <field name="type">form</field> <field name="arch" type="xml"> <form string="Button record"> <!--The header tag is built to add buttons within. This puts them at the top --> <header> <!--The oe_highlight class gives the button a red color when it is saved. It is usually used to indicate the expected behaviour. --> <button string="Run external function" type="object" name="run_external_function" class="oe_highlight"/> </header> <group> <field name="name"/> </group> </form> </field> </record> </data> </openerp>

This part of the code will link to a Python function:

<button string="Run external function" type="object" name="run_external_function" class="oe_highlight"/>

Next just create a Python function that calls your code:

# WARNING! @api.one is deprecated in Odoo 9, use @api.multi with ensure_one instead! @api.one def run_external_function(self): #From here on you can execute all the code you want. Don't forget to import the external Python library at the top though! conn.sendall(vd_comms.setGateOpen(_tid))

Yenthe

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/9/16, 8:36 PM
Seen: 419 times
Last updated: 2/5/16, 5:44 PM