Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
7 Antworten
4518 Ansichten

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
Verwerfen
Beste Antwort

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
Verwerfen

For more details

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

Beste Antwort

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
Verwerfen
Autor Beste Antwort

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
Verwerfen
Autor

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 !

Autor

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

welcome :)

Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Aug. 25
1452
0
Mai 25
731
0
Aug. 24
1043
2
März 24
1346
1
Juli 22
2665