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))
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):
This part of the code will link to a Python function:
<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>
<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))
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
|Asked: 1/9/16, 8:36 PM|
|Seen: 384 times|
|Last updated: 2/5/16, 5:44 PM|