İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
4746 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç
Üretici

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?

Üretici En İyi Yanıt

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Ara 19
3398
2
Tem 24
2505
1
Haz 24
4995
1
Eki 23
10681
1
Eki 23
98