This question has been flagged
2 Replies
2576 Views

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

Avatar
Discard
Best Answer

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

Avatar
Discard
Author Best Answer

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.

Avatar
Discard