Skip to Content
Menu
This question has been flagged
2 Replies
4617 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




Avatar
Discard

Thanks!


This solve my problem!

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

Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
2
Jul 22
4923
1
Oct 21
3511
2
Jul 21
5444
2
May 19
5105
2
May 19
7760