Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
4629 Visualizzazioni

Here's the write () method i want to restrict in my custom module. I don't want this existing write method to work how can I do that? 

class Product (models.Model):

    _name = 'product.product'


     @ api multi

def  write ( self ,  values ): 
'' 'Store the standard price change in order to be able to retrieve the cost of a product for a given date' '' 
res = super ( ProductProduct , self ). write ( values )
if 'standard_price' in values :
    self . _set_standard_price ( values [ 'standard_price' ])
return res
I can't comment this code as it belongs to the source model. I just want this function to bypass so it wont have any effect because i have written another method according to my requirement.



Avatar
Abbandona
Risposta migliore

If you want to overwrite a method on a model you should define the function without any super calls in a file that inherits the model where the function you want to overwrite exists.

Avatar
Abbandona
Autore

I have tried to completely override the write() method in my inherited model but it doesn't update the average cost on product. But when i commented these lines

if 'standard_price' in values :

self . _set_standard_price ( values [ 'standard_price' ])

from the above code then it worked as required. But obviously i cant comment the source code but i just want this to not do anything it should be as useless as when i comment the code. how can I do that?

Autore Risposta migliore

This is the solution I found from forum which worked for me. You can follow below code in order to achieve this part.

class CustomModel(models.Model):
    _inherit = "custom.model"
    
    @api.multi
    def write(self, vals):
        ## Definition
        return super(models.Model, self).write(vals)

Here only this function and write function of "model.Model" will call.

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
dic 19
3281
2
lug 24
2322
1
giu 24
4844
1
ott 23
10470
1
ott 23
98