Help

0

automated actions - store code in files

Avatar
Piavita AG

As i understand, per default, all written python code of automated actions is stored in the database.

Since we are a team and we would like to use a (git) repository for all our code - we are wondering how to store all python code in external files.

Is there any best practice or documentation? How do you share code with your team?        

Avatar
Discard
2 Answers
0
Avatar
Piavita AG
Best Answer

Ah okay, it will work via Modules. Perfect, thanks for the reads! 

For those who are interested:

you can create a new Model with your functions:


from odoo import models, fields
from openerp.exceptions import Warning

class ExternalCode(models.Model):
_name = "external.code"
name = fields.Char(string="Name", required=True)
description = fields.Text("Description")

##
# test function to show how to call a function
# @name - test
# @parameters - none (self is referencing the model itself)
# @return - void
##
def test(self):
# access another model
recordset = self.env['hr.employee'].search([("name", "<>", "Peter")])

nameslist = "I have following names: "

# walk throug data and concatenate model values
for record in recordset:
name = record.name
nameslist += name

# return String in a native Warning window
raise Warning(nameslist)

 
    ##
    # test function to show how to call a function with parameters. It returns
    # the given Parameter in a Warning
    # @name - test
    # @parameters - data(String), (self is referencing the model itself)
    # @return - void 
    ##
    def testWithParameters(selfdata): 
    raise Warning(data)

.

Install your module in Odoo and now you can create a call with those 2 lines:

tool = env["external.code"] 
tool.test()
# or tool.testWithParameters( "anything you need to pass" )


Any suggestions on that? It works fine for me so far



Avatar
Discard
0
Avatar
Ray Carnes
Best Answer

You would use XML to define a record that gets inserted into Odoo.  One of the fields in that record is the Python code that is executed when the action is run.

Look at how Odoo does it:

https://github.com/odoo/odoo/blob/11.0/addons/base_automation/data/base_automation_demo.xml

Review the documentation:

https://www.odoo.com/documentation/11.0/howtos/backend.html#build-an-odoo-module

https://guides.github.com/




Avatar
Discard