Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
1591 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

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

Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
0
Sep 23
1767
3
Des 19
5712
0
Apr 19
3587
0
Agu 16
3953
0
Mar 15
4640