Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
1609 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

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

Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
0
sep. 23
1796
3
dec. 19
5738
0
apr. 19
3609
0
aug. 16
3990
0
mrt. 15
4648