Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
35262 Visualizzazioni

Hello,

I found a guy had solved the same problem here:

\http://stackoverflow.com/questions/32859723/odoo-how-to-override-original-function

So I imitated to override a method of 'stock.inventory' class:


class StockInventoryInherit(models.Model):
_inherit = 'stock.inventory'

def _default_stock_location(self, cr, uid, context=None):
logger.info("_____________-------------------_____________")
logger.info("_____________-------------------_____________")
logger.info("_____________-------------------_____________")
return 19

But nothing changes.

What am I doing wrong?

Please help.

Thank you.

---


Avatar
Abbandona
Autore

It seems to be that private methods (which start with underscore _) can not be override. I tested with a public method and it worked. But I want to override that private one. Any idea? thank you.

Risposta migliore

Hello Loyal,


For overriding method, You should called super() for it.


For Ex:-

class StockInventoryInherit(models.Model):

_inherit = 'stock.inventory'


    def _stock_inventory_default_stock_location(self, cr, uid, context=None):

        res = super(StockInventoryInherit, self)._stock_inventory_default_stock_location(cr, uid, context=context)

        return res


Hope it works for you.

Thanks,


Avatar
Abbandona
Autore

Hi Jignesh Mehta, thank you for your answer. I am sorry, I did not make my self clear. My problem is my method was NOT called. Only the original method in 'stock' module was called.

Hello, For override any base method, You should called super(). Just call print "res :::" in my method.

Autore

yeah I would call super() if my method was called. But currently Odoo does not run into my function. MY FUNCTION WAS NOT CALLED. My problem is only that.

can you post your code ?

Autore

It seems to be that private methods (which start with underscore _) can not be override. I tested with a public method and it worked. But I want to override that private one. Any idea? thank you.

Autore

My (main) code is like above, the method I want to override is stock.py --> class stock_inventory --> method _default_stock_location

Hello, Try with my updated answer.

Autore

Hi Jignesh Mehta, thank you for your help. That still does not work. I have found the same question: https://www.odoo.com/forum/help-1/question/how-to-override-private-method-account-invoice-line-25187. . . If I override method 'action_done', it works just fine. But _default_stock_location does not. It seems to be maggical (something I still dont understand yet) keke.

Post correlati Risposte Visualizzazioni Attività
2
giu 23
2220
1
nov 17
3246
1
giu 16
4691
2
ago 15
5411
1
ago 23
3008