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

Hello guys,

I have writen this little function/method. I would want to use it in many pyhton files.

How to get it available everywhere and how to call it?


def whichCompanyPrefix(self):
    
        self.cr, self.uid, self.pool = request.cr, request.uid, request.registry
        user = self.pool["res.users"].browse(self.cr, self.uid, self.uid)
    
        company_id = user.company_id.id

        company_name = user.company_id.name

        company_prefix = user.company_id.x_company_prefix
        
        if not company_prefix :
            company_prefix = 'ZZ'


        return company_prefix

THANKS

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

You need to create new model or override an existing model and add the method there. After that you can use the self.env['module_name'].whichCompanyPrefix

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

This works too. I hope it is ok too.

In the file /Users/Flooder/.mount-odoo-test/addons/report_lapagept/controllers/control_pt.py :

def whichCompanyPrefix(self):
        self.cr, self.uid, self.pool = request.cr, request.uid, request.registry
        user = self.pool["res.users"].browse(self.cr, self.uid, self.uid)
        company_id = user.company_id.id
        company_name = user.company_id.name
        company_prefix = user.company_id.x_company_prefix
        if not company_prefix :
            company_prefix = 'ZZ'
        return company_prefix

In the file /Users/Flooder/.mount-odoo-test/addons/report_lapagept/controllers/main_pt.py, I could call whichCompanyPrefix like this :

from openerp.addons.report_lapagept.controllers.control_pt import whichCompanyPrefix
class PTPosController(PosController):

    def a(self, debug=False, **k):

        prefix = whichCompanyPrefix(self)

 

May be it could help somebody.

Ảnh đại diện
Huỷ bỏ