تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
8176 أدوات العرض

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?        

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

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



الصورة الرمزية
إهمال
أفضل إجابة

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/




الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يوليو 23
2476
1
فبراير 21
4431
3
يونيو 20
5144
2
يونيو 20
5752
0
يونيو 20
2705