跳至内容
菜单
此问题已终结
2 回复
1598 查看

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



形象
丢弃
最佳答案

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 

形象
丢弃
编写者

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

最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
0
9月 23
1780
3
12月 19
5729
0
4月 19
3596
0
8月 16
3978
0
3月 15
4643