Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to have this method available everywhere in other odoo python files?

By
Pascal Tremblay
on 3/2/15, 4:59 AM 682 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

1
Jordan Vrtanoski
On 3/2/15, 5:23 AM

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

0

Pascal Tremblay

--Pascal Tremblay--
1312
| 5 2 7
Alma, Canada
--Pascal Tremblay--


Pascal Tremblay
On 3/2/15, 6:24 AM

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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 3/2/15, 4:59 AM
Seen: 682 times
Last updated: 3/16/15, 8:10 AM