Skip to Content
Menu
This question has been flagged
2 Replies
7333 Views

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
Author 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
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
Related Posts Replies Views Activity
1
Jul 23
1297
1
Feb 21
3098
3
Jun 20
3814
2
Jun 20
4845
0
Jun 20
1746