Isaac Balam
Isaac Balam

Reputation: 37

extend python function in odoo from another custom python?

how can i extend a python function from another py with params in same folder in framework odoo?. for example:

main.py

class account_invoice(osv.osv):
    _inherit = 'account.invoice'

    def create(self, cr, uid, ids, vals, context=None):
        get_xml = self._generate_xml(ids.xml)

library.py

class library_invoice(osv.osv):

    def _generate_xml(self,xml):
        build xml......
        return xml

thanks in advance.

Upvotes: 0

Views: 1327

Answers (2)

Isaac Balam
Isaac Balam

Reputation: 37

Finaly done

first, i need to load the file in the init.py

import main

import library #for exmaple

after, its able call the funcion anywhere main.py by self.pool.get like this

from library import library_invoice var = self.pool.get('library.invoice')._generate_xml(param)

Upvotes: 0

forvas
forvas

Reputation: 10189

If you want to extend a python function in Odoo, you can do it by writing:

def _generate_xml(self,xml):
   get_xml = super(account_invoice, self)._generate_xml(xml)
   # And from now on you can add whatever you want...

NOTE

I've just realized that you are trying to extend the method in a class which does not inherit from account.invoice. To be honest, I've never tried to extend a function from a class which does not inherit from the class where the original method was declared. I'm not sure if that's possible.

Upvotes: 1

Related Questions