Skip to Content
Menu
This question has been flagged
3 Replies
3587 Views

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
Discard
Best Answer

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
Discard
Author

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?

Author Best Answer

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
Discard
Related Posts Replies Views Activity
2
Dec 19
2575
2
Jul 24
942
1
Jun 24
3564
1
Oct 23
8590
1
Oct 23
97