Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
8202 Lượt xem

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?        

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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/




Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 23
2486
1
thg 2 21
4432
3
thg 6 20
5154
2
thg 6 20
5769
0
thg 6 20
2708