Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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))
About This Community
This platform 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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 1/9/16, 8:36 PM|
|Seen: 618 times|
|Last updated: 2/5/16, 5:44 PM|