Skip to Content
Menu
This question has been flagged
7 Replies
3729 Views

Hi,

I'm new to Odoo. I have module "crm.lead" and my module "record.clone". Now I want to create a record that has some fields I need of the recent record has just been created.

Example: When I click on button "Create" in CRM and fill info on form, after that it will create a record in CRM, I want to create a record the same as that record in my module (maybe has less fields than CRM). How can I do that ? (Sorry for my english.)

Avatar
Discard
Best Answer

Ok, The solution is to override create method of odoo. The idea is to override create method and on the click of create button method update or create new record in "record.clone" model. Below is how you can override odoo create method:

class Campus(models.Model):
    _name='campus'    
    @api.model
    def create(self,values):
        campus_create = super(Campus,self).create(values)
        return campus_create

For more details

Reference: https://goo.gl/4BkizH

Avatar
Discard

For more details

Reference: https://goo.gl/4BkizH

Best Answer

Hello Hserht,

you have to inherit crm model like this.

class CRM(models.Model):

    _inherit = 'crm.lead'    


    @api.model

    def create(self,values):

        result = super(CRM,self).create(values)

        clone_vals = {

                        what are all the fields you want pass here, you can get fields data from values

                        }

        self.env['record.clone'].create(clone_vals)

        return result


make sure record.clone model have create permission for logged in user

Avatar
Discard
Author Best Answer

I can't comment in your answer because I dont have enough Karma, sorry about that.

Maybe you're not clear my problem (or my english is bad). The point is when I click button "Create" IN "crm.lead" NOT IN "record.clone".  CRM will create a record, and so does my module. (1 click create 2 record , one in CRM and one in mine).

Avatar
Discard
Author

I found solution. Just creating some fields in module "record.clone" which is the same type as fields in "crm.lead", and create another models that _inherit models "crm.lead" (ex. "CRMLeadinherit"), then override create method in "crm.lead" and create the clone record in that method:

class CRMLeadinherit(models.Model):

_inherit='crm.lead'

@api.model

def create(self,values):

result = super(CRMLeadinherit,self).create(values)

vals = {'name': values.get('name'), ...}

return result

thanks Sehrish for your help !

Author

'name' in vals is a fields that have the same type with values['name'] belongs to "record.clone" :))

welcome :)

Related Posts Replies Views Activity
0
Aug 24
189
2
Mar 24
257
1
Jul 22
1597
0
May 22
912
1
May 22
891