This question has been flagged
1 Reply
4596 Views

I have developed a new addon to add new fields into "crm.lead" model. Also trying to update import functionality for leads, i.e, system will skip duplicate lead import by checking it's name attribute (Label is "Opportunity" in view). Please view my code attached,

class MyCustomModule(models.Model):    
    _inherit = "crm.lead"
        
    customfield1 = fields.Char("My Custom Field 1")     customfield2 = fields.char("My Custom field 2")    
   
    @api.model
    def create(self, vals):
        context = dict(self._context or {})
        valCount = self.search_count([('name''='vals.get('name'))])
        if valCount == 0:
            return super(Lead, self.with_context(contextmail_create_nolog=True)).create(vals)
        else:
            return False

How to solve this issue.

Avatar
Discard
Author Best Answer

Solved it :)
"else" part in "create" method shouldn't contain a Boolean return, instead it should return the model object.

Avatar
Discard