Skip to Content
मेन्यू
This question has been flagged
2 Replies
1581 Views

How to correct error in my code :


from odoo import models, fields, api

class HomeMarketProduct(models.Model):   

​ _inherit = 'product.template'      

​  ProductUrl = fields.Char(string='Product Url', store=True)  

​  Discount = fields.Float(string='Discount', compute='_computed_price', store=True)  

​  @api.depends('list_price', 'compare_list_price')    

​  def _computed_price(self):       

​ for record in self:   

​         if record.compare_list_price:  

​           ​    record.Discount = ((record.compare_list_price - record.list_price) / ​record.compare_list_price) * 100         

​  ​  else:               

​ record.Discount = 0
error:

ValueError: Wrong @depends on '_computed_price' (compute method of field product.template.Discount). Dependency field 'compare_list_price' not found in model product.template.

Although there is a field inside product.template



Avatar
Discard
Best Answer

Hello Muhammad Mahmoud, 


    To resolve the dependency issue, 

    Go to the addons/website_sale/models/product_template.py

    

    Inside product_template.py file you can find the field 'compare_list_price'.

    

    Here, 'website_sale' module inherit 'product.template'.

    

    So, Directly if you assign the filed 'compare_list_price' on depends. It will raise error.

    

    To do so, In __manifest__.py add 'website_sale' in "depends".

   

I Hope this information proves helpful to you.


Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari 

Avatar
Discard
Author

Thanks Jainesh Shah
The problem has already been solved when add 'website_sale' module inherit 'product.template
Thanks

Best Answer

Hi,
As you have used compare_list_price inside the api depends decorator system is looking for a field with name:  compare_list_price in the product.template model and system cant find the field.

So either remove the dependency, or correct the dependency to right field or define the field in the model.


Thanks

Avatar
Discard
Related Posts Replies Views Activity
0
सित॰ 23
1740
3
दिस॰ 19
5703
0
अप्रैल 19
3581
0
अग॰ 16
3949
0
मार्च 15
4635