Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
1583 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

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

Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
zář 23
1740
3
pro 19
5703
0
dub 19
3581
0
srp 16
3951
0
bře 15
4636